How To Assign Query Results to Variables?
Submitted by: AdministratorIf you want to assign results from SELECT statements to variables, you can use the INTO clause, which an extension of SELECT statements for PL/SQL. The sample code below shows some good example on INTO clause:
DECLARE
total NUMBER;
now DATE;
fname VARCHAR2(10);
lname VARCHAR2(10);
BEGIN
SELECT COUNT(*) INTO total FROM employees;
DBMS_OUTPUT.PUT_LINE('Count = ' || TO_CHAR(total));
SELECT SYSDATE INTO now FROM DUAL;
DBMS_OUTPUT.PUT_LINE('Now = ' || TO_CHAR(now, 'SSSSS'));
SELECT first_name, last_name INTO fname, lname
FROM employees
WHERE employee_id = 100;
DBMS_OUTPUT.PUT_LINE('Name = ' || fname || ' ' || lname);
END;
/
Count = 107
Now = 82375
Name = Steven King
Submitted by: Administrator
DECLARE
total NUMBER;
now DATE;
fname VARCHAR2(10);
lname VARCHAR2(10);
BEGIN
SELECT COUNT(*) INTO total FROM employees;
DBMS_OUTPUT.PUT_LINE('Count = ' || TO_CHAR(total));
SELECT SYSDATE INTO now FROM DUAL;
DBMS_OUTPUT.PUT_LINE('Now = ' || TO_CHAR(now, 'SSSSS'));
SELECT first_name, last_name INTO fname, lname
FROM employees
WHERE employee_id = 100;
DBMS_OUTPUT.PUT_LINE('Name = ' || fname || ' ' || lname);
END;
/
Count = 107
Now = 82375
Name = Steven King
Submitted by: Administrator
Read Online Oracle Database Job Interview Questions And Answers
Top Oracle Database Questions
☺ | How To Write Date and Time Interval Literals in Oracle? |
☺ | How Oracle Handles Dead Locks? |
☺ | How To Use Values from Other Tables in UPDATE Statements using Oracle? |
☺ | What Is Input Buffer in SQL*Plus? |
☺ | What Is the Relation of a User Account and a Schema? |
Top DB Oracle Categories
☺ | Oracle PL-SQL Interview Questions. |
☺ | Oracle DBA Interview Questions. |
☺ | Oracle D2K Interview Questions. |
☺ | OCI Interview Questions. |
☺ | Oracle RMAN Interview Questions. |