Question

>        set serveroutput on  
>        set autoprint on;  
>       declare  
>       v_first_name employees.first_name%type;  
>       v_street_address locations.street_address%type;   
>       v_city locations.city%type;    
>       v_postal_code locations.postal_code%type;   
>       begin   
>       select employee_id first_name,street_address,city,postal_code       into:b_employee_id,v_first_name,v_street_address,v_city,v_postal_code 
> 
>       from employees   natural join locations    
>     where employee_id=156;    // how to get employee_id stored in b_employee_ud
>     dbms_output.put_line('the employee'||v_first_name ||' is located    at:'||v_street_address||   v_city ||v_postal_code );    
>     end;     
>     /

getting error Error report: ORA-06550: line 7, column 134: PL/SQL: ORA-00913: too many values ORA-06550: line 7, column 1: PL/SQL: SQL Statement ignored 06550. 00000 - "line %s, column %s:\n%s" *Cause: Usually a PL/SQL compilation error. *Action:

b_employee_id

156

i want to use employee_id which is stored in b_employee_id

No correct solution

OTHER TIPS

First of all, you're missing a comma after employee_id in your SELECT clause.

select employee_id first_name,street_address,city,postal_code 
into   :b_employee_id,v_first_name,v_street_address,v_city,v_postal_code 

should be

select employee_id, first_name,street_address,city,postal_code 
into   :b_employee_id,v_first_name,v_street_address,v_city,v_postal_code 

Now, coming back to the part where you want to use employee_id = 156

i want to use employee_id which is stored in b_employee_id

If your intent is not hard coding the employee_id for which you want to run your query (I am guessing this by reading the commented line at the end of your WHERE clause), then you need to use substitution variable in the WHERE clause, something like this:

WHERE employee_id = :b_emp_id

Another assumption here will be there, there is one record for one employee in the table from where you are trying to retrieve the records. You should not use a substitution variable in the variables of INTO clause

In case you want to override the value being returned in the INTO clause to some other value for any reason, you can use another variable later on in your program to do that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top