Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

oracle bind variable

Posted on 2008-06-09
2
Medium Priority
?
1,114 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

604 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