?
Solved

oracle bind variable

Posted on 2008-06-09
2
Medium Priority
?
1,109 Views
Last Modified: 2013-12-07
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

0
Comment
Question by:yanci1179
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 28

Accepted Solution

by:
Naveen Kumar earned 2000 total points
ID: 21748488
try the below :

VARIABLE basic_percent number
VARIABLE pf_percent number
 
declare
outputHello varchar2(11):= 'Hello World';
today DATE:=SYSDATE;
tomorrow today%type:= today+1;
 
begin
 
: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
0
 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 21748498
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>
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question