Can You Assign Multiple Query Result Rows To a Variable?
Submitted by: AdministratorYou can use "SELECT ... INTO variable" to assign query results to variables. But what happens if the SELECT statements return multiple rows? The answer is that you will get a run time error. The following tutorial exercise shows this error condition:
DECLARE
fname VARCHAR2(10);
lname VARCHAR2(10);
BEGIN
SELECT first_name, last_name INTO fname, lname
FROM employees WHERE employee_id = 100;
DBMS_OUTPUT.PUT_LINE('Name = ' || fname || ' ' || lname);
SELECT first_name, last_name INTO fname, lname
FROM employees WHERE employee_id > 100;
DBMS_OUTPUT.PUT_LINE('Name = ' || fname || ' ' || lname);
END;
/
ORA-01422: exact fetch returns more than requested number
of rows
ORA-06512: at line 8
Name = Steven King
Submitted by: Administrator
DECLARE
fname VARCHAR2(10);
lname VARCHAR2(10);
BEGIN
SELECT first_name, last_name INTO fname, lname
FROM employees WHERE employee_id = 100;
DBMS_OUTPUT.PUT_LINE('Name = ' || fname || ' ' || lname);
SELECT first_name, last_name INTO fname, lname
FROM employees WHERE employee_id > 100;
DBMS_OUTPUT.PUT_LINE('Name = ' || fname || ' ' || lname);
END;
/
ORA-01422: exact fetch returns more than requested number
of rows
ORA-06512: at line 8
Name = Steven King
Submitted by: Administrator
Read Online Oracle Database Job Interview Questions And Answers
Top Oracle Database Questions
☺ | How To Shutdown Your 10g XE Server? |
☺ | How To Use "OUT" Parameter Properly? |
☺ | How Run SQL*Plus Commands That Are Stored in a Local File? |
☺ | What Is the Relation of a User Account and a Schema? |
☺ | How To Recover a Dropped Table in Oracle? |
Top DB Oracle Categories
☺ | Oracle PL-SQL Interview Questions. |
☺ | Oracle DBA Interview Questions. |
☺ | Oracle D2K Interview Questions. |
☺ | OCI Interview Questions. |
☺ | Oracle RMAN Interview Questions. |