169563 Users read it.

Calling an Oracle Stored Procedure

by George Petrov (March 14, 2001)

How do I call an Oracle Stored Procedure
by Surya Rao

Folks, contrary to popular belief there are many ways to call stored procedures from an ASP page.I've tried it with Oracle (the only REAL RDBMS and it works.

User Rating (169 votes)
2 reviews available | Read all reviews »
Assume you have a procedure like this one below, and that it has been already created on the
Oracle database. This procedure doesn't return anything, but that doesn't change anything!
STEP #1:
/******STORED PROCEDURE ON ORACLE DATABASE************/
/*====================================================*/
create or replace procedure test_me
is
w_count integer;
begin
insert into TEST values ('Surya was here');
--commit it
commit;
end;
/*****END OF STORED PROCEDURE****/

STEP # 2:
+++++++++
I assume you have tested it from sql*plus by running the
following statements:
/************TEST THE STORED PROCEDURE FROM SQL*PLUS******/
SQL> execute test_me
PL/SQL procedure successfully completed.
 SQL> 
/***************END OF TESTING THE STORED PROC************/
STEP# 3:
++++++++
/*****CALLING A STORED PROCEDURE FROM ASP******************/
1. USING THE CONNECTION OBJECT
You can execute stored procedures which perform Oracle Server side tasks and return you a recordset. 
You can only use this method if your stored procedure doesn't return any OUTPUT values.
<%    Set Conn = Server.CreateObject("ADODB.Connection")
      Conn.execute "test_me",-1,4
%>
Note that -1 means no count of total number of records is
required. If you want to get the count, substitute count
with some integer variable
   Note that 4 means it is a stored procedure. By using the
actual number -1 and 4, you don't need the server side
include ADOVBS.INC
   The above would do the job on the database and return
back to you without returning any recordsets.
   Alternatively, you could:
<%   Set rs = conn.execute("test_me",w_count,4)   %>
   W_count is the number of records affected. If your stored
procedure were to return a query result, it is returned
within your recordset (rs). This method is useful with Stored procs
which return results of an SQL query

2. USING THE COMMAND OBJECT
<%
Set Conn = Server.CreateObject("ADODB.Connection")
Set Comm = Server.CreateObject("ADODB.Command")
    Set comm.ActiveConnection = conn
comm.commandtype=4
     '(or use adCmdStoredProc instead of 4, but then you would have to
'include the ADOVBS.INC. Its upto you
    comm.commandtext = "test_me"
    comm.execute
'or
Set rs = comm.execute()
%>
STEP# 4
+++++++++
/************PASSING INPUT/OUTPUT PARAMETERS**************************/
<%
'If your stored procedure accepts IN parameters and returns OUT parameters
'here's how to go about it
    set param = comm.Parameters
param.append comm.createparameter("Input",3,1)
param.append comm.createparameter("Output",3,2)
'Note that 3 = adInteger for the datatype
'Note that 1="adParamInput" and 2="adParamOutput" for parameter direction
'Pass the input value
comm("Input") = "...."
    OR
    set param = comm.createparameter("InPut",3,1)
set param = comm.createparameter("OutPut",3,2)
comm.parameters.append param
'Pass the input value
comm("Input") = "...."
    'Execute after setting the parameters
comm.execute()
    'If your stored procedure returns OUT parameters, here's how to get it
    
Out_1 = comm("Output")
'and so on...
%>
Thats it!

George Petrov

George PetrovGeorge Petrov is the Founder of the highly successful Zones: DMXzone.com, FWzone.net, FLzone.com, CFzone.net, DNzone.com and FlashFiles.nl


He has developed the comprehensive Dynamic Zones Content Management System that is the brains driving them and constantly supports their online communities with his extensive and valuable knowledge.

He is a renowned web development 'Guru' who has written many articles and extension for Adobe's Dreamweaver.

George Petrov is also the CEO and Founder of Dynamic Zones and also very proud of his children Sofie, Victor and Alexander!

See All Postings From George Petrov >>

User Reviews

Total of 2 reviews
Calling an Oracle Stored Procedure and Oracle specific datatypes
Written by viswa Peesapati on December 26, 2002

Hi Surya, Very nice to see the program unit. Thanks very much. I have further questions to get clarified. How do I use Oracle RecordTypes and TableTypes(having mulitple fields) in my ASP/ColdFusion. I am posting a sample package, which I need to ...

Problem in calling Oracle Stored Procedure
Written by Surendra Choudhary on September 7, 2002

I am not very clear about this method. Actually I have a procedure named proc_exp_comp_dt in which there are 3 IN parameter and 2 OUT parameter. Both OUT parameter returns one- one value. I have to use that value in my ASP page for further ...

Follow us on twitter Subscribe to our RSS feed
Activate your free membership today | Login | Currency