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?
Similar Messages
-
How to call oracle stored procedure with OUT parameter?
I create oracle stored procedure in eclipse oepe
PROCEDURE SP_SELECT_ORA (
ID_INPUT IN VARCHAR2,
ID_OUTPUT OUT VARCHAR2,
PASSWD_OUTPUT OUT VARCHAR2,
NAME_OUTPUT OUT VARCHAR2) IS
BEGIN
SELECT EMP_ID, EMP_Passwd, EMP_Name
INTO ID_OUTPUT, PASSWD_OUTPUT, NAME_OUTPUT
FROM family
WHERE EMP_ID = ID_INPUT;
END;
and I try to call the sp in jpa like below,
@NamedNativeQueries({
@NamedNativeQuery(name = "callSelectSP", query = "call SP_SELECT_ORA(?,?,?,?)", resultClass = Members.class)
@Entity
@Table(name="family")
public class Members implements Serializable {
@Id
@Column(name = "EMP_ID")
private String ID;
@Column(name = "EMP_Passwd")
private String Passwd;
@Column(name = "EMP_Name")
private String Name;
==============
@PersistenceContext(unitName="MyFamily")
EntityManager em;
query = em.createNamedQuery("callSelectSP");
query.setParameter(1, ID);
String id_output = null;
String passwd_output = null;
String name_output = null;
query.setParameter(2,id_output);
query.setParameter(3,passwd_output);
query.setParameter(4,name_output);
query.executeUpdate();
member = (Members)query.getSingleResult();
But this query throws exception,
19:55:35,500 WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (http--127.0.0.1-8080-1) SQL Error: 1465, SQLState: 72000
19:55:35,500 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (http--127.0.0.1-8080-1) ORA-01465: invalid hex number
I don't know how. Pls, give me your advice. Thanks in advnace.
Best regardsThank you for your reply, Chris!
I tried this one.
@NamedNativeQueries({
@NamedNativeQuery(name = "callSelectSP", query = "exec SP_SELECT_ORA( ?, :id_output, :passwd_output, :name_output) " , resultClass = Members.class)
@Entity
@Table(name="family")
public class Members implements Serializable
===================
query = em.createNamedQuery("callSelectSP");
query.setParameter(1, ID);
String id_output = null;
String passwd_output = null;
String name_output = null;
query.setParameter("id_output", id_output);
query.setParameter("passwd_output", passwd_output);
query.setParameter("name_output",name_output);
query.executeUpdate();
On Console hibernate shew the sql and ora # like below,
19:59:25,160 INFO [stdout] (http--127.0.0.1-8080-1) Hibernate: exec SP_SELECT_ORA( ?, ?, ?, ?)
19:59:25,192 WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (http--127.0.0.1-8080-1) SQL Error: 900, SQLState: 42000
19:59:25,192 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (http--127.0.0.1-8080-1) ORA-00900: Invalid SQL statement
Pls, inform me your advice. Thanks in advance.
Best regards. -
Calling ORACLE Store Procedure with parameters in user define function
Hi everybody,
We have a scenario connecting Oracle DB thru JDBC adapter.
We have to call store procedure with input parameter and output parameter to retrieve data from DB. The implementation was made using JDBC adapter by building the correct XML message with EXECUTE action, and it works fine.
Now we need to use DB lookup within mapping. I wrote users define function with SELECT statement (using the JDBC adapter) and it works fine but I need to call store procedure in ORACLE instead of SELECT statement.
I found lot of examples concerning DB lookup but none of them explained how to write UDF calling store procedure in ORACLE with input and output parameters.
I am looking for an example.
Thanks in advance,
GigiI agree with you, but issue is we have lots of existing store procedure, which we need to call where damn required. I am sure those will be few but still i need to find out.
If you think you are going to get existing MS Stored Procedures or Oracle Packages that had nothing to do with the ORM previously to work that are not geared to do simple CRUD operations with the ORM and the database tables, you have a rude awakening
coming that's for sure. You had better look into using ADO.NET and Oracle Command objects and call those Oracle Packages by those means and use a datareader.
You could use the EF backdoor, call Oracle Command object and use the Packages, if that's even possible, just like you can use MS SQL Server Stored Procedures or in-line T-SQL via the EF backdoor.
That's about your best shot.
http://blogs.msdn.com/b/alexj/archive/2009/11/07/tip-41-how-to-execute-t-sql-directly-against-the-database.aspx -
Getting error while Calling Oracle Stored Procedure with output Parameter
HI All,
From long days i am working on this but i unable to solve it.
Even i have studied so many forums in SAP but i didn't find the solution.
I am calling Oracle Store procedure with 3 inputs and 1 output without cursor.
Store Procedure:-
CREATE OR REPLACE PROCEDURE PDS.send_rm
IS
proc_name VARCHAR2(64) := 'send_rm';
destination_system VARCHAR2(32) := 'RAWMAT';
xml_message VARCHAR2(4000);
status_code INTEGER;
status_message VARCHAR2(128);
debug_message VARCHAR2(128);
p_ret INTEGER;
BEGIN
DBMS_OUTPUT.PUT_LINE( proc_name || ' started' );
xml_message := '<RAW_MATERIAL>'||
'<BAR_CODE>10000764601</BAR_CODE>'||
'<MATERIAL>1101448</MATERIAL>'||
'<VENDOR_CODE/>'||
'<PRODUCTION_DATE>0000-00-00</PRODUCTION_DATE>'||
'<EXPIRE_DATE>0000-00-00</EXPIRE_DATE>'||
'<BATCH/>'||
'<PO_NUM/>'||
'<MATERIAL_DESCRIPTION>POWER SUPPLY</MATERIAL_DESCRIPTION>'||
'<SPEC_NAME/>'||
'<STOCK_CODE>BSW-JH</STOCK_CODE>'||
'<INSPECTION_LOT>00</INSPECTION_LOT>'||
'<USAGE_DECISION_CODE/>'||
'<MATERIAL_GROUP>031</MATERIAL_GROUP>'||
'</RAW_MATERIAL>';
dbms_output.put_line('XML '||xml_message);
-- vp_interface.load_rawmat@cnprpt1_pds(SYSDATE, destination_system,
-- xml_message, p_ret);
vp_interface.load_rawmat(SYSDATE, destination_system,
xml_message, p_ret);
dbms_output.put_line('Return Code '||p_ret);
COMMIT;
EXCEPTION
WHEN OTHERS THEN
status_code := SQLCODE;
status_message := SUBSTR(SQLERRM, 1, 64);
-- Extract_Error_Logger(proc_name, 'LOCAL', SYSDATE, -999,
-- status_message, 0, debug_message);
ROLLBACK;
END send_rm;
And while i am calling this Store procedure in MII, I am facing error.
I have tried different ways but didnt solved
In SQL Query, i kept mode as: FixedQueryOutput
Can anyone tell me or send code for calling above store procedure
And onemore thing, While creating store procedure in Oracle for MII. Do we need to Create output parameter as cursor or normal.
Thanks,
Kind Regards,
Praveen Reddy MHi Praveen
Our wrapper was created because we could not modify the procedure we call (it was not returning a cursor).
CREATE OR REPLACE PROCEDURE CHECK_PUT_IN_USE
(STRCMPNAME in varchar2,
STRSCANLABEL in varchar2,
RCT1 out SYS_REFCURSOR
AS
charDispo Char(1);
charStatus Char(1);
intCatNo Integer;
charCatDispo Char(1);
strCatQual VarChar2(2);
strCatDesc VarChar2(30);
strMsg VarChar2(128);
BEGIN
qa.check_put_in_use@AR(STRCMPNAME,
STRSCANLABEL,
charDispo,
charStatus,
intCatNo,
charCatDispo,
strCatQual,
strCatDesc,
strMsg);
OPEN RCT1
FOR Select charDispo,charStatus,charDispo,charStatus,intCatNo,charCatDispo,strCatQual,strCatDesc,strMsg from Dual;
END;
Hope this helps
Regards
Amrik
then with a FixedQueryWithOutput
call mixar.qasap.wrapper_update_put_in_use('[Param.1]','[Param.2]',[Param.3],?)
Hope this helps. -
Calling a package procedure with Date parameter only
Hi All,
Please help me to call a package procedure with Date parameter from sql prompt.
ArifCheck the below procedure.
SQL> ed
Wrote file afiedt.buf
1 create or replace procedure procdate (p_date_in date)
2 is
3 p_date_out date;
4 begin
5 p_date_out := add_months(p_date_in,6);
6 dbms_output.put_line(p_date_out);
7* end;
SQL> /
Procedure created.
SQL> exec procdate('01-JAN-2010');
01-JUL-10
PL/SQL procedure successfully completed.
SQL> exec procdate(to_date('01/01/2010','DD-MM-YYYY'));
01-JUL-10
PL/SQL procedure successfully completed.
SQL> exec procdate('31-DEC-2010');
30-JUN-11
PL/SQL procedure successfully completed. -
About JDBC CALL STORE PROCEDURE with out parameter is greater than 4000
Hi Guys,
I have a problem call store procedure with a large string.
as i know varchar2 can contain 32767 characters in pl/sql .
But when i used varchar2 as a out parameter in a store procedure, if the out parameter is greater than 4000 characters , it always give me error message as 'the buffer is too small'.
why it happened?
I read some article that says i need configure a property in data-source.xml , and jdbc 10g driver already solved this problem, but i used jdev 10.1.3.2 ,the driver should be fine.
How can i solve this problem?
Thanks in advance,
AppCatObject is Foundation, Execute Script
This is for a query, you can change to a stored procedure call. Pull the value back in the Java code then put into the process variable.
import javax.naming.InitialContext;
import javax.sql.DataSource;
import java.sql.*;
PreparedStatement stmt = null;
Connection conn = null;
ResultSet rs = null;
try {
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:IDP_DS");
conn = ds.getConnection();
stmt = conn.prepareStatement("select FUBAR from TB_PT_FUBAR where PROCESS_INSTANCE_ID=?");
stmt.setLong(1, patExecContext.getProcessDataLongValue("/process_data/@inputID"));
rs = stmt.executeQuery();
rs.next();
patExecContext.setProcessDataStringValue("/process_data/outData", rs.getString(1));
} finally {
try {
rs.close();
} catch (Exception rse) {}
try {
stmt.close();
} catch (Exception sse) {}
try {
conn.close();
} catch (Exception cse) {} -
Hi there,
I'm very new to this jdeveloper for bpel and I would like to know how do you call a stored procedure with parameters.
I've been using dbadapters to insert and update database with a transform function but I don't know if you need to do transformation do a stored procedure.Hi,
have you read:
http://download-east.oracle.com/docs/cd/B31017_01/integrate.1013/b28994/adptr_db.htm#CHDFBBCD -
How to call a Stored Procedure with a REF CURSOR output parameter
I am looking forward an example that call a stored function/procedure with a REF CURSOR output parameter and get the result.
In other words, I have a stored function/procedure that execute a SELECT statement using the OCI library and then it could get the values of each column and each row.
I put a code snippet, it have only the main thing to call a simple stored procedure and print the name of each column of the cursor, but I couldn´t to print out the values in the table that call the stored procedure.
I understand that the next step, it is to call a OCIStmtFetch.
How to associate the cursor with the OCIStmtFetch?
If you need more information, only tell me.
I am using ANSI C with HP-UX Operative System (C for HP-UX) and Oracle 10g.
Regards.
Antonio Garcia
/* callOracleSP */
#include <stdio.h>
#include <string.h>
#include <oci.h>
#include <stdlib.h>
char* pConnectChar ="server";
char* pUsernameChar = "user";
char* pPasswordChar = "passwd";
char* sqlCharArray1 = "BEGIN SP_GETCITIES(:s, :c); END;";
int retval;
ub4 parmcnt=0;
ub4 pos2=0;
text *pcoln[20];
ub4 namelen[20];
char state_key[5];
OCIStmt* pOciStatement;
OCIStmt* pOciStatCursor;
OCIError* pOciError;
OCIEnv* pOciEnviron;
OCIServer* pOciServer;
OCISession* pOciSession;
OCISvcCtx* pOciServiceContext;
OCIBind* pOciBind[500];
OCIParam* pOciParam;
int main()
retval = OCIEnvCreate(&pOciEnviron, OCI_DEFAULT, NULL, NULL, NULL, NULL,0,NULL);
retval = OCIEnvInit(&pOciEnviron, OCI_DEFAULT, 0, NULL);
retval = OCIHandleAlloc(pOciEnviron, (void **)&pOciError, OCI_HTYPE_ERROR, 0, NULL);
retval = OCIHandleAlloc(pOciEnviron, (void **)&pOciServiceContext, OCI_HTYPE_SVCCTX, 0, NULL);
retval = OCIHandleAlloc(pOciEnviron, (void **)&pOciStatement, OCI_HTYPE_STMT, 0, NULL);
retval = OCILogon(pOciEnviron,pOciError,&pOciServiceContext,(unsigned char *)pUsernameChar,
strlen(pUsernameChar), (unsigned char *)pPasswordChar, strlen(pPasswordChar),
(unsigned char *)pConnectChar,strlen(pConnectChar));
printf("OCILogon retval=%d\n",retval);
retval = OCIStmtPrepare(pOciStatement, pOciError, (unsigned char *)sqlCharArray1,strlen(sqlCharArray1),
OCI_NTV_SYNTAX, OCI_DEFAULT);
printf("StmtPrepare retval=%d\n",retval);
retval = OCIHandleAlloc(pOciEnviron, (void **)&pOciStatCursor, OCI_HTYPE_STMT, 0, NULL);
retval = OCIBindByPos(pOciStatement,&pOciBind[0], pOciError, (ub4) 1, (void *)&state_key,
(sb4) sizeof(state_key), SQLT_STR, (void *) 0, (ub2 *) 0, (ub2 *)0,(ub4)0, (ub4 *)0, (ub4) OCI_DEFAULT);
printf("BindByPos OCI_HTYPE_STMT retval=%d\n",retval);
retval = OCIBindByPos(pOciStatement,&pOciBind[1], pOciError, (ub4) 2, (void *)&pOciStatCursor,
(sb4) 0, SQLT_RSET, (void *) 0, (ub2 *) 0, (ub2 *)0,(ub4)0, (ub4 *)0, (ub4) OCI_DEFAULT);
printf("BindByPos OCI_HTYPE_STMT retval=%d\n",retval);
strcpy(state_key,"CA");
retval = OCIStmtExecute(pOciServiceContext, pOciStatement, pOciError, (ub4)1, (ub4) 0,
(OCISnapshot *)NULL, (OCISnapshot *)NULL, (ub4) OCI_DEFAULT);
printf("StmtExecute retval=%d\n",retval);
/* How to get the values of the cursor? */
/* Get number of parameters of the Cursor */
OCIAttrGet((void *) pOciStatCursor, (ub4)OCI_HTYPE_STMT, (void*) &parmcnt,(ub4 *) 0,
(ub4)OCI_ATTR_PARAM_COUNT, pOciError);
printf("\nNumber of parameters of the cursor = %d\n",parmcnt);
for (int pos = 1; pos <= (int)parmcnt; pos++)
OCIAttrGet((void *) pOciStatCursor, (ub4)OCI_HTYPE_STMT, (void*) &pos2,(ub4 *) 0,
(ub4)OCI_ATTR_CURRENT_POSITION, pOciError);
retval = OCIParamGet((void *)pOciStatCursor, (ub4)OCI_HTYPE_STMT, pOciError, (void **)&pOciParam,
(ub4) pos );
OCIAttrGet((void*) pOciParam, (ub4) OCI_DTYPE_PARAM,(void*) &pcoln[pos-1],(ub4 *) &namelen[pos-1],
(ub4) OCI_ATTR_NAME,(OCIError *)pOciError );
for (int i = 1; i <=(int)parmcnt; i++)
printf("Column %i\tNAME = %.*s\n",i,namelen[i-1],pcoln[i-1]);
return 0;
This is the script that create the table, insert records and create the stored procedure
CREATE TABLE CITIES (
STATE_CODE VARCHAR2(2) NULL,
CITY_CODE NUMBER(15,5) NULL,
CITY_NAME VARCHAR2(30) NULL
INSERT INTO CITIES(STATE_CODE, CITY_CODE, CITY_NAME)
VALUES('CA', 30, 'SAN DIEGO')
INSERT INTO CITIES(STATE_CODE, CITY_CODE, CITY_NAME)
VALUES('CA', 40, 'SACRAMENTO')
INSERT INTO CITIES(STATE_CODE, CITY_CODE, CITY_NAME)
VALUES('FL', 10, 'MIAMI')
INSERT INTO CITIES(STATE_CODE, CITY_CODE, CITY_NAME)
VALUES('FL', 20, 'ORLANDO')
INSERT INTO CITIES(STATE_CODE, CITY_CODE, CITY_NAME)
VALUES('NY', 10, 'NEW YORK')
INSERT INTO CITIES(STATE_CODE, CITY_CODE, CITY_NAME)
VALUES('NY', 20, 'ALBANY')
INSERT INTO CITIES(STATE_CODE, CITY_CODE, CITY_NAME)
VALUES('CA', 10, 'LOS ANGELES')
INSERT INTO CITIES(STATE_CODE, CITY_CODE, CITY_NAME)
VALUES('CA', 20, 'SAN FRANCISCO')
CREATE OR REPLACE PACKAGE globalPkg AUTHID CURRENT_USER AS
/* The following are T/SQL specific global variables. */
TYPE RCT1 IS REF CURSOR;/*new weak cursor definition*/
END globalPkg;
CREATE OR REPLACE PROCEDURE SP_ADDCITY(
P_STATE_CODE IN VARCHAR,
P_CITY_CODE IN NUMBER,
P_CITY_NAME IN VARCHAR2,
P_RETURN IN OUT NUMBER)
AS
StoO_error INTEGER;
StoO_selcnt INTEGER;
StoO_rowcnt INTEGER;
StoO_errmsg VARCHAR2(255);
BEGIN
StoO_rowcnt := 0;
StoO_error := 0;
StoO_selcnt := 0;
P_RETURN := 0;
INSERT INTO CITIES (STATE_CODE, CITY_CODE, CITY_NAME)
VALUES (P_STATE_CODE, P_CITY_CODE, P_CITY_NAME);
StoO_rowcnt := SQL%ROWCOUNT;
EXCEPTION
WHEN TOO_MANY_ROWS THEN
StoO_rowcnt := 2;
WHEN OTHERS THEN
StoO_rowcnt := 0;
StoO_selcnt := 0;
StoO_error := SQLCODE;
StoO_errmsg := SQLERRM;
IF StoO_error != 0 THEN
BEGIN
P_RETURN := 1;
RETURN;
END;
END IF;
END;
CREATE OR REPLACE PROCEDURE SP_GETCITIES(
STATE_KEY IN VARCHAR,
RC1 IN OUT globalPkg.RCT1)
AS
StoO_error INTEGER;
StoO_selcnt INTEGER;
StoO_rowcnt INTEGER;
StoO_errmsg VARCHAR2(255);
BEGIN
StoO_rowcnt := 0;
StoO_error := 0;
StoO_selcnt := 0;
OPEN RC1 FOR
SELECT STATE_CODE, CITY_CODE, CITY_NAME
FROM CITIES
WHERE STATE_CODE = STATE_KEY
ORDER BY CITY_CODE;
StoO_rowcnt := SQL%ROWCOUNT;
EXCEPTION
WHEN OTHERS THEN
StoO_rowcnt := 0;
StoO_error := SQLCODE;
StoO_errmsg := SQLERRM;
END;
/Hi Mark,
Thanks for your recommendations.
I change the code with OCIDefineByPos, one for each parameter from cursor and then use the OCIStmtFetch.
I don´t receive a error when call OCIDefineByPos, but when I call OCIStmtFetch receive a -1 error number.
What is wrong with the code?
The script is the same.
I need your help!
Best Regards!
Antonio Garcia (Mexico)
This the new code:
#include <stdio.h>
#include <string.h>
#include <oci.h>
#include <stdlib.h>
char* pConnectChar ="ORAC617";
char* pUsernameChar = "C617_005_DBO_01";
char* pPasswordChar = "Tempora1";
char* sqlCharArray1 = "BEGIN SP_GETCITIES(:s, :c); END;";
int retval;
ub4 parmcnt=0;
ub4 pos2=0;
sb2 *c_indp;
text *pcoln[20], *name,*name2;
ub4 namelen[20],len;
ub2 type,size;
char state_key[5];
OCIDefine *pdef;
OCIBind *p_bnd;
ub1 **c_buf;
OCIStmt* pOciStatement; /* Statement handle */
OCIStmt* pOciStatCursor; /* Statement handle */
OCIError* pOciError; /* Error handle */
OCIEnv* pOciEnviron; /* Environment handle */
OCIServer* pOciServer; /* Server handle */
OCISession* pOciSession; /* Session handle */
OCISvcCtx* pOciServiceContext; /* Service Context handle */
OCIBind* pOciBind[500]; /* Bind handle */
OCIParam* pOciParam; /* Param handle */
int OCI_Fetch(OCIStmt *p_select,OCIError *p_err, int *piOcc)
int iOcc, rc;
rc=OCIStmtFetch(p_select,p_err,1,OCI_FETCH_NEXT,OCI_DEFAULT);
printf("rc fetch %i",rc);
if(rc==0&&piOcc!=NULL){
printf("entro al if");
iOcc=*piOcc;
*piOcc=iOcc+1;
return rc;
int main()
int pos,i=0,rc;
retval = OCIEnvCreate(&pOciEnviron, OCI_DEFAULT, NULL, NULL, NULL, NULL,0,NULL);
printf("EnvCreate retval=%d\n", retval);
retval = OCIEnvInit(&pOciEnviron, OCI_DEFAULT, 0, NULL);
printf("EnvInit retval=%d\n",retval);
retval = OCIHandleAlloc(pOciEnviron, (void **)&pOciError, OCI_HTYPE_ERROR, 0, NULL);
printf("HandleAlloc OCI_HTYPE_ERROR retval=%d\n",retval);
retval = OCIHandleAlloc(pOciEnviron, (void **)&pOciServiceContext, OCI_HTYPE_SVCCTX, 0, NULL);
printf("HandleAlloc OCI_HTYPE_SVCCTX retval=%d\n",retval);
retval = OCIHandleAlloc(pOciEnviron, (void **)&pOciStatement, OCI_HTYPE_STMT, 0, NULL);
printf("HandleAlloc OCI_HTYPE_STMT retval=%d\n",retval);
retval = OCILogon(pOciEnviron,pOciError,&pOciServiceContext,(unsigned char *)pUsernameChar,
strlen(pUsernameChar), (unsigned char *)pPasswordChar, strlen(pPasswordChar),
(unsigned char *)pConnectChar,strlen(pConnectChar));
printf("OCILogon retval=%d\n",retval);
retval = OCIStmtPrepare(pOciStatement, pOciError, (unsigned char *)sqlCharArray1,strlen(sqlCharArray1),
OCI_NTV_SYNTAX, OCI_DEFAULT);
printf("StmtPrepare retval=%d\n",retval);
retval = OCIHandleAlloc(pOciEnviron, (void **)&pOciStatCursor, OCI_HTYPE_STMT, 0, NULL);
printf("HandleAlloc OCI_HTYPE_STMT retval=%d\n",retval);
retval = OCIBindByPos(pOciStatement,&pOciBind[0], pOciError, (ub4) 1, (void *)&state_key,
(sb4) sizeof(state_key), SQLT_STR, (void *) 0, (ub2 *) 0, (ub2 *)0,(ub4)0, (ub4 *)0, (ub4) OCI_DEFAULT);
printf("BindByPos OCI_HTYPE_STMT retval=%d\n",retval);
retval = OCIBindByPos(pOciStatement,&pOciBind[1], pOciError, (ub4) 2, (void *)&pOciStatCursor,
(sb4) 0, SQLT_RSET, (void *) 0, (ub2 *) 0, (ub2 *)0,(ub4)0, (ub4 *)0, (ub4) OCI_DEFAULT);
printf("BindByPos OCI_HTYPE_STMT retval=%d\n",retval);
strcpy(state_key,"CA");
retval = OCIStmtExecute(pOciServiceContext, pOciStatement, pOciError, (ub4)1, (ub4) 0,
(OCISnapshot *)NULL, (OCISnapshot *)NULL, (ub4) OCI_DEFAULT);
printf("StmtExecute retval=%d\n",retval);
c_buf=(ub1 **)calloc(sizeof(ub1 *),3);
c_indp=(sb2 *)calloc(sizeof(sb2 *),3);
// Get number of parameters of the Cursor
OCIAttrGet((void *) pOciStatCursor, (ub4)OCI_HTYPE_STMT, (void*) &parmcnt,(ub4 *) 0,
(ub4)OCI_ATTR_PARAM_COUNT, pOciError);
printf("\nNumber of parameters of the cursor = %d\n",parmcnt);
for (pos = 1; pos <= (int)parmcnt; pos++)
OCIAttrGet((void *) pOciStatCursor, (ub4)OCI_HTYPE_STMT, (void*) &pos2,(ub4 *) 0,
(ub4)OCI_ATTR_CURRENT_POSITION, pOciError);
retval = OCIParamGet((void *)pOciStatCursor, (ub4)OCI_HTYPE_STMT, pOciError, (void **)&pOciParam,(ub4) pos );
// Get the column name
OCIAttrGet((void*) pOciParam, (ub4) OCI_DTYPE_PARAM,(void*) &name,(ub4 *) &len, (ub4) OCI_ATTR_NAME,(OCIError *)pOciError );
// Get the column datatype
OCIAttrGet((void*) pOciParam, (ub4) OCI_DTYPE_PARAM,(void*) &type,(ub4 *)0,(ub4)OCI_ATTR_DATA_TYPE,(OCIError *)pOciError);
// Get the column size
OCIAttrGet((void*) pOciParam, (ub4) OCI_DTYPE_PARAM,(void*) &size,(ub4 *)0,(ub4)OCI_ATTR_DATA_SIZE,(OCIError *)pOciError);
printf("Column %i\tNAME = %.*s \ttype %d \tsize %d\n",pos,len,name,type,size);
// OCIDefine ByPos, one for each parameter
// c_buf store the STATE_CODE, CITY_CODE and CITY_NAME columns from the cursor
rc=OCIDefineByPos(pOciStatCursor,&pdef,(OCIError *)pOciError,pos,c_buf[pos-1],size+1,(ub2)type,(dvoid *)c_indp[pos-1],(ub2 *)0,(ub2 *)0,OCI_DEFAULT);
printf("OCIDefineByPos retval=%d\n,rc);
// call OCIStmtFetch. In the next line, I receive the error
rc=OCIStmtFetch(pOciStatCursor,pOciError,1,OCI_FETCH_NEXT,OCI_DEFAULT);
printf("rc fetch %i",rc);
return 0;
{code} -
Error while calling a stored procedure with OUT parameter.
Hi,
I am trying to call a Stored Procedure(SP) with an OUT parameter(Ref Cursor) from a third party tool. It is called using OLE-DB Data provider. In one database the procedure works fine but when I change the database the procedure call is giving following error.
Distribution Object: COM Error. COM Source: OraOLEDB. COM Error message: IDispatch error #3092. COM Description: ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'TEST1'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored.
I am not able to find as to why is this happening. Please let me know any clues /help to solve this problem.
Thanks in advance.If you're using Oracle Provider for OLE DB (OraOLEDB) to execute this stored procedure, you need to set PLSQLRSet attribute. This attribute can be set in registry, connection string, or command object. Please refer to User Documentation for more information.
-
Calling Oracle Stored procedure with OUT parameter from ODI
Hi,
I called an oracle stored procedure with following anonymous block in the ODI procedure.
Declare
Status varchar2(10);
Begin
OTM.DeleteTarget('E_KPI_TARGET_VALUE', Status);
End;
I want to capture the OUT parameter STATUS value in a project level variable.
And based on its va;lue I would like to choose between 2 interfaces in my package.
Please help me in doing this.Hi,
For that kind of situation I commoly use:
1) one step with:
create or replace package <%=odiRef.getSchemaName("W")%>.pck_var
Status varchar2(10);
end;
* transaction 9, for instance
2) step
Begin
OTM.DeleteTarget('E_KPI_TARGET_VALUE', <%=odiRef.getSchemaName("W")%>.pck_var.Status);
End;
* transaction 9
3) then, at an ODI variable, use a refresh like:
select <%=odiRef.getSchemaName("W")%>.pck_var.Status from dual
at same logical shema where the package was created.
Does it make sense to you? -
How to turn a stored procedure with a parameter into table function?
Could someone please let me know how to turn the SP below into table-value function? I want to be able to run this function by using SELECT statements with the parameter. Thanks
CREATE
PROCEDURE
[dbo].[Transformation](@year
varchar(4))
AS
BEGIN
Declare@Q1
Varchar(100)=
'['+@year+'Q1'+']'
Declare@Q2
Varchar(100)=
'['+@year+'Q2'+']'
Declare@Q3
Varchar(100)=
'['+@year+'Q3'+']'
Declare@Q4
Varchar(100)=
'['+@year+'Q4'+']'
Declare@StrQuery
Varchar(1000)
Set@StrQuery
= 'Select Date, Job, [Cost Elements],Units,
'+@Q1+'+'+'+'+@Q2+'+'+'+'+@Q3+'+'+'+'+@Q4+'
as [Amounts], ''Update'' as [Description] From Export with (nolock)'
--Print @StrQuery
Exec(@StrQuery)
ENDYou cannot use dynamic SQL in user-defined functions.
Work around (not an ideal solution, it has problems): OPENQUERY.
Blog: http://www.sqlusa.com/bestpractices2005/selectfromsproc/
Kalman Toth Database & OLAP Architect
SQL Server 2014 Design & Programming
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012 -
How to call Java Store Procedure?
Hi Everybody,
I had created a java class call FileReader and inside tht class it has two method
fileCount and fileName. fileCount is to locate the specified directory and count number of file and directory are in that directory and return back to the pl/sql and fileName is to return the filename for a specified directory. I also created a Oracle Package to call this call and the code for the java class and package listed below.
CREATE OR REPLACE PACKAGE "CIS2"."PK_FILE_READER" AS
FUNCTION F_GET_FILE_COUNT(P_DIR IN VARCHAR2) RETURN NUMBER;
FUNCTION F_GET_FILE_NAME(P_DIR IN VARCHAR2, P_POS IN NUMBER) RETURN VARCHAR2;
END PK_FILE_READER;
CREATE OR REPLACE PACKAGE BODY "CIS2"."PK_FILE_READER" AS
FUNCTION F_GET_FILE_COUNT(P_DIR IN VARCHAR2) RETURN NUMBER
AS LANGUAGE JAVA NAME 'FileReader.fileCount(java.lang.String) return int';
FUNCTION F_GET_FILE_NAME(P_DIR IN VARCHAR2, P_POS IN NUMBER) RETURN VARCHAR2
AS LANGUAGE JAVA NAME 'FileReader.fileName(java.lang.String, int) return java.lang.String';
END PK_FILE_READER;
Class : FileReader
import java.io.*;
public class FileReader
public static int fileCount(String dir)
int recount;
File path = new File(dir);
File[] FileList = path.listFiles();
recount = FileList.length;
return recount;
} // end method fileCount
public static String fileName(String dir, int pos)
String filename;
File path = new File(dir);
File[] FileList = path.listFiles();
filename = FileList[pos].getAbsolutePath();
return filename;
} // end method fileName
} // end of class FileReader
The package created successful and the Java complite okey
The only problem is when I try to use the loadjava it give me the oracle error ora-29545
badly formed class
I am not sure what is the problem? Did I create the java problem for FileReader is incorrect? or I don't know how to use the loadjava function.
I did check the user_object and I did see there is a object name for FileReader but is invalid.
Can anyone could tell me what is the problem and how to fix it??
Thanks you so muchThe good news is, there's nothing wrong with your code:
SQL> SET serveroutput ON SIZE 1000000
SQL> SET lines 1000
SQL> SET pages 100
SQL>
SQL> exec dbms_java.set_output(2000)
PL/SQL procedure successfully completed.
SQL>
SQL>
SQL> CREATE AND COMPILE JAVA SOURCE NAMED "FileReader" AS
2 import java.io.*;
3
4 public class FileReader
5 {
6 public static int fileCount(String dir)
7 {
8 int recount;
9
10 File path = new File(dir);
11 File[] FileList = path.listFiles();
12
13 recount = FileList.length;
14
15 return recount;
16 } // end method fileCount
17
18 public static String fileName(String dir, int pos)
19 {
20 String filename;
21
22 File path = new File(dir);
23 File[] FileList = path.listFiles();
24
25 filename = FileList[pos].getAbsolutePath();
26
27 return filename;
28 } // end method fileName
29
30 } // end of class FileReader
31 ;
32 /
Java created.
SQL> SELECT owner, object_type, status, dbms_java.longname(object_name) class, created, last_ddl_tim
e
2 FROM all_objects
3 WHERE substr(object_type,1,4)='JAVA'
4 AND dbms_java.longname(object_name) LIKE '%FileReaderp%'
5 /
no rows selected
SQL> SELECT owner, object_type, status, dbms_java.longname(object_name) class, created, last_ddl_tim
e
2 FROM all_objects
3 WHERE substr(object_type,1,4)='JAVA'
4 AND dbms_java.longname(object_name) = '%FileReader%'
5 /
OWNER OBJECT_TYPE STATUS
CLASS
CREATED LAST_DDL_
APC JAVA CLASS VALID
FileReader
28-FEB-06 28-FEB-06
APC JAVA SOURCE VALID
FileReader
28-FEB-06 28-FEB-06
8 rows selected.
SQL> CREATE OR REPLACE PACKAGE "PK_FILE_READER" AS
2
3 FUNCTION F_GET_FILE_COUNT(P_DIR IN VARCHAR2) RETURN NUMBER;
4
5 FUNCTION F_GET_FILE_NAME(P_DIR IN VARCHAR2, P_POS IN NUMBER) RETURN VARCHAR2;
6
7 END PK_FILE_READER;
8 /
Package created.
SQL>
SQL> CREATE OR REPLACE PACKAGE BODY "PK_FILE_READER" AS
2
3 FUNCTION F_GET_FILE_COUNT(P_DIR IN VARCHAR2) RETURN NUMBER
4 AS LANGUAGE JAVA NAME 'FileReader.fileCount(java.lang.String) return int';
5
6 FUNCTION F_GET_FILE_NAME(P_DIR IN VARCHAR2, P_POS IN NUMBER) RETURN VARCHAR2
7 AS LANGUAGE JAVA NAME 'FileReader.fileName(java.lang.String, int) return java.lang.String';
8
9 END PK_FILE_READER;
10 /
Package body created.
SQL>
SQL> var n number
SQL> exec :n := PK_FILE_READER.F_GET_FILE_COUNT('C:\temp')
PL/SQL procedure successfully completed.
SQL> print n
N
295
SQL> So this is obviously a configuration issue.
Cheers, APC -
How to call a stored procedure with only one output parameter using toplink
Can anybody help me to get out of this exception. I have tried through several ways, but could not find the solution.
I have a following stored proc : -
CREATE OR REPLACE PROCEDURE spt_remove_duplicates_pr (outbuffer OUT VARCHAR2)
IS
buff VARCHAR2(32000) := ' ';
BEGIN
buff := ' Hi From Stored Proc' ;
outbuffer : = buff;
END;
When I am executing it using following code :-
StoredProcedureCall call = new StoredProcedureCall();
call.setProcedureName("spt_remove_duplicates_pr");
call.addNamedOutputArgument("a","a",String.class);
ValueReadQuery query = new ValueReadQuery();
query.setCall(call);
String buff1 = (String) session.executeQuery(query);
I am getting the exception as : -
LOCAL EXCEPTION STACK:
EXCEPTION [TOPLINK-4002] (TopLink - 9.0.3.4 (Build 432)): oracle.toplink.exceptions.DatabaseException
EXCEPTION DESCRIPTION: java.sql.SQLException: ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'SPT_REMOVE_DUPLICATES_PR'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
INTERNAL EXCEPTION: java.sql.SQLException: ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'SPT_REMOVE_DUPLICATES_PR'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
ERROR CODE: 6550
at oracle.toplink.exceptions.DatabaseException.sqlException(Unknown Source)
at oracle.toplink.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(Unknown Source)
at oracle.toplink.internal.databaseaccess.DatabasePlatform.executeStoredProcedureCall(Unknown Source)
at oracle.toplink.internal.databaseaccess.DatabaseAccessor.executeCall(Unknown Source)
at oracle.toplink.threetier.ServerSession.executeCall(Unknown Source)
at oracle.toplink.internal.queryframework.CallQueryMechanism.executeCall(Unknown Source)
at oracle.toplink.internal.queryframework.CallQueryMechanism.executeCall(Unknown Source)
at oracle.toplink.internal.queryframework.CallQueryMechanism.executeSelectCall(Unknown Source)
at oracle.toplink.internal.queryframework.CallQueryMechanism.executeSelect(Unknown Source)
at oracle.toplink.queryframework.DirectReadQuery.executeNonCursor(Unknown Source)
at oracle.toplink.queryframework.DataReadQuery.execute(Unknown Source)
at oracle.toplink.queryframework.ValueReadQuery.execute(Unknown Source)
at oracle.toplink.queryframework.DatabaseQuery.execute(Unknown Source)
at oracle.toplink.queryframework.ReadQuery.execute(Unknown Source)
at oracle.toplink.publicinterface.Session.internalExecuteQuery(Unknown Source)
at oracle.toplink.threetier.ServerSession.internalExecuteQuery(Unknown Source)
at oracle.toplink.publicinterface.Session.executeQuery(Unknown Source)
at oracle.toplink.publicinterface.Session.executeQuery(Unknown Source)
at com.marshmc.eta.reuse.persistent.PersistentService$DuplicateRemovalThread.run(Unknown Source)
INTERNAL EXCEPTION STACK:
java.sql.SQLException: ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'SPT_REMOVE_DUPLICATES_PR'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:582)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1983)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1141)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2149)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:2032)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2894)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:608)
at oracle.toplink.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(Unknown Source)
at oracle.toplink.internal.databaseaccess.DatabasePlatform.executeStoredProcedureCall(Unknown Source)
at oracle.toplink.internal.databaseaccess.DatabaseAccessor.executeCall(Unknown Source)
at oracle.toplink.threetier.ServerSession.executeCall(Unknown Source)
at oracle.toplink.internal.queryframework.CallQueryMechanism.executeCall(Unknown Source)
at oracle.toplink.internal.queryframework.CallQueryMechanism.executeCall(Unknown Source)
at oracle.toplink.internal.queryframework.CallQueryMechanism.executeSelectCall(Unknown Source)
at oracle.toplink.internal.queryframework.CallQueryMechanism.executeSelect(Unknown Source)
at oracle.toplink.queryframework.DirectReadQuery.executeNonCursor(Unknown Source)
at oracle.toplink.queryframework.DataReadQuery.execute(Unknown Source)
at oracle.toplink.queryframework.ValueReadQuery.execute(Unknown Source)
at oracle.toplink.queryframework.DatabaseQuery.execute(Unknown Source)
at oracle.toplink.queryframework.ReadQuery.execute(Unknown Source)
at oracle.toplink.publicinterface.Session.internalExecuteQuery(Unknown Source)
at oracle.toplink.threetier.ServerSession.internalExecuteQuery(Unknown Source)
at oracle.toplink.publicinterface.Session.executeQuery(Unknown Source)
at oracle.toplink.publicinterface.Session.executeQuery(Unknown Source)
at com.marshmc.eta.reuse.persistent.PersistentService$DuplicateRemovalThread.run(Unknown Source)I got the partial solution. The code is working now, however I am not getting the return value from stored proc.
The changed code is as :-
StoredProcedureCall call = new StoredProcedureCall();
call.setProcedureName("spt_remove_duplicates_pr");
call.addNamedOutputArgument("outbuffer","outbuffer",StringBuffer.class);
ValueReadQuery query = new ValueReadQuery();
query.setCall(call);
StringBuffer buff1 = (StringBuffer) session.executeQuery(query);
System.err.println("Done ! Output is : " + buff1);
The result is :-
Done ! Output is : null
How can I get the output ? -
How to call a oracle procedure with in/out parameter frm unix shell script?
Hi,
I need to call an oracle stored procedure from unix script. The procedure has 1 input parameter and 2 output parameter. Please send me the syntax for the same. Based on the output values of procedure, I have to execute some more commands in unix script.
Thanks and regards
AAn example :
TEST@db102 SQL> select ename, job from emp
2 where empno = 7902;
ENAME JOB
FORD ANALYST
TEST@db102 SQL> create or replace procedure show_emp (
2 v_empno in number,
3 v_ename out varchar2,
4 v_job out varchar2 )
5 is
6 begin
7 select ename, job into v_ename, v_job
8 from emp
9 where empno = v_empno;
10 end;
TEST@db102 SQL> /
Procedure created.
TEST@db102 SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
[ora102 work db102]$ IN=7902
[ora102 work db102]$ set `sqlplus -s test/test@db102 << !
var out1 varchar2(30);
var out2 varchar2(30);
set pages 0
set feed off
exec show_emp($IN,:out1,:out2);
print
exit
`[ora102 work db102]$ echo $1 $2
FORD ANALYST
[ora102 work db102]$ -
How to call Java Store Procedure Part III
Hi APC
Everything is working now but when I exce this line
exec :n := PK_FILE_READER.F_GET_FILE_COUNT('C:\')
It did give me a number of file count but the problem was the C:\ dir is from
the server side not from the local PC C Drive.
My question is there a way you can point to your local drive? or your network drive? to get the file count
thanks
davidYou would either need to have some component that runs on the client machine (i.e. an application you deploy on the client either directly or through something like an ActiveX control/ Java applet on a web site) or your client file system would have to be mounted and accessible to the server at the file system level.
In other words, not easily.
Justin
Maybe you are looking for
-
Workarounds of 32K-limitation in jdbc:kprb needed!
Hello ALL. Can you help me with solution of workarounds the limitation in jdbc:kprb(internal driver) for stored java? I try to put large string more than 32K into LONG field type using internal driver and Java Stored Procedure. And I get the error: "
-
Hopefully someone can help me with my question. When I try to add photos from PhotoStream into my iPhoto Library a message appears asking to view the photo in the library (as if it were already imported). When I click View it brings me to my iPhoto
-
HT201250 First generation MacBook Air slow on Lion OS
My macbook air 2GB 667Mhz DDR2 1.8GHz intel core 2 duo was just upgraded to Mac OS X 10.7. It was Ok for a while but now its slow. i found out that it uses up to 1.9GB of CPU memory to process requests. do i downgrade to 10.6 or install updates? i re
-
Hi, I installed TREX7.0 newly into Netweavwer Portals. Can any one provide me any good link to know How To use TREX in Netweaver Portals. Regds Phanikumar
-
No Such Entity error when persisting changes to web descriptor
Hello. Has anyone else run into trouble editing a web descriptor via the Admin Console? When I attempt to save any changes I get the following error: ' No Such Entity. There is no longer a Web Descriptor named XYZ Runtime entity may have ceased to ex