Home » SQL & PL/SQL » SQL & PL/SQL » Initialization of a bind variable
Initialization of a bind variable [message #285831] Wed, 05 December 2007 16:31 Go to next message
DbSpa
Messages: 7
Registered: November 2007
Junior Member
Hi,

Lets take a simple procedure as

SQL> CREATE OR REPLACE PROCEDURE procInOut(n IN OUT NUMBER) IS
2 BEGIN
3 n := n * n;
4 end;
5 /

I want to execute this using a bind variable.
But how to initialize the bind variable to some value before passing to this procedure?

SQL>VARIABLE a NUMBER;
SQL>EXEC procInOut(:a);
SQL>PRINT :a;

Thanks,
Re: Initialization of a bind variable [message #285832 is a reply to message #285831] Wed, 05 December 2007 16:37 Go to previous messageGo to next message
Barbara Boehmer
Messages: 8625
Registered: November 2002
Location: California, USA
Senior Member
SCOTT@orcl_11g> CREATE OR REPLACE PROCEDURE procInOut
  2    (n IN OUT NUMBER)
  3  AS
  4  BEGIN
  5    n := n * n;
  6  END procInOut;
  7  /

Procedure created.

SCOTT@orcl_11g> SHOW ERRORS
No errors.
SCOTT@orcl_11g> VARIABLE a NUMBER;


SCOTT@orcl_11g> EXEC :a := 3

PL/SQL procedure successfully completed.

SCOTT@orcl_11g> EXEC procInOut(:a);

PL/SQL procedure successfully completed.

SCOTT@orcl_11g> PRINT :a

         A
----------
         9


SCOTT@orcl_11g> BEGIN
  2    :a := 4;
  3  END;
  4  /

PL/SQL procedure successfully completed.

SCOTT@orcl_11g> EXEC procInOut(:a);

PL/SQL procedure successfully completed.

SCOTT@orcl_11g> PRINT :a

         A
----------
        16

SCOTT@orcl_11g> 

Re: Initialization of a bind variable [message #285833 is a reply to message #285832] Wed, 05 December 2007 16:45 Go to previous message
DbSpa
Messages: 7
Registered: November 2007
Junior Member
Many thanks...
Previous Topic: Table rows and sizes.
Next Topic: Urgent SQL Assistance
Goto Forum:
  


Current Time: Sun Dec 04 14:57:00 CST 2016

Total time taken to generate the page: 0.05953 seconds