VARRAY as Stored Proc output parameter
VARRAY as Stored Proc output parameter
I have an Oracle VARRAY data type declared as follows:
CREATE TYPE NUMBER_ARRAY AS VARRAY(100) OF NUMBER;
I have a stored procedure which takes a single input and
returns a NUMBER_ARRAY as output:
CREATE OR REPLACE PROCEDURE one_in_number_array_out(
IN_PARAM IN NUMBER,
OUT_NUMBER_ARRAY OUT NUMBER_ARRAY )
IS
BEGIN
-- OUT_NUMBER_ARRAY getting populated here
END one_in_number_array_out;
I want to be able hit this proc using TopLink StoreProcedureCall objects and retrieve through a map.
I thought I would be able to do something like:
public void execute() {
StoredProcedureCall call = new StoredProcedureCall();
call.setProcedureName( getStoredProcedureName() );
call.addNamedArgumentValue("IN_NUMBER_PARAM", new Double(324) );
call.addNamedOutputArgument("OUT_NUMBER_ARRAY", "numberArray"); // use an alias
ClientSession clientSession = .....getClientSession();
// EXCEPTION OCCURS on following call:
Map row = (Map) clientSession.executeSelectingCall( call ).firstElement();
Object numberArray = row.get( "numberArray" );
System.out.println("numberArray = " + numberArray);
But, when I call the stored proc I get the following stack trace:
LOCAL EXCEPTION STACK:
EXCEPTION [TOPLINK-4002] (TopLink - 9.0.3 (Build 423)): 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 'ONE_IN_NUMBER_ARRAY_OUT'
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 'ONE_IN_NUMBER_ARRAY_OUT'
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.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.DataReadQuery.executeNonCursor(Unknown Source)
at oracle.toplink.queryframework.DataReadQuery.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.threetier.ClientSession.internalExecuteQuery(Unknown Source)
at oracle.toplink.publicinterface.Session.executeQuery(Unknown Source)
at oracle.toplink.publicinterface.Session.executeQuery(Unknown Source)
at oracle.toplink.publicinterface.Session.executeSelectingCall(Unknown Source)
at com.gs.lab.rr.db.plsql.gs_practice_pkg.OneInNumberArrayOutStoredProcedure.execute(OneInNumberArrayOutStoredProcedure.java:51)
at com.gs.lab.rr.db.plsql.gs_practice_pkg.PracticeStoredProceduresTest.testOneInNumberArrayOutStoredProcedure(PracticeStoredProceduresTest.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:329)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:218)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:151)
INTERNAL EXCEPTION STACK:
java.sql.SQLException: ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'ONE_IN_NUMBER_ARRAY_OUT'
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:573)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1093)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2047)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1940)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2709)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:589)
at oracle.toplink.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(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.DataReadQuery.executeNonCursor(Unknown Source)
at oracle.toplink.queryframework.DataReadQuery.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.threetier.ClientSession.internalExecuteQuery(Unknown Source)
at oracle.toplink.publicinterface.Session.executeQuery(Unknown Source)
at oracle.toplink.publicinterface.Session.executeQuery(Unknown Source)
at oracle.toplink.publicinterface.Session.executeSelectingCall(Unknown Source)
at com.gs.lab.rr.db.plsql.gs_practice_pkg.OneInNumberArrayOutStoredProcedure.execute(OneInNumberArrayOutStoredProcedure.java:51)
at com.gs.lab.rr.db.plsql.gs_practice_pkg.PracticeStoredProceduresTest.testOneInNumberArrayOutStoredProcedure(PracticeStoredProceduresTest.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:329)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:218)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:151)
Thanks in advance,
John
Using the SQL/ObjectRelational types as stored procedure arguments is not supported. But it may work...
You should not pass in the reference to the array type. Instead, do something like this:
call.addNamedOutputArgument("OUT_NUMBER_ARRAY", "OUT_NUMBER_ARRAY");
Hope this helps. If not, I suspect it would take some technical services to do this as I don't think the source.zip contains the classes involved in this.
- Don
Similar Messages
-
Passing array to stored proc as parameter
Hi,
I want to pass an array from my .Net application to oracle as a parameter to one of my stored proc. The signature of my SP looks like.
SP_Name(counter int, table_name varchar, log_values logs)
--(where logs is a varray of type varchar(100)
How can i pass an array of logs from .Net to this stored proc using ODP.Net?
Please help.You should have an example on your hard drive in
%OracleHome%\ODP.NET\samples\AssocArray
Cheers -
Stored Proc output being truncated with latest ojdbc14 and classes12.jar
Hello,
I downloaded the latest ojdbc14.jar from Oracle website and used it with my Java program. I noticed a peculiar behavior. If my stored proc is returning a VARCHAR with large number of characters, the output is being truncated. This worked fine with the older ojdbc14.jar (and the older classes12.jar). It does not work properly with the new ojdbc14 and classes12.jar. Is there something that I am missing here?
My Oracle Server version is - Oracle Database 10g Enterprise Edition Release 10.2.0.1.0.
Below is the sample stored proc and the Java file to execute the same.
Am I missing something here?
CREATE OR REPLACE PROCEDURE TestOracleDriver (returnVal OUT VARCHAR2) IS
BEGIN
returnVal := '';
FOR tmpVar in 1..2000
Loop
returnVal := returnVal || to_char(tmpVar) || ',';
END LOOP;
END;
import java.sql.*;
import java.util.*;
import java.util.Hashtable;
import oracle.jdbc.driver.OracleTypes;
public class OracleDriverTest
public static void main(String argv[]) throws Exception
Connection c = null;
try
Driver dr = new oracle.jdbc.OracleDriver();
Properties props = new Properties();
props.put("user", "scott");
props.put("password", "tiger");
c = dr.connect("jdbc:oracle:thin:@SERVER_NAME:PORT:SID", props);
System.out.println("GOT A PLAIN CON" );
System.out.println("The driver is " + c.getMetaData().getDriverVersion() );
System.out.println("The DBMS is " + c.getMetaData().getDatabaseProductVersion() );
execute(c);
catch (Exception e)
e.printStackTrace();
finally { try {c.close();} catch (Exception ign){} }
private static String execute(Connection connection )
String procName = "TestOracleDriver";
CallableStatement cstmt=null;
ResultSet rs = null;
String returnedData = null;
try
cstmt = connection.prepareCall("{call " + procName+" (?)}");
cstmt.registerOutParameter(1,OracleTypes.VARCHAR);
cstmt.execute();
returnedData = cstmt.getString(1);
System.out.println("ProcTest ::execute --> Returned data is \n"+ returnedData);
return returnedData;
catch (Exception e) {
System.out.println("ProcTest ::execute -->Error while executing "+procName);
e.printStackTrace();
return null;
finally
try
connection.close();
catch (Exception e1)
System.out.println("ProcTest ::execute -->Error while closing connection ");
e1.printStackTrace();
}//end of catch
}//end of finally
}//End of execute method
Regards,
Hari
Message was edited by:
user553601
Message was edited by:
user553601Hari,
If you think it is a bug, you can report it to Oracle Support via the MetaLink Web site.
Good Luck,
Avi. -
How to retrieve Stored Procedure Output Parameter?
Hi,
I'm using a stored procedure with MS SQL Server. The stored procedure creates the required table entries correctly. After executing the procedure i free the resulting recordset reference and am able to retrieve the return value of the stored procedure. However,
I am not able to retrieve the output parameters of the procedure. I am connected to the database using the MS OLE DB Provider for SQL Server. I tried using ODBC as well. Didn't work either. I know this issue has been addressed before, did anyone come up with a solution for this problem?
Thanks in advance,
MarcoI can tell you what I do with LabSQL and a single output parameter. After I open the connection to the database, I execute a SQL statement that looks like this:
declare @resultID int
execute spInsUUTResult @SerialNumber = '999DEBUGXXX',
@SequenceName = 'Sequence File2.seq',
@CategoryID = 2,
@TypeID = 1,
@StartDateTime = '10-10-2003 13:42:45',
@ExecutionTime = 3.5698713,
@UUTStatus = 'Passed',
@UserName = 'Dennis Knutson',
@StationName = 'DENNIS-KNUTSON',
@UUTResultID = @resultID OUTPUT
This query result is the output parameter. I first debugged the call to the stored procedure in the SQL Server Query Analyzer and then just copied that straight into my LabVIEW code. You may be using something other than LabSQL but you should have a function t
hat allows for raw SQL commands. -
Stored procedure output parameter cast problem - there was a mistake in the
Hi
I call to an oracle stored procedure from java and when i get the output parameter i get a classCastException.
The output parameter is for example of typeA
typeA is a sql object composed by a parameter of typeB and a parameter of typeC
typeC is a sql table of typeD objects
and typeD, typeB are objects composed by numbers, varchar2, date.....
I know that i have all the java to sql mappings correctly done because when my typeA is an input parameter of a procedure, it works correctly.
But when i have it as an output parameter i can�t solve the classCastException.
This is more or less my java code to call to the procedure:
dbConn=DriverManager.getConnection(dnsName,dnsUser,dnsPwd);
Map map = dbConn.getTypeMap();
map.put("TYPEA", Class.forName("tiposOracle.inv.Inv"));
map.put("TYPEB", Class.forName("tiposOracle.inv.Inv_cab"));
map.put("TYPED", Class.forName("tiposOracle.inv.Inv_lin"));
CallableStatement cstmt = dbConn.prepareCall("{call GENERAL.OBTENER_MENSAJE (?,?)}");
cstmt.setBigDecimal(1, codMensaje);
cstmt.registerOutParameter(2, OracleTypes.STRUCT, "TYPEA");
cstmt.execute();
Inv inv = (Inv)cstmt.getObject(2,map); ////////Here the exception-----------------------------------------------------------------------------------------------
The java class Inv represents the sql object typeA as this:
public Inv_cab cab;
public ARRAY lins;
And the classes Inv_cab and Inv_lin typeB and typeD with dates, BigDecimals and String.
lins is the table of Inv_lin.
And finally, this is the exception i get:
java.lang.ClassCastException
at tiposOracle.inv.Inv.readSQL(Invrpt.java:29)
at oracle.sql.STRUCT.toClass(STRUCT.java:829)
at oracle.sql.STRUCT.toJdbc(STRUCT.java:734)
at oracle.jdbc.driver.OracleStatement.getObjectValue(OracleStatement.java:6094)
at oracle.jdbc.driver.OracleCallableStatement.getObject(OracleCallableStatement.java:840)
at principal.PedirDatosMensaje.main(PedirDatosMensaje.java:103)
Can anyone help me?
ThanksNow i get this exception in cstmt.registerOutParameter(2, OracleTypes.STRUCT);java.sql.SQLException: Conflicto de tipo de par�metro: sqlType=2002
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.driver.OracleCallableStatement.registerOutParameterBytes(OracleCallableStatement.java:248)
at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:402)
at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:471)
at principal.PedirDatosMensaje.main(PedirDatosMensaje.java:78)
Conflicto de tipo de par�metro means: conflict of parameter type -
Stored procedure output parameter cast problem
Hi
I call to an oracle stored procedure from java and when i get the output parameter i get a classCastException.
The output parameter is for example of typeA
typeA is a sql object composed by a parameter of typeB and a parameter of typeC
typeB is a sql table of typeD objects
and typeD, typeB are objects composed by numbers, varchar2, date.....
I know that i have all the java to sql mappings correctly done because when my typeA is an input parameter of a procedure, it works correctly.
But when i have it as an output parameter i can�t solve the classCastException.
This is more or less my java code to call to the procedure:
dbConn=DriverManager.getConnection(dnsName,dnsUser,dnsPwd);
Map map = dbConn.getTypeMap();
map.put("TYPEA", Class.forName("tiposOracle.inv.Inv"));
map.put("TYPEB", Class.forName("tiposOracle.inv.Inv_cab"));
map.put("TYPED", Class.forName("tiposOracle.inv.Inv_lin"));
CallableStatement cstmt = dbConn.prepareCall("{call GENERAL.OBTENER_MENSAJE (?,?)}");
cstmt.setBigDecimal(1, codMensaje);
cstmt.registerOutParameter(2, OracleTypes.STRUCT, "TYPEA");
cstmt.execute();
Inv inv = (Inv)cstmt.getObject(2,map); ////////Here the exception-----------------------------------------------------------------------------------------------
The java class Inv represents the sql object typeA as this:
public Inv_cab cab;
public ARRAY lins;
And the classes Inv_cab and Inv_lin typeB and typeD with dates, BigDecimals and String.
lins is the table of Inv_lin.
And finally, this is the exception i get:
java.lang.ClassCastException
at tiposOracle.inv.Inv.readSQL(Invrpt.java:29)
at oracle.sql.STRUCT.toClass(STRUCT.java:829)
at oracle.sql.STRUCT.toJdbc(STRUCT.java:734)
at oracle.jdbc.driver.OracleStatement.getObjectValue(OracleStatement.java:6094)
at oracle.jdbc.driver.OracleCallableStatement.getObject(OracleCallableStatement.java:840)
at principal.PedirDatosMensaje.main(PedirDatosMensaje.java:103)
Can anyone help me?
ThanksNow i get this exception in cstmt.registerOutParameter(2, OracleTypes.STRUCT);java.sql.SQLException: Conflicto de tipo de par�metro: sqlType=2002
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.driver.OracleCallableStatement.registerOutParameterBytes(OracleCallableStatement.java:248)
at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:402)
at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:471)
at principal.PedirDatosMensaje.main(PedirDatosMensaje.java:78)
Conflicto de tipo de par�metro means: conflict of parameter type -
Using collection as a stored proc. parameter
I have a requirement of a using a stored proc ('in') parameter as a collection and using it futher in the where clause of a sql query. What are my options here ? I am currently trying with a nested table, getting errors in using with sql query.
What are my options here ?sql>create or replace type NumberTable as table of number;
2 /
Type created.
sql>create or replace procedure p_test
2 (p_list in NumberTable)
3 is
4 v_count pls_integer;
5 begin
6 select count(*)
7 into v_count
8 from table(p_list);
9 dbms_output.put_line( 'Count: ' || v_count );
10 end;
11 /
Procedure created.
sql>declare
2 v_list NumberTable := NumberTable(1, 2, 3, 4, 5);
3 begin
4 p_test(v_list);
5 end;
6 /
Count: 5
PL/SQL procedure successfully completed.There are some cases where you need to use CAST with the TABLE function:
table(cast(p_list as NumberTable)) -
URGENT: CLOB as output parameter for stored proc
HELP
I am unable to execute a stored procedure which has a CLOB defined as an output parameter from my Java code. It executes just fine from the SQL Plus promt.
When I try to run it through JDBC I get a PLS-00306 error.
I am using the Thin JDBC driver. When I try to compile using the OCI driver, I get class not found compile errors trying to import oracle.sql.*.
Thanks!
Donna J. PolkThe oracle.sql.* classes are part of the Oracle JDBC Driver.
Update your CLASSPATH variable to include $ORACLE_HOME/jdbc/lib/classes12_01.zip for JDK 1.2 or $ORACLE_HOME/jdbc/lib/classes111.zip for JDK 1.1.x -
Calling Stored Procedure with Boolean Output Parameter
Hi all,
I'm running into an issue (or is it a BUG) when calling a Database Stored Procedure that has an output parameter of the boolean type.
procedure proc(p_text in varchar2, p_result out boolean)
is
.....I use the following 'standard' code (developer guide 36-19 36-20) to invoke this procedure from my application module.
try {
// 1. Define the PL/SQL block for the statement to invoke
String stmt = "begin proc(?,?); end;";
// 2. Create the CallableStatement for the PL/SQL block
st = getDBTransaction().createCallableStatement(stmt, 0);
// 3. Register the positions and types of the OUT parameters
st.registerOutParameter(2, Types.BOOLEAN);
// 4. Set the bind values of the IN parameters
st.setObject(1, "Some text");
// 5. Execute the statement
st.executeUpdate();
..............................As soon as 'st.registerOutParameter(2, Types.BOOLEAN);' is invoked I run into a SQLexception. "Invalid ColumnType: 16". Obviously 16 refers to Types.BOOLEAN.
[edit by Luc]
SOLUTION / WORKAROUND
To answer my own question.
It looks like BOOLEAN output parameters are not supported. I just Read "Appendix D Troubleshooting" of the Oracle® Database JDBC Developer's Guide and Reference 10g Release 2 (10.2).
I found that JDBC drivers do not support the passing of BOOLEAN parameters to PL/SQL stored procedures. If a PL/SQL procedure contains BOOLEAN values, you can work around the restriction by wrapping the PL/SQL procedure with a second PL/SQL procedure that accepts the argument as an INT and passes it to the first stored procedure. When the second procedure is called, the server performs the conversion from INT to BOOLEAN.
I'm not very happy with this but I guess I've no choice.
Regards Luc
Edited by: lucbors on Nov 30, 2010 10:37 AMfyi
Related to the solution/workaround posted by Luc.
see "Do Oracle's JDBC drivers support PL/SQL tables/result sets/records/booleans? "
at http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-faq-090281.html#34_05
regards
Jan Vervecken -
Stored Proc with SSRS multi value parameter gives " Must Declare scalar Varaiable @StateID
Hi All,
I have one stored proc with @fromDate , @Todate and multivalue input
parameter@StateID of type integer.
When I run below stored proc via SSRS by selecting multiple values thru multiValue parameter into @StateID...it gives error saying "Must Declare scalar variable @StateID"
Not sure what is wrong with the input parameters.
ID is Integer type in all the 3 tables - dbo.EastCities, dbo.WestCities , dbo.Country
I need help fixing this "Must Declare scalar variable @StateID" error
This is the UDF split() I am using..
Function:
CREATE FUNCTION dbo.SplitStateID
( @List VARCHAR(MAX))
RETURNS TABLE
AS
RETURN
( SELECT DISTINCT [Value] = CONVERT(INT, LTRIM(RTRIM(CONVERT( VARCHAR(12),SUBSTRING(@List, Number, CHARINDEX(',', @List + ',', Number) - Number))))
FROM dbo.Numbers
WHERE Number <= CONVERT(INT, LEN(@List))AND SUBSTRING(',' + @List, Number, 1) = ',' );
GO
SELECT [Value] FROM dbo.SplitStateID('10,30,50');
Also, I have created dbo.Numbers table which is used in udf..
reference url -- >
http://sqlblog.com/blogs/aaron_bertrand/archive/2009/08/01/processing-a-list-of-integers-my-approach.aspx
SET NOCOUNT ON;
DECLARE @UpperLimit INT;
SET @UpperLimit = 10000;
WITH n AS(
SELECT rn = ROW_NUMBER() OVER (ORDER BY s1.[object_id])
FROM sys.objects AS s1
CROSS JOIN sys.objects AS s2
CROSS JOIN sys.objects AS s3)
SELECT [Number] = rn - 1
INTO dbo.Numbers FROM n
WHERE rn <= @UpperLimit + 1;
CREATE UNIQUE CLUSTERED INDEX n ON dbo.Numbers([Number]);
Stored procedure:
Create Procedure dbo.CountrySelection
( @FromDate Date, @ToDate Date, @StateID Int)
AS
BEGIN
set nocount on;
SELECT * INTO #EastCities
FROM (
SELECT ID,Description from dbo.EastCities
Where ID IN (SELECT Value from dbo.SplitStateID(@StateID))
) AS A
SELECT * INTO #WestCities
FROM (
SELECT ID,Description from dbo.WestCities
Where ID IN (SELECT Value from dbo.SplitStateID(@StateID))
) AS B
SELECT * INTO #Country
FROM (
SELECT ID , Description, State,Country From dbo.Country
) AS C
SELECT EC.ID AS East, WC.ID AS West , EC.Description AS EastDesc, WC.Description AS WestDesc, CT.State, CT.Country
FROM #Country CT
LEFT JOIN #EastCities EC ON CT.ID=EC.ID
LEFT JOIN #WestCities WC ON CT.ID=WC.ID
DROP TABLE #EastCities
DROP TABLE #WestCities
DROP TABLE #Country
END
Above 3 temp tables are joined by #Country.ID key
It works fine when single value is passed in @StateID
Exec dbo.CountrySelection '01/01/2010','02/01/2010',10
It fails when multi value passed into @StateID
Exec dbo.CountrySelection '01/01/2010','02/01/2010','10,30,40'
SSRS error log shows "Must declare scalar variable @StateID"
Need help in fixing this issue.
Thanks,
RH
sqlVisakh,
I changed @StateID date type to varchar(max) and still I get this error.
System.Data.SqlClient.SqlException: Must declare the scalar variable "@StateID".
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
I am running this SO in SSRS quert Type =Text
Actually sp created on db2 database and due to some limitations I am running(via SSRS) this from different db1 database data source within the same db server. When I run this sp from SSRS query designer(edit query designer button) and pass
multivalue parameters to @StateID as 10 , 20 it works and gives expected resultset.
Thanks,
RH
sql -
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} -
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 ? -
BizTalk Stored Proce-passing XML as one of the Input parameter and String as another parameter
I have a requirement in BizTalk that
- I will receive XML from Source and i need to submit this XML data and two other string parameters in SQL storeprocedure as a parameters and submit data
Ex: My_SP(myID Integer INPUT,myXML xml Input,mystring OUT)
Could you please help me how call storeprocedure and submit multiple parameters in BizTalk.you can execute stored procedure by generating schemas from WCF-SQL Adapter.
for passing parameters you will have to do the mapping to the Generated schema for Stored proc.
I would suggest to do this in Message Assignment shape, there you can easily assign all the parameters.
Integer and String parameters can be assigned from normal variables and XML parameter can be inserted as suggested by Abhishek-
xmldoc=requestMsg;
varOuterstring=xmldoc.Outerxml.Tostring();
Please refer the below article.
https://www.packtpub.com/books/content/new-soa-capabilities-biztalk-server-2009-wcf-sql-server-adapter
http://msdn.microsoft.com/en-us/library/dd787968.aspx
Thanks,
Prashant
Please mark this post accordingly if it answers your query or is helpful. -
Is it possible to pass TABLE as the output parameter in stored procedure
Hey Experts,
Is it possible to pass TABLE as the output parameter in stored procedure.
eg
create procedure spGetData
@tableName as TABLE(intValue INT NOT NUL)
asYou can use OPENQUERY or OPENROWSET, as mentioned above, to make stored procedure results table like. There are
some limitations with these methods:
http://technet.microsoft.com/en-us/library/ms188427.aspx
In OPENQUERY this-sql-server-instance can be used instead of a linked server name. It requires setting data accces server option:
exec sp_serveroption @server = 'PRODSVR\SQL2012'
,@optname = 'DATA ACCESS'
,@optvalue = 'TRUE'
LINK: http://www.sqlusa.com/bestpractices/select-into/
Kalman Toth Database & OLAP Architect
SELECT Video Tutorials 4 Hours
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012 -
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.
Maybe you are looking for
-
My Creative Cloud still thinks I'm on a trial and won't accept my serial number.
I have been set up with a seat on a Creative Cloud team and downloaded/started to use all apps. The second day in it's now saying that premiere has 29 days left of its trial period. I have clicked through to license the software and put in my seria
-
How to Restore System Preferences From Time Machine
Hi, Is there any way to restore past system preferences using Time Machine (such as desktop photo, trackpad settings, screensaver, etc.)? I would like to revert to some of these past settings without restoring my whole system from the backup disk & D
-
How to restore the original default ip5 ringtones lost due to upgrade to ios 7.0
Is there a solution to restore the original default iPhone 5 ringtones lost due to upgrade to IOS 7.0?
-
Wrong frieght value in Proforma Invoice
Hi, When Freight is calculated in the SO, the same is not copied into the Proforma Invoices (F8) but the correct value is copied to commerical invoice. this is happening for only particular item for rest of the items it is getting copied correctly. I
-
Use the CALL LIBRARY FUNCTION to access a function in a DLL Attachments: DLLQuestion.txt 1 KB