Collections:
Assign Query Results to Variables in Oracle
How To Assign Query Results to Variables in Oracle?
✍: FYIcenter.com
If 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
⇒ Error: Exact Fetch Returns More Rows in Oracle
⇐ Name Conflicts between Variables and Columns in Oracle
2018-09-24, 3907🔥, 0💬
Popular Posts:
How To Assign Debug Privileges to a User in Oracle? In order to run SQL Developer in debug mode, the...
How To Generate CREATE TABLE Script on an Existing Table in SQL Server? If you want to know how an e...
How To Get Year, Month and Day Out of DATETIME Values in SQL Server Transact-SQL? You can use DATEPA...
How To Round a Numeric Value To a Specific Precision in SQL Server Transact-SQL? Sometimes you need ...
How To Start Instance with a Minimal Initialization Parameter File in Oracle? The sample initializat...