1. var [iable] is a way to declare variables in SQL * Plus, which must be of any type specified in the help. They can be used in sql and in pl / sql both for the substitution of any values and for storing values, for example:
variable value varchar2(10); begin select 'a' into :value from dual; end; / select :value from dual /
2. def [ine] is a way to declare variables in SQL * Plus, in which you can specify the text that will be substituted for them in the places where they are used. Also using this command you can get a list of all existing variables that can be used for substitution.
If you declare a variable in advance and assign a value to it, then it will simply be substituted in the query text:
define value = dual select * from &value /
This query will produce the following result:
old 1: select * from & value
new 1: select * from dual
D
-
X
In the variable, you can specify almost any text:
define value ='23 from dual' select 1&value / old 1: select 1&value new 1: select 123 from dual 123 ---------- 123
If you do not assign a text value to a variable in advance, but simply use it in the query text, SQL * Plus will prompt you to enter its value:
select * from &another_value /
After executing this text, SQL * Plus will display on the screen a request to specify values for the variable:
Enter value for another_value:
Specifying that (in our case, dual
) and pressing Enter, we will see the following result:
old 1: select * from & another_value
new 1: select * from dual
D
-
X
When you call just a command
define
A list of already existing variables is displayed:
DEFINE _DATE = "03-AUG-15" (CHAR)
DEFINE _CONNECT_IDENTIFIER = "orcl" (CHAR)
DEFINE _USER = "SYS" (CHAR)
DEFINE _PRIVILEGE = "AS SYSDBA" (CHAR)
DEFINE _SQLPLUS_RELEASE = "1102000200" (CHAR)
DEFINE _EDITOR = "Notepad" (CHAR)
DEFINE _O_VERSION = "Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options "(CHAR)
DEFINE _O_RELEASE = "1102000200" (CHAR)
DEFINE VALUE = "dual" (CHAR)
3. declare is part of the declaration of the pl / sql code block define ... begin ... end
followed by a variable declaration, which can be used inside the begin ... end
block begin ... end
For example:
declare val1 number; val2 varchar2(10); val3 date; begin select 1, 'a' into val1, val2 from dual; val3 := sysdate; dbms_output.put_line(val1); dbms_output.put_line(val2); dbms_output.put_line(val3); end; /