Collections:
Use Variables in SQL Statements in Oracle
Can Variables Be Used in SQL Statements in Oracle?
✍: FYIcenter.com
Yes, you can use variables in SQL statements as part of any expressions. The tutorial script provides you some good examples:
(Connect to XE with SQL*Plus)
CREATE TABLE student (id NUMBER(5) PRIMARY KEY,
first_name VARCHAR(80) NOT NULL,
last_name VARCHAR(80) NOT NULL);
Table created.
DECLARE
var_id NUMBER;
var_name CHAR(10);
BEGIN
var_id := 29;
var_name := 'Bob';
INSERT INTO student VALUES(var_id, var_name, 'Henry');
var_name := 'Joe';
INSERT INTO student VALUES(var_id+1, var_name, 'Bush');
var_name := 'Fyi';
UPDATE student SET first_name = var_name
WHERE id = var_id+1;
DELETE FROM student WHERE id = var_id;
END;
/
SELECT * FROM student;
ID FIRST_NAME LAST_NAME
-------- ----------- -----------
30 Fyi Bush
⇒ Variable Names Collide with Column Names in Oracle
⇐ Cannot Use DDL Statements in PL/SQL in Oracle
2018-09-24, 3170🔥, 0💬
Popular Posts:
How To Use DATEADD() Function in SQL Server Transact-SQL? DATEADD() is a very useful function for ma...
What Are the Basic Features of a Trigger in SQL Server? Since a SQL Server trigger is a really an ev...
How To Convert Binary Strings into Integers in SQL Server Transact-SQL? Binary strings and integers ...
What Privilege Is Needed for a User to Delete Rows from Tables in Another Schema in Oracle? For a us...
How To Recover a Dropped Index in Oracle? If you have the recycle bin feature turned on, dropped ind...