Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a stored procedure in Oracle with IN and OUT parameters

Tags:

sql

oracle11g

I have this procedure:

CREATE OR REPLACE PROCEDURE PROC1(invoicenr IN NUMBER, amnt OUT NUMBER) AS BEGIN SELECT AMOUNT INTO amnt FROM INVOICE WHERE INVOICE_NR = invoicenr; END; 

So when I run it like this it returns absolutely nothing:

DECLARE     amount NUMBER; BEGIN     PROC1(1000001, amount);     dbms_output.put_line(amount); END; 

BTW I use DreamCoder for Oracle. Is there a problem with the procedure itself or with the way I call it? There is an entry in the INVOICE table with INVOICE_NR equal to 1000001.

like image 878
RegedUser00x Avatar asked Apr 05 '12 08:04

RegedUser00x


People also ask

How use out parameter in Oracle procedure?

The value of the IN/OUT parameter is passed into the stored procedure/function and a new value can be assigned to the parameter and passed out of the module. An IN/OUT parameter must be a variable, not a constant. However, it can be found on both sides of an assignment.

Can a stored procedure use output parameters?

The Output Parameters in Stored Procedures are used to return some value or values. A Stored Procedure can have any number of output parameters. The simple logic is this — If you want to return 1 value then use 1 output parameter, for returning 5 values use 5 output parameters, for 10 use 10, and so on.

What is in and in out in procedure in Oracle?

IN represents the value that will be passed from outside and OUT represents the parameter that will be used to return a value outside of the procedure. procedure-body contains the executable part. The AS keyword is used instead of the IS keyword for creating a standalone procedure.


1 Answers

If you set the server output in ON mode before the entire code, it works, otherwise put_line() will not work. Try it!

The code is,

set serveroutput on; CREATE OR REPLACE PROCEDURE PROC1(invoicenr IN NUMBER, amnt OUT NUMBER) AS BEGIN SELECT AMOUNT INTO amnt FROM INVOICE WHERE INVOICE_NR = invoicenr; END; 

And then call the function as it is:

DECLARE amount NUMBER; BEGIN PROC1(1000001, amount); dbms_output.put_line(amount); END; 
like image 99
Keerthi Avatar answered Sep 29 '22 07:09

Keerthi