Link to home
Create AccountLog in
Avatar of yanci1179
yanci1179

asked on

oracle bind variable

I am new to oracle, and I wanted to know how to initialize a bind variable.  I tried doing the example below but I keep getting an error at line exec :basic_percent  := 45;  Once I remove the line it runs fine.  How do I set 45 to basic_percent within the executable section?
VARIABLE basic_percent number
VARIABLE pf_percent number
 
declare
outputHello varchar2(11):= 'Hello World';
today DATE:=SYSDATE;
tomorrow today%type:= today+1;
 
begin
 
 
exec :basic_percent  := 45;
DBMS_OUTPUT.PUT_LINE(outputHello);
DBMS_OUTPUT.PUT_LINE(today);
DBMS_OUTPUT.PUT_LINE(tomorrow);
end;
/
print basic_percent 
print pf_percent

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Naveen Kumar
Naveen Kumar
Flag of India image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
exec should not be used in begin .. end; section. It can be used in the sql prompt to assign values like as shown below :

12:30:04 SQL> exec :basic_percent := 50

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.07
12:31:24 SQL> print

BASIC_PERCENT
-------------
           50

12:31:27 SQL>