How to call procedure from OCI ?
How to call oracle procedure from OCI ?
Following works on Windows, your mileage may vary. IIRC one of the standard OCI examples that install with the libraries demonstrates this too.
/* SQL to create table and Stored Procedures */
Create table OCI8StoredProcedureSampleTable
(field1 number(5), field2 varchar2(30));
CREATE OR REPLACE PROCEDURE OCI8StoredProcedureSample3
(field1 number, field2 IN OUT varchar2)
is
begin
insert into OCI8StoredProcedureSampleTable values (field1, field2);
Commit;
field2 := 'Successful';
end;
CREATE OR REPLACE PROCEDURE OCI8StoredProcedureSample4
(field1 number, field2 char, field3 OUT varchar2)
is
begin
insert into OCI8StoredProcedureSampleTable values (field1, field2);
Commit;
field3 := 'Successful';
end;
CREATE OR REPLACE FUNCTION OCI8StoredProcedureSample5
RETURN VARCHAR2
is
v_Sysdate DATE;
v_charSysdate VARCHAR2(20);
begin
SELECT TO_CHAR(SYSDATE, 'dd-mon-yyyy') into v_charSysdate FROM DUAL;
return(v_charSysdate);
end;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <oci.h>
static void checkerr (OCIError *p_err, sword status);
void main()
OCIEnv *p_env;
OCIError *p_err;
OCISvcCtx *p_svc;
OCIStmt *p_sql;
OCIBind p_Bind1 = (OCIBind ) 0;
OCIBind p_Bind2 = (OCIBind ) 0;
OCIBind p_Bind3 = (OCIBind ) 0;
OCIDefine p_define1 = (OCIDefine ) 0;
char field2[20] = "Entry 3";
char *field3;
//char field3[20];
sword field1 = 3;
text mySql = (text ) "Begin OCI8StoredProcedureSample3(:field1, :field2); END;";
printf("OCIInitialize\n");
checkerr(p_err, OCIInitialize((ub4) OCI_OBJECT,
(dvoid *) 0, (dvoid * (*) ()) 0,
(dvoid * (*) ()) 0, (void (*) ()) 0));
printf("OCIEnvInit\n");
checkerr(p_err, OCIEnvInit(&p_env, (ub4) OCI_DEFAULT,
(size_t) 0, (dvoid **)0));
printf("OCIHandleAlloc\n");
checkerr(p_err, OCIHandleAlloc(p_env, &p_err, OCI_HTYPE_ERROR,
(size_t) 0, (dvoid **) 0));
printf("OCIHandleAlloc\n");
checkerr(p_err, OCIHandleAlloc(p_env, &p_svc, OCI_HTYPE_SVCCTX,
(size_t) 0, (dvoid **) 0));
printf("OCIHandleAlloc\n");
checkerr(p_err, OCIHandleAlloc(p_env, &p_sql, OCI_HTYPE_STMT, (size_t) 0, (dvoid **) 0));
printf("OCILogon\n\n");
checkerr(p_err, OCILogon(p_env, p_err, &p_svc, "SCOTT", 5, "TIGER", 5, "V8", 2));
/* Example 1 - Using an IN OUT Parameters */
printf("*************************************************\n");
printf("Example 1 - Using an IN OUT Parameters\n");
printf("*************************************************\n");
printf(" OCIStmtPrepare\n");
printf(" %s\n",mySql);
checkerr(p_err, OCIStmtPrepare(p_sql, p_err, mySql,
(ub4) strlen(mySql), OCI_NTV_SYNTAX, OCI_DEFAULT));
printf(" OCIBindByPos 1\n");
checkerr(p_err, OCIBindByPos(p_sql, &p_Bind1, p_err, 1, (dvoid *) &field1, sizeof(sword),
SQLT_INT, 0, 0, 0, 0, 0, OCI_DEFAULT));
printf(" OCIBindByPos 2\n");
checkerr(p_err, OCIBindByPos(p_sql, &p_Bind2, p_err, 2, field2, (sizeof(field2) - 1),
SQLT_CHR, 0, 0, 0, 0, 0, OCI_DEFAULT));
printf(" Field2 Before:\n");
printf(" size ---> %d\n", sizeof(field2));
printf(" length ---> %d\n", strlen(field2));
printf(" value ---> %s\n", field2);
printf(" OCIStmtExecute\n");
checkerr(p_err, OCIStmtExecute(p_svc, p_sql, p_err, (ub4) 1, (ub4) 0, (OCISnapshot *)
NULL, (OCISnapshot *) NULL, (ub4) OCI_COMMIT_ON_SUCCESS));
printf(" Field2 After:\n");
printf(" size ---> %d\n", sizeof(field2));
printf(" length ---> %d\n", strlen(field2));
printf(" value ---> %s\n", field2);
/* Example 2 - Using OUT Parameters */
field1 = 4;
strcpy(field2, "Entry 4");
printf("\n\n*************************************************\n");
printf("Example 2 - Using OUT Parameters\n");
printf("*************************************************\n");
printf(" OCIStmtPrepare\n");
strcpy(mySql,(text *) "Begin OCI8StoredProcedureSample4(:field1, :field2, :field3); END;");
printf(" %s\n",mySql);
checkerr(p_err, OCIStmtPrepare(p_sql, p_err, mySql,
(ub4) strlen(mySql), OCI_NTV_SYNTAX, OCI_DEFAULT));
printf(" OCIBindByPos 1\n");
checkerr(p_err, OCIBindByPos(p_sql, &p_Bind1, p_err, 1, (dvoid *) &field1, sizeof(sword),
SQLT_INT, 0, 0, 0, 0, 0, OCI_DEFAULT));
printf(" OCIBindByPos 2\n");
checkerr(p_err, OCIBindByPos(p_sql, &p_Bind2, p_err, 2, field2, strlen(field2),
SQLT_CHR, 0, 0, 0, 0, 0, OCI_DEFAULT));
printf(" OCIBindByPos 3\n");
checkerr(p_err, OCIBindByPos(p_sql, &p_Bind3, p_err, 3, field3, 19,
SQLT_CHR, 0, 0, 0, 0, 0, OCI_DEFAULT));
printf(" OCIStmtExecute\n");
checkerr(p_err, OCIStmtExecute(p_svc, p_sql, p_err, (ub4) 1, (ub4) 0, (OCISnapshot *)
NULL, (OCISnapshot *) NULL, (ub4) OCI_COMMIT_ON_SUCCESS));
printf(" Field3 After:\n");
printf(" size ---> %d\n", sizeof(field3));
printf(" length ---> %d\n", strlen(field3));
printf(" value ---> %s\n", field3);
/* Example 3 - Using a Function to Return a Value */
printf("\n\n*************************************************\n");
printf("Example 3 - Using a Function to Return a Value \n");
printf("*************************************************\n");
printf(" OCIStmtPrepare\n");
strcpy(mySql,(text *) "SELECT OCI8StoredProcedureSample5 from DUAL");
printf(" %s\n",mySql);
checkerr(p_err, OCIStmtPrepare(p_sql, p_err, mySql,
(ub4) strlen(mySql), OCI_NTV_SYNTAX, OCI_DEFAULT));
checkerr(p_err, OCIDefineByPos(p_sql, &p_define1, p_err, 1, (dvoid *) field3,
(sword) 20, SQLT_STR, (dvoid *) 0, (ub2 *)0, (ub2 *)0, OCI_DEFAULT));
printf(" OCIStmtExecute\n");
checkerr(p_err, OCIStmtExecute(p_svc, p_sql, p_err, (ub4) 1, (ub4) 0, (OCISnapshot *)
NULL, (OCISnapshot *) NULL, (ub4) OCI_COMMIT_ON_SUCCESS));
printf(" The return value:\n");
printf(" size ---> %d\n", sizeof(field3));
printf(" length ---> %d\n", strlen(field3));
printf(" value ---> %s\n", field3);
return;
static void checkerr(errhp, status)
OCIError *errhp;sword status;
text errbuf[512];
ub4 errcode;
switch (status)
case OCI_SUCCESS:
break;
case OCI_SUCCESS_WITH_INFO:
printf("Error - OCI_SUCCESS_WITH_INFO\n");
break;
case OCI_NEED_DATA:
printf("Error - OCI_NEED_DATA\n");
break;
case OCI_NO_DATA:
printf("Error - OCI_NO_DATA\n");
break;
case OCI_ERROR:
OCIErrorGet ((dvoid *) errhp, (ub4) 1, (text *) NULL, &errcode,
errbuf, (ub4) sizeof(errbuf), (ub4) OCI_HTYPE_ERROR);
printf("Error - %s\n", errbuf);
break;
case OCI_INVALID_HANDLE:
printf("Error - OCI_INVALID_HANDLE\n");
break;
case OCI_STILL_EXECUTING:
printf("Error - OCI_STILL_EXECUTE\n");
break;
case OCI_CONTINUE:
printf("Error - OCI_CONTINUE\n");
break;
default:
break;
Similar Messages
-
How to Call Procedure from Trigger body?
I have a procedure that works which I tested from sqlplus with 'exec proc_name;'
what I want is to call this procedure from the trigger and pass the parameters to the proc. the trigger fires AFTER INSERT of certain table and I want to pass those just added attribute values to the proc.
please help.
I have tried to do 'exec proc_name' from the trigger but it does not work?You don't use exec within pl/sql, just proc_name followed by your parmateters. From within a trigger, the just added values will be :new.column_name. So, you would have something like:
CREATE OR REPLACE TRIGGER your_trigger_name
AFTER INSERT ON your_table_name
FOR EACH ROW
BEGIN
proc_name (:NEW.column_name1, :NEW.column_name2);
END your_trigger_name;
/You will need to have corresponding input parameters in your proc_name procedure, something like:
CREATE OR REPLACE PROCEDURE proc_name
(p_column_name1 your_table_name.column_name1%TYPE,
p_column_name2 your_table_name.column_name2%TYPE)
AS
BEGIN
-- whatever processing you want to do
END proc_name; -
How to call procedure from java
My database : oracle xe 10g
I develop my application by use jdeveloper
I call procedure following code :
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection c = (Connection)DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "shm", "shm");
CallableStatement cs = c.prepareCall("begin shm_increase_capital.ins_upd_tb_payment_rec_pc(:1,:2,:3,:4,:5,:6,:7);end;");
cs.setLong(1, shareHolderId);
cs.setString(2, companyCode);
cs.setString(3, lotYear);
cs.setLong(4, seqLot);
cs.setLong(5, allocateId);
cs.setLong(6, originateFrom);
cs.setString(7, curUser);
cs.execute();
cs.close();
c.close();
When I run my application several times I found error :
Exception in thread "main" java.sql.SQLException: Listener refused the connection with the following error:
ORA-12519, TNS:no appropriate service handler found
The Connection descriptor used by the client was:
localhost:1521:XE
Do you have another way for call procedure
Please recommend me
Thank you,
Ja-aeI can call procedure
but when I using my application too long
I found error :
Exception in thread "main" java.sql.SQLException: Listener refused the connection with the following error:
ORA-12519, TNS:no appropriate service handler found
The Connection descriptor used by the client was:
localhost:1521:XE
so, I think perhaps another way to call procedure for avoid this error -
Is possible to call procedure from vorowimpl class
Hi,
please tell me how to call procedure from vorowimpl class.
Thanks in advance,
SANHi cruz,
Thanks for your reply.
I checked that link and they given for controller.
But i want to call that from the vorowimpl class. but i tried similar like calling in the controller.
here my code, please correct it if it is mistake.
public AssessmentsAMImpl xxam;
public String getXXCompName() {
//return (String) getAttributeInternal(XXCOMPNAME);
OADBTransaction txn=(OADBTransaction)xxam.getDBTransaction();
String compName=getCompName();
String xxName="";
CallableStatement cs=txn.createCallableStatement("DECLARE OUTPARAM VARCHAR2(100);begin apps.XX_COMP_ELEMENTSVO_PROC(:1,:2);end;",0);
try{
cs.setString(1,compName);
cs.registerOutParameter(2,OracleTypes.VARCHAR,0);
cs.execute();
xxName=cs.getString(1);
catch(Exception e){
try{
cs.close();
catch(Exception e){
return xxName;
} -
How to call procedure in Java from SQL Server Database
Hello Every Body
i Have Question about
How to call procedure in Java from SQL Server Database
ThanksHi,
have you tried a Google search? I just gave it a 3 second try and already found: http://stackoverflow.com/questions/6113674/how-do-i-execute-a-ms-sql-server-stored-procedure-in-java-jsp-returning-table-d
Frank -
How to Call Procedure or Function
Hi,
How to call a procedure or function in apex, Please let me know
Thanks
SudhirHi,
This post might help
Re: How to Call procedure In Processes
Regards,
Jari -
Related documents or links on how to call webservices from WDJ
Hi all
i need documents & links on how to call webservices from Webdynpro for Java.
if anybody send the documents on sample scenarios on the same then it is the great help to me...
Thanks
SunilHi Sunil,
May these links help you.
http://help.sap.com/saphelp_nw04/helpdata/en/f7/f289c67c759a41b570890c62a03519/frameset.htm
http://help.sap.com/saphelp_nwce10/helpdata/en/64/0e0ffd314e44a593ec8b885a753d30/frameset.htm
http://help.sap.com/saphelp_nw04s/helpdata/en/d2/0357425e060d53e10000000a155106/frameset.htm
and the below thread to call weservices in java.
Re: How to call a web service from Java
Regards,
Supraja -
How to call procedure and package in BI
IN OBIEE how to call procedure- function and pass parameter in it.??
Thanks
Jatin.Do you mean DB function. Check this link:
http://oracle-bi.siebelunleashed.com/articles/callingdb-function-in-obiee/
For OBIEE 11g, you have additional options to make calls with Action Framework. For now, I think the above link will help.
If helpful pls mark as correct or helpful -
How to call procedure in which one formal parameter is associative array ty
how to call procedure in which one formal parameter is associative array type,
pls explain with eg.>
above code work fine but when i use case then it give error like
i identifier should be declare
& my code is as
CASE v_array(i)
WHEN 'A' THEN
insert into di_ivpn_report (ID, test_name, table_name, status, entity, proposition)
values (v_att_id, v_att_name, 'DI_'||v_array(i)||'_REPORT'||'_'||v_att_id,
v_status, v_ent_name, v_array(i));
WHEN 'B' THEN
insert into di_mpls_report (ID, test_name, table_name, status, entity, proposition)
values (v_att_id, v_att_name, 'DI_'||v_array(i)||'_REPORT'||'_'||v_att_id,
v_status, v_ent_name, v_array(i));
END CASE;
>
Then you have to use ordinary loop
PROCEDURE insert_update_***_array (TRANID IN VARCHAR2, ATT_NAME IN VARCHAR2, ENT_NAME VARCHAR2, v_array IN ***_array)
IS
v_tranid VARCHAR2(1);
v_att_name VARCHAR2(100) := ATT_NAME;
v_ent_name VARCHAR2(100) := ENT_NAME;
v_att_id VARCHAR2(6);
v_ent_id NUMBER;
v_status VARCHAR2(20) DEFAULT 'INACTIVE';
I NUMBER;
BEGIN
i := v_array.first;
while i is not null loop
CASE v_array(i)
WHEN 'A' THEN
insert into di_ivpn_report (ID, test_name, table_name, status, entity, proposition)
values (v_att_id, v_att_name, 'DI_'||v_array(i)||'_REPORT'||'_'||v_att_id,
v_status, v_ent_name, v_array(i));
WHEN 'B' THEN
insert into di_mpls_report (ID, test_name, table_name, status, entity, proposition)
values (v_att_id, v_att_name, 'DI_'||v_array(i)||'_REPORT'||'_'||v_att_id,
v_status, v_ent_name, v_array(i));
END CASE;
i := v_array.next(i);
end loop;
end; -
Help!How can I find the name of a calling procedure from within a procedure/function?
Is there anyway to find out the name of calling procedure(database) from within a database stored procedure/function? This is required for creating an auditing module.
Thanks,
Abraham
===========
email:[email protected]You can use this query to get the procedure names that are calling your procedure.
SELECT name FROM all_Dependencies
WHERE upper(referenced_name) = 'YOUR_PROC_NAME'
In your procedure, you can get these values into a cursor and then use them one by one.
Hope this would help.
Faheem -
'ORA-12571: TNS:packet writer failure' error while calling procedure from VC++
hi all,
i am writing stored procedures and calling these from vc++. I have one stored procedure in that all
in and out perameters are numeric. When i am calling these procedure i am able to get the values properly. But in another procedure one in perameter is varchar and one out perameter is varchar. When i am calling these procedure from vc++ the error i am getting is "ORA-12571: TNS:packet writer failure". I test my vc++ code on different computers but its giving the same errors. I think ora-12571 error is when i can't communicate with oracle. But other stored procedures(in and out perameters are numbers) and sql statements are running properly. Only these stored procedure which has in and out perameters as varchar is giving me the above said problem. My out perameter in this procedure strtax is of type varchar and the length 100. Is it the problem. Please suggest me how to over come this problem.
thanks in advance,
with regards
vali.Hi
We recently changed our load balancer to a new load balancer. we get this error only after the load balancer change.
When the error occurs, I could see ORA-12571 error message only in the application error log. The listener.log has only the following message about TNS 12502. It does not have any message about ORA -12571.
TNS-12502: TNS:listener received no CONNECT_DATA from client
12-MAR-2010 12:23:26 * (CONNECT_DATA=(SERVICE_NAME=AppName)(CID=(PROGRAM=c:\wind ows\system32\inetsrv\w3wp.exe)(HOST=WEB02)(USER=NETWORK?SERVICE))) * (ADDRESS=(PROTOCOL=tcp)(HOST=172.x.x.x.x)(PORT=2202)) * establish * AppName * 0
12-MAR-2010 12:23:26 * (CONNECT_DATA=(SERVICE_NAME=AppName)(CID=(PROGRAM=c:\wind ows\system32\inetsrv\w3wp.exe)(HOST=WEB02)(USER=NETWORK?SERVICE))) * (ADDRESS=(PROTOCOL=tcp)(HOST=172.x.x.x.x)(PORT=2203)) * establish * AppName * 0
12-MAR-2010 12:23:26 * (CONNECT_DATA=(SERVICE_NAME=AppName)(CID=(PROGRAM=c:\wind ows\system32\inetsrv\w3wp.exe)(HOST=WEB02)(USER=NETWORK?SERVICE))) * (ADDRESS=(PROTOCOL=tcp)(HOST=172.x.x.x.x)(PORT=2204)) * establish * AppName * 0
12-MAR-2010 12:24:09 * 12502
TNS-12502: TNS:listener received no CONNECT_DATA from client
Thanks
Ashok -
ORA-12571: TNS:packet writer failure while calling procedure from VC++
hi all,
i am writing stored procedures and calling these from vc++. I have one stored procedure in that all
in and out perameters are numeric. When i am calling these procedure i am able to get the values properly. But in another procedure one in perameter is varchar and one out perameter is varchar. When i am calling these procedure from vc++ the error i am getting is "ORA-12571: TNS:packet writer failure". I test my vc++ code on different computers but its giving the same errors. I think ora-12571 error is when i can't communicate with oracle. But other stored procedures(in and out perameters are numbers) and sql statements are running properly. Only these stored procedure which has in and out perameters as varchar is giving me the above said problem. My out perameter in this procedure strtax is of type varchar and the length 100. Is it the problem. Please suggest me how to over come this problem.
thanks in advance,
with regards
vali.hi,
thanks for reply,
I wanna let u know that this is my personal lappy & i have installed apps dump on it in Linux & connect it through VM player in Window environment. I have recently purchased a new Antivirus K7 & installed it on my Lappy. i wanna know does this impact your application or Dbase Bcoz the application is running fine after starting the services in linux.
The only thing is that i am not able access the database through TOAD or SQL*Plus. the same error i am facing in both.
So
shud i uninstall the antivirus on this And this is the only solution to it ?
If yes, then how do i fix it again when i'll reinstall it Bcoz i need Antivirus as well.
kindly suggest.
thanks
D -
I am trying to call a procedure from a button that will work out the total of an order and display it in the total field in my master block.
I am unsure as to how to call the prodcedure from my button. I have written the procedure in the PL/SQL Stored Program Units part like it says in the help file but am now stuck.
I assume I use a WHEN-BUTTON-PRESSED trigger but what do I write in the trigger?What about placing outputs from the procedure to fields on the form?
Here is the procedure I have created:
procedure vatTotal (Order_no IN number,Total2 OUT number)
AS
CURSOR c_vatTotal is
select order_line.quantity, gre_product.cost from ord, gre_product, order_line where ord.order_no = order_line.order_no AND
gre_product.prod_no = order_line.Product_no;
Total number;
begin
Total:= 0;
for c_record in c_vatTotal loop
Total := Total + c_record.quantity * c_record.cost;
end loop;
Total2 := Total;
end;
I believe this is correct. It compiles.
I tried using Total as an out parameter but received the "duplicate fields in RECORD, TABLE or argument list are not permitted" error. -
How to call infotypes from webdynpro applications
Hi friends
My requirement is, I need to call infotypes in r/3 system. Exact requirement is I got a dropdown, which gets the data from infotype, I got a textview which also gets the the data from other infotype.My question how to call these infotypes. Is this is the same way like importing bapis or different. Please let me know the detail procedure, and any doccuemnts mail me to [email protected]
Regards
keerthiHello Keerthi,
it is no special way to call infotypes, you have to find a Bapi which return data you want (or part of this thata). When there is no Bapi which fill your requirements (or you must call to much bapis) i think you should write your own bapi. Last step is using this (own or found) in wdp.
Regards
Bogdan -
How to call infotypes from webdynpro application
Hi friends
My requirement is, I need to call infotypes in r/3 system. Exact requirement is I got a dropdown, which gets the data from infotype, I got a textview which also gets the the data from other infotype.My question how to call these infotypes. Is this is the same way like importing bapis or different. Please let me know the detail procedure, and any doccuemnts mail me to [email protected]
Regards
keerthiFor reading HR infotypes you have to do the following
a. Create a Remote enabled function module (FM) in the HR syste. This FM shall wrap the standard FM HR_READ_INFOTYPE.
b. Create a Model in your webdynpro project for the FM you developed in step a.
Thanks and Regards,
Prasanna Krishnamurthy
Maybe you are looking for
-
Hiding old apps from showing in App store?
Using a Mac, I'm logged into iTunes and looking at purchased apps from a few years back on my iPhone 4 and iPad2 that I want to hide from being shown on my new Air2. I do not see a way to delete the apps or hide them. How is this done? Thanks.
-
Tax not calculating for loss of pay on the reduced basic pay
Hi Experts, We have an employee who has LOP for five days and hence the basic pay is reduced. However for tax calculation the system is not considering the reduced basic pay, it is considering the actual basic pay. Eg Employee X has 5 day Loss Of Pay
-
how to install apple mobile device support in other drives other than C drive, how to install apple mobile device support in other drives other than C drive as my C drive is full ...
-
Playing songs off iPOD without installed software.
Ok so I am aware that if we set my iPod classic to manually manage and disk use mode, we can transfer it around with us and plug it into a computer with itunes we can listen to the music right off the ipod. I am wanting to be able to either install s
-
Error Like........
Hi, I have error like....... Invalid Response Code: (401) Unauthorized. The requested URL was:"http://localhost:50000/AdobeDocumentServices/Config?style=document" Regards, Gurprit Bhatia