How to execute a store procedure
Hi Forum
I have a store procedure with 4 variables in and 1 out, how to execute via sql this procedure for obtain the result in the out variable.
Thanks and regards
SQL> create or replace procedure test_proc (
2 a in number,
3 b in number,
4 c in number,
5 d in number,
6 outvar out number) is
7 begin
8 outvar := a + b + c + d;
9* end;
SQL> /
Procedure created.
SQL> variable var1 number;
SQL> exec test_proc (1, 2, 3, 4, :var1);
PL/SQL procedure successfully completed.
SQL> print var1
VAR1
10
SQL>
Similar Messages
-
HOW TO EXECUTE A STORE PROCEDURE THAT RETURN MULTIPLE ROWS FROM A QUERY
I NEED TO CREATE AND USE A STORE PROCEDURE THAT IS GOING TO DO A SELECT STATEMENT AN THE RESULT OF THE SELECT STATEMENT IS RETURN IN SOME WAY TO THE REQUESTER.
THIS CALL IS MADE BY AN EXTERNAL LANGUAGE, NOT PL/SQL OR FORMS APPLICATION. USING FOR EXAMPLE ODBC AND VISUAL BASIC. WHAT I NEED TO DO IS ADD A DATA ACCESS LAYER TO MY APPLICATION AND I ALREADY HAVE IT DONE FOR MS SQL SERVER, BUT I NEED THE SAME FUNCTIONALITY ACCESSING AN ORACLE DATABASE.
FLOW:
1. VB CREATE A ODBC CONNECTION TO A ORACLE DATABASE
2. VB EXECUTE A STORE PROCEDURE
3. THE STORE PROCEDURE RETURNS TO THE VB APPLICATION THE RESULT OF THE QUERY THAT IS INSIDE OF THE STORE PROCEDURE.(I.E. THE STORE PROCEDURE IS A BASIC SELECT, NOTHING COMPLEX)
4. VB DISPLAY THE RESULT IN A GRID
FOR SURE I CAN DO THE SELECT DIRECTLY TO ORACLE, BUT FOR PERFORMANCE REASONS AND SCALABILITY, I'LL LIKE IT TO DO IT USING A STORE PROCUDURES
IS THIS POSIBLE?, HOW?
THANKSCertainly, it's possible. First, define a stored procedure that includes an OUT parameter which is a REF CURSOR. Then, call the stored procedure via ODBC omitting the OUT parameter from the list of parameters. IT will automatically be returned as a result set. Syntax for both is below...
CREATE PROCEDURE foo (inParam in varchar2, resultSet OUT REF CURSOR )
In ODBC:
{call foo( 'someData' )}
Justin -
How to execute a store procedure automatically every day
NT4 and Oracle816,I wanna let Oracle execute a store procedure automatically every day.
How to do it?
Thanx.There are a few ways to do this: first of all you could write a script file and schedule it to run every night.
Another solution is to use the DBMS_JOB package. Refer to the documentation to see how it is used -
(Resolved) How to execute 2 store procedures in 1 transaction?
public void method1(){
Session session = getSessionFactory().acquireSession();
StoredProcedureCall spc1 = new StoredProcedureCall();
spc1.setProcedureName("PKG.SP1");
spc1.addNamedArgumentValue("param", "aaa");
session.executeNonSelectingCall(spc1);
StoredProcedureCall spc2 = new StoredProcedureCall();
spc2.setProcedureName("PKG.SP2");
spc2.addNamedArgumentValue("param", "bbb");
session.executeNonSelectingCall(spc2);
The above method is defined in SessionFacadeBean (just like the EJB in SRDemo),
I want the above 2 procedures executed in 1 transaction. If spc2 failed, the spc1 should not be committed. How can I do this?
Regards,
Jason
Message was edited by:
Jason.LuI have changed code as follows:
public void method1(){
DatabaseSession session = getSessionFactory().getSharedSession();
session.beginTransaction();
try{
StoredProcedureCall spc1 = new StoredProcedureCall();
spc1.setProcedureName("PKG.SP1");
spc1.addNamedArgumentValue("param", "aaa");
session.executeNonSelectingCall(spc1);
StoredProcedureCall spc2 = new StoredProcedureCall();
spc2.setProcedureName("PKG.SP2");
spc2.addNamedArgumentValue("param", "bbb");
session.executeNonSelectingCall(spc2);
} catch (Exception e) {
session.rollbackTransaction();
} finally {
session.release();
It seems that the "session.rollbackTransaction();" will be executed if spc2 fails.
toplink logs are as follows:
[TopLink Info]: 2007.11.12 10:20:36.690--ServerSession(1901666)--Thread(Thread[HTTPThreadGroup-4,5,HTTPThreadGroup])--default login successful
[TopLink Finer]: 2007.11.12 10:20:36.690--ServerSession(1901666)--Thread(Thread[HTTPThreadGroup-4,5,HTTPThreadGroup])--TX beginTransaction, status=NO_TRANSACTION
[TopLink Finer]: 2007.11.12 10:20:36.705--ServerSession(1901666)--Thread(Thread[HTTPThreadGroup-4,5,HTTPThreadGroup])--TX Internally starting
[TopLink Finer]: 2007.11.12 10:20:36.705--ServerSession(1901666)--Thread(Thread[HTTPThreadGroup-4,5,HTTPThreadGroup])--external transaction has begun internally
[TopLink Fine]: 2007.11.12 10:20:36.705--ServerSession(1901666)--Connection(11203640)--Thread(Thread[HTTPThreadGroup-4,5,HTTPThreadGroup])--BEGIN PKG.SP1(param=>'aaa'); END;
[TopLink Fine]: 2007.11.12 10:20:36.971--ServerSession(1901666)--Connection(22861541)--Thread(Thread[HTTPThreadGroup-4,5,HTTPThreadGroup])--BEGIN PKG.SP2(param=>'bbb'); END;
[TopLink Warning]: 2007.11.12 10:20:37.440--ServerSession(1901666)--Thread(Thread[HTTPThreadGroup-4,5,HTTPThreadGroup])--Local Exception Stack:
Exception [TOPLINK-4002] (Oracle TopLink - 10g Release 3 (10.1.3.3.0) (Build 070608)): oracle.toplink.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'SP2'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
Error Code: 6550
[TopLink Finer]: 2007.11.12 10:20:37.455--ServerSession(1901666)--Thread(Thread[HTTPThreadGroup-4,5,HTTPThreadGroup])--TX rollbackTransaction, status=STATUS_ACTIVE
[TopLink Finer]: 2007.11.12 10:20:37.455--ServerSession(1901666)--Thread(Thread[HTTPThreadGroup-4,5,HTTPThreadGroup])--TX Internally rolling back
[TopLink Finer]: 2007.11.12 10:20:37.455--ServerSession(1901666)--Thread(Thread[HTTPThreadGroup-4,5,HTTPThreadGroup])--external transaction has rolled back internally
The problem is the 1st store procedure is committed (it should be rolled back!), and the database is updated.
Thanks,
Jason -
how to use ADO(Microsoft ActiveX Data Objective 2.8 Library) to execute the store procedure of database in SQL server?
Does any body can tell me about this?
thanks
[email protected]Hi
Did you succeed to execute the procedure?
How ?
Thanks
Shimon Zerbib -
Can't execute Sybase store procedure
Hi All,
I'm trying to execute sybase store procedure, but somehow the procedure not executing. if any body what's the problem? I'm using JBoss server
Code:
public void deleteRigMapSP(String pMappingID, String rigid, String date,String pPhysicalDel, String database) throws DataAccessException {
GregorianCalendar val = new GregorianCalendar();
DateFormatter dateform = new DateFormatter();
String deletiondate = dateform.convertGregorianToString(val);
query = new StringBuffer("EXECUTE spRR_STAT_DeleteMapping ");
query.append("'"+pMappingID + "',");
query.append(null + ",");
query.append(null + ",");
query.append(null + ",");
query.append(null + ",");
query.append(null + ",");
query.append(null + ",");
query.append("'"+deletiondate + "',");
query.append(pPhysicalDel);
System.out.println("query: "+query);
try {
getDBConnection(ServiceLocator.getInstance().getDataSource(database));
CallableStatement cs = dbConnection.prepareCall(query.toString());
if (cs.execute()) {
System.out.println("deleted");
} else {
System.out.println("not deleted");
When I try to execute the method it's run fine, but it not executing the procedure.
Any help will be greately appreciated.How do you know it's not executing? Maybe you're in manual transaction mode and you're not committing the transaction before you close the connection and it gets rolled back.
And why on earth are you using CallableStatement if you're embedding the parameters into the SQL query rather than using placeholders and the setXXX() methods?
Alin. -
Execute ORACLE STORE PROCEDURE from DATABASE
Hi Everyone...
i have a store procedure, it has a 5 params, 3 are IN parameters and 2 left are OUT parameters, I need execute this store procedure using a SQL Intruction like this
DECLARE integracion_sia_kac PROCEDURE FOR KACTUS.SP_SIAKAC_NMDHODO
:ll_horario,
:ll_ide_doc,
:ls_con_kac,
@PINDREGI=:ls_ind_registro output, @PVALERRO=:ls_error_int output
USING gt_kactus;
i think this function is using from MSSQL Server, this has a three IN params but the declaration of the OUT params I don't understand.
HELP ME!!!!!.... I need know way to execute the SP
ThanksWell it is very simple!
example:
CREATE OR REPLACE PROCEDURE PROC1 (P1 IN NUMBER, P2 IN NUMBER, P3 OUT NUMBER) IS
BEGIN
P3 := P1 + P2;
END;
This is how to use PROC1 from, say, PROC2 :
CREATE OR REPLACE PROCEDURE SomeShema.PROC2 IS
Var1 NUMBER(15,2);
Var2 NUMBER(15,2);
ReturnParamFromPROC1 NUMBER(15,2);
BEGIN
Select SomeField INTO Var1 from Table1 where Table1.ID = 10;
Select SomeField INTO Var2 from Table2 where Table2.ID = 20;
PROC1(Var1, Var2, ReturnParamFromPROC1);
DBMS_OUTPUT.PUT_LINE('Returned value from PROC1 is : '||ReturnParamFromPROC1);
END; -
How to get the store procedure name inside this store procedure?
how to get the store procedure name inside this store procedure?
Why cant you get the procedure name as hard code as the proc name is going to change.
Are you looking for getting the parent proc name from child proc name which is getting executed within parent proc?
Try the below:
--Parent Proc
Alter Proc sp_test
as
Begin
Declare @s varbinary(MAX) = Cast('sp_test' as Varbinary(MAX));
SET CONTEXT_INFO @s;
exec sp_test2
End
--Child proc
Alter proc sp_test2
as
SELECT Cast(CONTEXT_INFO() as varchar(100));
--Test execution
Exec sp_test
Please mark this reply as answer if it solved your issue or vote as helpful if it helped.
[Blog] -
How to Execute a Remote Procedure in Portal using Database Link
Hi,
I followed the instructions to create a Portal form for a remote procedure. But I am encountering the following error. Can someone advise what may be the cause?
Failed to execute - Missing string(create_package_body) language(us) domain (wwv) sub_domain (wwv_builder) (WWV-04300)
ORA-04020: deadlock detected while trying to lock object PUBLIC.PORTLET_SCHEMA (WWV-11230)
Failed to parse as PORTAL - (WWV-08300)
PURPOSE
How to execute a remote procedure in Portal using Database Link.
DESCRIPTION
This procedure assumes that you have two databases, one of which is remote, and Portal is configured in the other.
Remote Database A:
==================
1) Create a procedure as follows: Create or Replace PROCEDURE SCOTT.ADD_TWO_VALUES ( v_one IN NUMBER, v_two IN NUMBER, v_result OUT NUMBER) as begin v_result :=v_one+v_two; end; 2) Grant execute privileges to PUBLIC on the procedure.
Database B (where Portal is configured): ========================================
1) Create a public database link and choose to connect as a specific user (say SYSTEM). By default, in an Oracle 8i database, the "global_names" parameter in initSID.ora (or init.ora) file is set to "true". This Global Naming parameter enforces that a dblink has the same name as the database it connects to. Therefore, if the remote global database (A) name is "ora8.acme.com" then the database link should also be named as "ora8.acme.com".
2) Create a synonym for the procedure in Database A. Make sure you fully qualify the procedure name in the remote database (like SCOTT.ADD_TWO_VALUES).
3) Create a dynamic page to execute the procedure. The ORACLE tags in the dynamic page will look similar to the following: <ORACLE> DECLARE v_total NUMBER; BEGIN ADD_TWO_VALUES(:v_one,:v_two, v_total); htp.p('The total is => '); htp.p('<input type="TEXT" VALUE='||v_total||'>'); htp.para; htp.anchor('http://<machine.domain:port#>/pls/portal30/SCOTT.DYN_ADD_TWO_VALUES.show_parms', 'Re-Execute Procedure'); END; </ORACLE>
4) Portal does not have an option to create a form based on a synonym. Therefore, if you want to create a form instead of a dynamic page, create a wrapper procedure and then create a form based on this procedure. For example: Create or Replace PROCEDURE PORTAL30.ADD_TWO_VALUES_PR ( v_one IN NUMBER, v_two IN NUMBER, v_total OUT NUMBER) as begin add_two_values(v_one, v_two, v_total); end;
5) Grant execute privileges to PUBLIC on the procedure.hello...
any input will welcomed... Thanks.. -
How to execute a stored procedure/function in TOAD?
Hi, All ,
Can someone please tell me how to execute a stored procedure/function in TOAD?
I have tired
EXECUTE PROCEDURENAME(888), but it doesn’t work.
TOAD give me the error: invalid SQL statement.
Thanks a lotWrite PL/SQl block.
i.e Begin
Procedure name..
end;
Then it will be excuted.
Ashutosh -
How to call a Store Procedure with IN PARAMETER
Hi, im new using Oracle 10G with Oracle SQL Developer, my cuestion is how to call a Store Procedure with IN PARAMETER, I tried the following without results
SELECT * FROM procedure_name(parameter);
PROCEDURE procedure_name(parameter);
EXEC procedure_name(parameter);
CALL procedure_name(parameter);
Please help me....Hi,
As Beijing said,
EXEC procedure_name(parameter);
CALL procedure_name(parameter);work for me.
So does
BEGIN
procedure_name(parameter);
END;Can you be more specific about what you're doing? That is, are you testing it in SQL Developer? Where are you entering the commands? Where are you looking for output? Do you get error messages? Does anything else (like "SELECT SYSDATE FROM dual;") work? -
How to execute a stored procedure every 5 minutes in biztalk admin console
Hi
how to execute a stored procedure every 5 minutes in biztalk admin console without using biztalk orchestration
we need to update table data every 5minutes
please replay asap...........
thanks advance....WCF adapter is best suited for the same. Use ‘Template’ feature of WCF adapter. Template is mainly used to add wrapper elements around the body of the outgoing message from send port.
Below mentioned post is perfectly suited for you.
http://social.technet.microsoft.com/wiki/contents/articles/19845.invoke-a-sql-stored-procedure-on-the-biztalk-wcf-send-port-without-needing-an-orchestration.aspx
Regards,
Rachit
If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply. -
How to execute a SQL procedure in UNIX
How to execute a SQL procedure in UNIX
Check this out..
-Sri
<< a.sql >>
create or replace procedure junk(nout out varchar2) is
x varchar2(20);
begin
select 'Sam' into x
from dual;
nout := x;
end;
<< Shell script >>
sqlplus -s / << DOC
scott/tiger
variable x varchar2(20);
set autoprint on
@a.sql
begin
junk(:x);
end;
exit
DOC
<< Execution of Shell SCript >>
# sh b.sh
Procedure created.
PL/SQL procedure successfully completed.
X
Sam -
How to execute the packaged procedure(having out param) in TOAD for Oracle
Hi.
Could you help me
How to execute the packaged procedure having out parameters in TOAD for Oralce..
Thanks..Use anonymous PL/SQL block to execute it.
Example.
DECLARE
<out variable name> <out variable data type>;
BEGIN
<package name>.<procedure name>(<out variable name>);
END; -
How to execute oracle stored procedure through php as externally?
hi...
i am searching for the way that how to execute oracle stored procedure through web service, i am using php and mysql, i have some stored procedures in oracale database, i want to execute them, from php, means the database will be remain mysql, and the stored procedures of oracle will be executed externally...
Kind regards,
Wilayat.Ok, so first of all this is a kind of strange question. Since Oracle and MYSQL can happily live side by side.
Make sure you have the oracle client (instant or regular ) installed and OCI_8 is set up and working correctly in PHP. If it is, when you run the phpinfo() routine you will see oci_8 on there. IF PHP connects just fine from the command line yet apache wont connect check permissions and things like the LD_Library Path.
Then in php, right along with your MySQL statements run Oracle Statements eg:
<?php
$OraDB = oci_connect(name,pass,tnsname);
$MySQLdb = mysql_connect([parms]);
$oraQueryText = "begin sp_some_proc([some parms]); end;" ;
$mysqlQuery = " Some mysql Query";
$oraQuery = oci_parse($OraDB,$oraQueryText );
oci_execute($oraQuery);
mysql_execute([parms]);
?>
Use the standard fetch code to get data from either of them.
If you cannot and I mean absolutely cannot get an admin to link in OCI_8 then you still have recourse although it will be tedious as hell. PHP allows you to exec calls to the OS. You still MUST make sure the Oracle Client is installed and that sqlplus runs from the command line. You will more then likely have to have a shell script written to do this as well, but maybe not as I have never tried it with the exception of capturing the return value of sqlplus and you will have to dig into sqlplus to get it to send its results to a file you can then parse with php.
Good Luck!
Maybe you are looking for
-
Routine sample code for reading 2 fields from existing DSO
Hi Gurus, I am a monkey when it comes to write ABAP code. I have one DSO-A where we store accounting info of purchading (from DS 2lis_02_acc) and one DSO-B getting data from 2lis_02_scl data source. We need to write a rountine to read DS
-
Only two hard drives - optimal file locations?
Hi, Can anyone tell what would be the optimal file location configuration (regarding perfomance) when there are only two physical hard drives available? One is abviously running the OS (Windows XP), but how to locate raw images, ACR cache and catalog
-
Hi all, we are having two systems, in which we are trying to send Idoc from one system to another. Now, we created a Vendor Invoice in system1. We are getting successful creation of Idoc Message as well as stated below: "Idoc '0000000083307310' was c
-
Code bug help for a beginner!!
Ok, I've written this code so far. Everything was fine until I got to the IF condition. When I try compiling it it tells me that the 'a' variable in the IF condition expression may not have been initialised, which I don't really understand as it's be
-
Email particular pages only not the full form
Hi Experts I am working with LiveCycle Designer ES2 forms. I am trying to add a submit button form as pdf it works fine. My problem is I have 15 pages form but I need to send only the main pages for example I need to send email attachment only the la