Solved

oracle bind variable

Posted on 2008-06-09
2
1,101 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
  • 2
2 Comments
 
LVL 28

Accepted Solution

by:
Naveen Kumar earned 500 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines

808 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