Difference between DECLARE, VARIABLE and DEFINE in PL/SQL

2.7k views Asked by At

i am new to PL/SQL. I am confused with the difference between following.

DECLARE name Varchar2(20);

VARIABLE name Varchar2(20);

DEFINE name = 'myname';

Thanks in advance.

2

There are 2 answers

1
vishnu sable On

please note a syntax bellow for pl/sql block

declare
 -- you can declare variable here like
v_name     varchar2(50); -- declaration of variable
v_app_name varchar2(10):= 'oracle_app'; -- declaration and definition of veriable 
begin
  -- business logic goes here...
--exception section....
end;

declare : start of pl/sql block.

variable : is name of variable used for storing intermediate/computation value.

Define : The DEFINE and UNDEFINE commands allow you to explicitly create and delete user variables. DEFINE creates a variable and assigns it an initial value. DEFINE also lets you list all currently defined user variables with their values. these are mainly used in sql script; eg to store table_space name which can be used for creating table

0
AudioBubble On

DECLARE starts a pl/sql block.

DEFINE substitute values.

Regarding VARIABLE take a look on Oracle Documentation.