Stored procedure: nested cursor problem
Hey folks,
i am really having a hard time trying to figure out how nested cursors work.
What i want to do:
-> Do one select statement and process the yielded rows with one cursor
-> Do another select statement depending on the first cursor
The code is quite simple, the beginning of the stored procedure is:
create or replace
PROCEDURE extractEntireMD IS
CURSOR curTemplateUnitId IS
SELECT
tu.externalident,
tu.templateunitid
FROM
templateunit tu
WHERE
tu.templateunitid = 100007;
CURSOR curPartTypeId(templateUnitID IN varchar2) IS
SELECT
tpt.parttypeid
FROM
templateparttype tpt
WHERE
tpt.templateunitid = templateUnitID;
From what i have read, this seems to be right.
No i want to use this code like this:
BEGIN
FOR valInCurTemplateUnitId IN curTemplateUnitId LOOP
DBMS_OUTPUT.PUT_LINE('ExtIdent: ' || valInCurTemplateUnitId.externalident);
DBMS_OUTPUT.PUT_LINE('templateunitid: ' || valInCurTemplateUnitId.templateunitid);
FOR valIncurPartTypeId IN curPartTypeId(valInCurTemplateUnitId.templateunitid) LOOP
DBMS_OUTPUT.PUT_LINE('PartTypeId: ' || valIncurPartTypeId.parttypeid);
END LOOP;
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No such data ');
END;
The problem:
I seem to be doing something wrong, because Oracle does not heed the argument which i give to the second cursor from the first cursor:
CURSOR curPartTypeId(templateUnitID IN varchar2) IS
which i call via:
FOR valIncurPartTypeId IN curPartTypeId(valInCurTemplateUnitId.templateunitid)
Instead, oracle prints out __all__ templateunitids.
If I modify the second cursor with a constant argument like this:
CURSOR curPartTypeId(templateUnitID IN varchar2) IS
SELECT DISTINCT
tpt.parttypeid
FROM
templateparttype tpt
WHERE
tpt.templateunitid = 100007;
The result is correct. So it seems like oracle simply disregards the parameter i am giving him for the second cursor.
What am i doing wrong?
> i am really having a hard time trying to figure out how nested cursors work.
Good. I trust that this will result in the realisation that it is an idiotic thing to emulate the features of the SQL engine in PL/SQL. Only a fool thinks the he/she can outprogram and outsmart the SQL engine, and do things like nested loop joins better and faster in PL/SQL.
Use SQL for the purpose it was designed. Use PL/SQL for the purpose it was designed.
Joining of data? That is prime function and feature of SQL. Not PL/SQL.
Similar Messages
-
Is BC4J a viabl option for database with stored procedure (ref cursor) API?
I'm about to begin a Web application development project. As foundation, we have a (Oracle) database of certain complexity that have a data access API developed with PL/SQL packages.
This API is designed to get data through stored procedures/functions that return REF CURSOR.
Personally I have been investigating about Oracle ADF/JSF, and a number of others J2EE technologies, and at this moment I am doubting if ADF BC are a viable option to my development team.
I think this because I have noticed that one of the great drawback in ADF BC is the lack of simplicity to get data through stored procedures/functions that returns REF CURSORS.
I have been looking for documentation and the only thing that I have found are two examples:
1.- One that really do not work (fails in get data from ref cursor): ADF BC StoredProcedure Sample application.
2.- And other published by Steve Muench in
http://radio.weblogs.com/0118231/stories/2003/03/03/gettingAViewObjectsResultRowsFromARefCursor.html. This sample works fine.
But, the problem with the approach of this last article is the amount (and complexity) of the code necessary to make so basic and recurrent operation as is "obtain data through a stored procedure (ref cursor)".
Below it is the code that I have constructed to call a function that returns a ref cursor (based on steve's article).
If this is the only way to make this (historically so basic and simple) task, then it is obvious that BC is not a viable technology to my (or I am in a mistake?), since we have about 50 stored procedures/functions to access the underlying data; that stored procedures/functions are key to development of the new application (and, still more, currently are used to anothers apps ).
By all this, I would like consult to Oracle's people:
1.- I really must reject BC as technology to implement this project ?
2.- It is possible to access stored procedures in a simpler way using BC?
3.- If the answer to 2 is NOT: in near future, the BC team has plans to give more support to the simple access to stored procedures?
4.- If the answer to 3 is NOT: what another technology you recommend to construct my data access/business tier and still be able to using the others characteristics of ADF?
Thank you very much for your guidelines.
Regards, RL.
** And the code!!!
** ### I am forced to do this for each call to a procedure???? ###
package myrefcursor.model;
import java.math.BigDecimal;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Types;
import oracle.jbo.JboException;
import oracle.jbo.domain.NullValue;
import oracle.jbo.domain.Number;
import oracle.jbo.server.DBTransaction;
import oracle.jbo.server.ViewObjectImpl;
import oracle.jbo.server.ViewRowImpl;
import oracle.jbo.server.ViewRowSetImpl;
import oracle.jdbc.driver.OracleCallableStatement;
import oracle.jdbc.driver.OracleTypes;
public class TraePolizasViewImpl extends ViewObjectImpl {
private static final String SQL = "begin ? := PKG_PRUEBA.trae_polizas(?);end;";
private static final String COUNTSQL = "begin ? := PKG_PRUEBA.count_trae_polizas(?);end;";
public TraePolizasViewImpl() {
protected void executeQueryForCollection(Object qc,Object[] params,int numUserParams) {
BigDecimal rut_contratante = null;
Object[] theUserParam = null;
System.out.println(params);
System.out.println(params[0]);
if (params != null)
theUserParam = (Object[]) params[0];
//if (theUserParam != null && theUserParam.length > 0 )
if (! (theUserParam[1] instanceof NullValue) )
rut_contratante = (BigDecimal)theUserParam[1];
storeNewResultSet(qc ,retrieveRefCursor(qc, rut_contratante));
super.executeQueryForCollection(qc, params, numUserParams);
protected void create() {
getViewDef().setQuery(null);
getViewDef().setSelectClause(null);
setQuery(null);
protected ViewRowImpl createRowFromResultSet(Object qc, ResultSet rs) {
rs = getResultSet(qc);
ViewRowImpl r = createNewRowForCollection(qc);
try {
populateAttributeForRow(r,0, nullOrNewNumber(rs.getBigDecimal(1)));
populateAttributeForRow(r,1, rs.getString(2));
catch (SQLException s) {
throw new JboException(s);
return r;
protected boolean hasNextForCollection(Object qc) {
ResultSet rs = getResultSet(qc);
boolean nextOne = false;
try {
nextOne = rs.next();
if (!nextOne) {
setFetchCompleteForCollection(qc, true);
rs.close();
catch (SQLException s) {
throw new JboException(s);
return nextOne;
protected void releaseUserDataForCollection(Object qc, Object rs) {
ResultSet userDataRS = getResultSet(qc);
if (userDataRS != null) {
try { userDataRS.close(); }
catch (SQLException s) { ; }
super.releaseUserDataForCollection(qc, rs);
public long getQueryHitCount(ViewRowSetImpl viewRowSet) {
return viewRowSet.getRowCount();
private ResultSet retrieveRefCursor(Object qc, BigDecimal rut_contratante) {
CallableStatement st = null;
try {
st = getDBTransaction().createCallableStatement(SQL, DBTransaction.DEFAULT);
st.registerOutParameter(1,OracleTypes.CURSOR);
if (rut_contratante == null)
st.setNull(2, Types.NUMERIC);
else
st.setBigDecimal(2, rut_contratante);
st.execute();
ResultSet rs = ((OracleCallableStatement)st).getCursor(1);
rs.setFetchSize(getFetchSize());
return rs ;
catch (SQLException s) {
throw new JboException(s);
finally {try {st.close();} catch (SQLException s) {;}}
private void storeNewResultSet(Object qc, ResultSet rs) {
ResultSet existingRs = getResultSet(qc);
if (existingRs != null) {
try {existingRs.close();} catch (SQLException s) {;}
setUserDataForCollection(qc,rs);
hasNextForCollection(qc); // Prime the pump with the first row.
private ResultSet getResultSet(Object qc) {
return (ResultSet)getUserDataForCollection(qc);
private static Number nullOrNewNumber(BigDecimal b) {
try {
return b != null ? new Number(b) : null;
catch (SQLException s) { ; }
return null;
public BigDecimal getprutcontratante() {
return (BigDecimal)getNamedWhereClauseParam("prutcontratante");
public void setprutcontratante(BigDecimal value) {
setNamedWhereClauseParam("prutcontratante", value);
}no?
-
JCA Error while calling Stored Procedure containing cursors in BPEL/OSB
Hi,
I created JCA DBAdapter in Jdeveloper for calling remote stored procedure which contains cursors as OUT parameters.
I'm getting below exception when i try to call the database via BPEL/OSB.the same remote procedure call is working on Invoking with WLI .
Kindly sugggest !!!
The invocation resulted in an error: I*nvoke JCA outbound service failed with connection error, exception: com.bea.wli.sb.transports.jca.JCATransportException: oracle.tip.adapter.sa.api.JCABindingException: oracle.tip.adapter.sa.impl.fw.ext.org.collaxa.thirdparty.apache.wsif.WSIFException: servicebus:/WSDL/ServiceBus/BusinessServices/IsdnSiebelConn [ IsdnSiebelConn_ptt::IsdnSiebelConn(InputParameters,OutputParameters) ] - WSIF JCA Execute of operation 'IsdnSiebelConn' failed due to: Get object error.*
Error retrieving the value of a parameter R_NON_CNF_ATTR_CURSOR.
An error occurred when retrieving the value of parameter R_NON_CNF_ATTR_CURSOR after invoking the SIEBEL.ISDN_OBT_INS_DET.OBTAINASSETDETAILS API. Cause: java.sql.SQLException: Cursor is closed.
*; nested exception is:*
BINDING.JCA-11810
Get object error.
Error retrieving the value of a parameter R_NON_CNF_ATTR_CURSOR.
An error occurred when retrieving the value of parameter R_NON_CNF_ATTR_CURSOR after invoking the SIEBEL.ISDN_OBT_INS_DET.OBTAINASSETDETAILS API. Cause: java.sql.SQLException: Cursor is closed.
Check to ensure that the parameter has been correctly registered as a valid IN/OUT or OUT parameter of the API. This exception is considered retriable, likely due to a communication failure. To classify it as non-retriable instead add property nonRetriableErrorCodes with value "0" to your deployment descriptor (i.e. weblogic-ra.xml). To auto retry a retriable fault set these composite.xml properties for this invoke: jca.retry.interval, jca.retry.count, and jca.retry.backoff. All properties are integers.
com.bea.wli.sb.transports.jca.JCATransportException: oracle.tip.adapter.sa.api.JCABindingException: oracle.tip.adapter.sa.impl.fw.ext.org.collaxa.thirdparty.apache.wsif.WSIFException: servicebus:/WSDL/ServiceBus/BusinessServices/IsdnSiebelConn [ IsdnSiebelConn_ptt::IsdnSiebelConn(InputParameters,OutputParameters) ] - WSIF JCA Execute of operation 'IsdnSiebelConn' failed due to: Get object error.
Error retrieving the value of a parameter R_NON_CNF_ATTR_CURSOR.
An error occurred when retrieving the value of parameter R_NON_CNF_ATTR_CURSOR after invoking the SIEBEL.ISDN_OBT_INS_DET.OBTAINASSETDETAILS API. Cause: java.sql.SQLException: Cursor is closed.
; nested exception is:
BINDING.JCA-11810
Get object error.
Error retrieving the value of a parameter R_NON_CNF_ATTR_CURSOR.
An error occurred when retrieving the value of parameter R_NON_CNF_ATTR_CURSOR after invoking the SIEBEL.ISDN_OBT_INS_DET.OBTAINASSETDETAILS API. Cause: java.sql.SQLException: Cursor is closed.
Check to ensure that the parameter has been correctly registered as a valid IN/OUT or OUT parameter of the API. This exception is considered retriable, likely due to a communication failure. To classify it as non-retriable instead add property nonRetriableErrorCodes with value "0" to your deployment descriptor (i.e. weblogic-ra.xml). To auto retry a retriable fault set these composite.xml properties for this invoke: jca.retry.interval, jca.retry.count, and jca.retry.backoff. All properties are integers.
at com.bea.wli.sb.transports.jca.binding.JCATransportOutboundOperationBindingServiceImpl.invoke(JCATransportOutboundOperationBindingServiceImpl.java:153)
at com.bea.wli.sb.transports.jca.JCATransportEndpoint.sendRequestResponse(JCATransportEndpoint.java:209)
at com.bea.wli.sb.transports.jca.JCATransportEndpoint.send(JCATransportEndpoint.java:170)
at com.bea.wli.sb.transports.jca.JCATransportProvider.sendMessageAsync(JCATransportProvider.java:571)
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:597)
at com.bea.wli.sb.transports.Util$1.invoke(Util.java:83)
at $Proxy127.sendMessageAsync(Unknown Source)
at com.bea.wli.sb.transports.LoadBalanceFailoverListener.sendMessageAsync(LoadBalanceFailoverListener.java:148)
at com.bea.wli.sb.transports.LoadBalanceFailoverListener.sendMessageToServiceAsync(LoadBalanceFailoverListener.java:603)
at com.bea.wli.sb.transports.LoadBalanceFailoverListener.sendMessageToService(LoadBalanceFailoverListener.java:538)
at com.bea.wli.sb.transports.TransportManagerImpl.sendMessageToService(TransportManagerImpl.java:558)
at com.bea.wli.sb.transports.TransportManagerImpl.sendMessageAsync(TransportManagerImpl.java:426)
at com.bea.wli.sb.test.service.ServiceMessageSender.send0(ServiceMessageSender.java:377)
at com.bea.wli.sb.test.service.ServiceMessageSender.access$000(ServiceMessageSender.java:76)
at com.bea.wli.sb.test.service.ServiceMessageSender$1.run(ServiceMessageSender.java:134)
at com.bea.wli.sb.test.service.ServiceMessageSender$1.run(ServiceMessageSender.java:132)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:147)
at com.bea.wli.sb.security.WLSSecurityContextService.runAs(WLSSecurityContextService.java:55)
at com.bea.wli.sb.test.service.ServiceMessageSender.send(ServiceMessageSender.java:137)
at com.bea.wli.sb.test.service.ServiceProcessor.invoke(ServiceProcessor.java:454)
at com.bea.wli.sb.test.TestServiceImpl.invoke(TestServiceImpl.java:172)
at com.bea.wli.sb.test.client.ejb.TestServiceEJBBean.invoke(TestServiceEJBBean.java:167)
at com.bea.wli.sb.test.client.ejb.TestService_sqr59p_EOImpl.invoke(TestService_sqr59p_EOImpl.java:353)
at com.bea.wli.sb.test.client.ejb.TestService_sqr59p_EOImpl_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.ServerRequest.sendReceive(ServerRequest.java:174)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:345)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:259)
at com.bea.wli.sb.test.client.ejb.TestService_sqr59p_EOImpl_1033_WLStub.invoke(Unknown Source)
at com.bea.alsb.console.test.TestServiceClient.invoke(TestServiceClient.java:174)
at com.bea.alsb.console.test.actions.DefaultRequestAction.invoke(DefaultRequestAction.java:117)
at com.bea.alsb.console.test.actions.DefaultRequestAction.execute(DefaultRequestAction.java:70)
at com.bea.alsb.console.test.actions.ServiceRequestAction.execute(ServiceRequestAction.java:143)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.beehive.netui.pageflow.PageFlowRequestProcessor.access$201(PageFlowRequestProcessor.java:97)
at org.apache.beehive.netui.pageflow.PageFlowRequestProcessor$ActionRunner.execute(PageFlowRequestProcessor.java:2044)
at org.apache.beehive.netui.pageflow.interceptor.action.internal.ActionInterceptors.wrapAction(ActionInterceptors.java:91)
at org.apache.beehive.netui.pageflow.PageFlowRequestProcessor.processActionPerform(PageFlowRequestProcessor.java:2116)
at com.bea.alsb.console.common.base.SBConsoleRequestProcessor.processActionPerform(SBConsoleRequestProcessor.java:91)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.beehive.netui.pageflow.PageFlowRequestProcessor.processInternal(PageFlowRequestProcessor.java:556)
at org.apache.beehive.netui.pageflow.PageFlowRequestProcessor.process(PageFlowRequestProcessor.java:853)
at com.bea.alsb.console.common.base.SBConsoleRequestProcessor.process(SBConsoleRequestProcessor.java:191)
at org.apache.beehive.netui.pageflow.AutoRegisterActionServlet.process(AutoRegisterActionServlet.java:631)
at org.apache.beehive.netui.pageflow.PageFlowActionServlet.process(PageFlowActionServlet.java:158)
at com.bea.console.internal.ConsoleActionServlet.process(ConsoleActionServlet.java:256)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at com.bea.console.internal.ConsoleActionServlet.doGet(ConsoleActionServlet.java:133)
at com.bea.alsb.console.common.base.SBConsoleActionServlet.doGet(SBConsoleActionServlet.java:49)
at org.apache.beehive.netui.pageflow.PageFlowUtils.strutsLookup(PageFlowUtils.java:1199)
at org.apache.beehive.netui.pageflow.PageFlowUtils.strutsLookup(PageFlowUtils.java:1129)
at com.bea.portlet.adapter.scopedcontent.ScopedContentCommonSupport.executeAction(ScopedContentCommonSupport.java:687)
at com.bea.portlet.adapter.scopedcontent.ScopedContentCommonSupport.processActionInternal(ScopedContentCommonSupport.java:142)
at com.bea.portlet.adapter.scopedcontent.StrutsStubImpl.processAction(StrutsStubImpl.java:76)
at com.bea.portlet.adapter.NetuiActionHandler.raiseScopedAction(NetuiActionHandler.java:111)
at com.bea.netuix.servlets.controls.content.NetuiContent.raiseScopedAction(NetuiContent.java:181)
at com.bea.netuix.servlets.controls.content.NetuiContent.raiseScopedAction(NetuiContent.java:167)
at com.bea.netuix.servlets.controls.content.NetuiContent.handlePostbackData(NetuiContent.java:225)
at com.bea.netuix.nf.ControlLifecycle$2.visit(ControlLifecycle.java:180)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:324)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walk(ControlTreeWalker.java:130)
at com.bea.netuix.nf.Lifecycle.processLifecycles(Lifecycle.java:395)
at com.bea.netuix.nf.Lifecycle.processLifecycles(Lifecycle.java:361)
at com.bea.netuix.nf.Lifecycle.processLifecycles(Lifecycle.java:352)
at com.bea.netuix.nf.Lifecycle.runInbound(Lifecycle.java:184)
at com.bea.netuix.nf.Lifecycle.run(Lifecycle.java:159)
at com.bea.netuix.servlets.manager.UIServlet.runLifecycle(UIServlet.java:388)
at com.bea.netuix.servlets.manager.UIServlet.doPost(UIServlet.java:258)
at com.bea.netuix.servlets.manager.UIServlet.service(UIServlet.java:199)
at com.bea.netuix.servlets.manager.SingleFileServlet.service(SingleFileServlet.java:251)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.AsyncInitServlet.service(AsyncInitServlet.java:130)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.dms.wls.DMSServletFilter.doFilter(DMSServletFilter.java:330)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.doIt(WebAppServletContext.java:3684)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3650)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2268)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2174)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1446)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)You need to open all the cursors in the PLSQL ie., cursors should be initialized in your PLSQL package. JCA DB Adapter tries to open the cursor without checking whether its there or not..If you cant change the PLSQL package, raise a SR with Oracle for a patch.This would be considered as Enhancement Request.
Regards
Sesha -
Stored procedure with cursor as output param
It's the first time for me to test a stored procedure with a cursor as output parameter. I executed the following:
SQL> VARIABLE user_cur REFCURSOR; VARIABLE ret_code VARCHAR2; exec TEST_API.SEARCH_USER( :ret_code, '', '', 'john', '', :user_cur); print ret_code;print user_cur;
I got the following error:
Usage: VAR[IABLE] [ <variable> [ NUMBER | CHAR | CHAR (n [CHAR|BYTE]) |
VARCHAR2 (n CHAR) | NCHAR | NCHAR (n) |
NVARCHAR2 (n) | CLOB | NCLOB | REFCURSOR ] ]
May I know what's the problem?
The purpose of the stored procedure is to search for user with the name "john".
The stored procudure input/output params declaration is as follows:
PROCEDURE SEARCH_USER
RETURN_CODE OUT VARCHAR2,
USER_ID_IN IN VARCHAR2,
POSITION_IN IN VARCHAR2,
USERNAME_IN IN VARCHAR2,
STATUS_IN IN VARCHAR2,
USER_CUR_OUT OUT REFCURSOR
Edited by: user7383310 on Oct 19, 2008 9:05 PM
Edited by: user7383310 on Oct 19, 2008 9:05 PMfor the usage of refcursors in pl/sql refer here..
http://download.oracle.com/docs/cd/B14117_01/appdev.101/b10807/06_ora.htm#sthref808
You can code like..
SQL> create or replace procedure p1(id number,csr out sys_refcursor) is
2 begin
3 open csr for select ename from emp where deptno = id;
4 end;
5 /
Procedure created.
SQL> var csr1 refcursor
SQL> var n number
SQL> exec :n := 30;
PL/SQL procedure successfully completed.
SQL> exec p1(:n,:csr1);
PL/SQL procedure successfully completed.
SQL> print csr1
ENAME
ALLEN
WARD
MARTIN
BLAKE
TURNER
JAMES
6 rows selected. -
Forms Data-Block based on stored procedures - REF CURSOR feature NOT FUNCTIONING
This topic is related to another topic in this forum titled "FORMS HOW TO SET QUERY SOURCE ARGUMENTS??" I posted my message there as well. I am posting as a NEW TOPIC so that it catches the attention of Oracle Support.
I built a data form based on a stored procedure and REF CURSOR IN OUT parameter.
My procedure takes a IN parameter to fill in the criteria for the OPEN <cursor_variable> select ... where ... statement.
In the Value setting of the Query source Arguments , I set the VALUE to ":BLOCK_NAME.ITEM_NAME" at design time to supply the input value to the procedure. this works to the extent of making available the form item value to the stored procedure parameter. I verified this by doing an insert into some debug table , of the incoming parameter value inside my stored procedure.
The cursor gets opened properly into the REF cursor variable. I verified this by fetching a record into a local variable and inserting the value into a debug table again in the stored procedure.
(I took care to close and re-open the REF cursor variable again - so that the front-end can continue to fetch it from the first record. )
***** PROBLEM **************
But the front end forms runtime is giving me a FRM-40301 - query returned no records even though the REF cursor is returned properly opened.
Did anybody else face the same problem ??
Please post what you found.
Thanks,
Shankaran
nullThis topic is discussed at length in another thread "How Set Value For Query DataSource Arguments?"
But I am posting the findings here as well.
THIS TOPIC IS CLOSED.
My Bad. The problem Cause : I did not include all columns in the
cursor rowtype in the Data-block. In the wizard for the data block , I selected ONLY the columns that I needed. But I was doing a Select * from <my_table> in my open cursor <Cursor-Variable> .... The <Cursor Variable>
itself was declared <my_table>%rowtype
FIX : The Data Block structure (columns included as items) should match the cursor record Structure. One may or may not
display all the columns in the LAYOUT though.
But I don't understand why it gives such a misleading message like FRM-40301 Query retrieved no records. Oracle Team fix it.
Hope this helps people who face the same problem.
Thanks, -
Stored procedure - ref cursor - no rows
Hello,
I am stumped. Hopefully another pair of eyes will see what mine cannot. I am calling a stored procedure that accepts a single output parameter [the proc has been dumbed down to limit variables of my problem] that is a ref cursor. When I make the call I get now data. I have used both adapter and datareaders. If I call the proc from another proc I can loop through the results. I am including the code of my c# function and the stored proc.
The version number of my Oracle.DataAccess.dll is 10.1.0.303.
** Stored Proc ***********************
TYPE refcursor is ref cursor ;
procedure P_CUSTOMER_INFO_GET_SLIM( thecur out refcursor )
is
begin
open thecur for
select *
from customer_info
where rownum < 21;
end P_CUSTOMER_INFO_GET_SLIM;
** C# Func ***************************
private DataSet _FetchCustomerData2(string CustNbr, string ShipToSuffix)
string sc = "PKG_CUSTOMER_CONTACT.P_CUSTOMER_INFO_GET_SLIM";
OracleConnection con = new OracleConnection(_Database.GetConnection().ConnectionString);
OracleCommand cmd = new OracleCommand(sc, con);
OracleDataAdapter da = new OracleDataAdapter(cmd);
DataSet ds = new DataSet();
// must pass strings with data
if (CustNbr.Length==0 || ShipToSuffix.Length==0)
return null;
try
// we are calling a stored proc so set it
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("thecur", OracleDbType.RefCursor, DBNull.Value, ParameterDirection.Output);
da.Fill(ds, "Customer"); // no data ?????????????????
// Close and Dispose OracleConnection object
con.Close();
con.Dispose();
return ds;Hey all,
I ended up declaring a variable in the proc as refcursor and opening it. Then I assigned the out parameter ref cursor to the variable. That took care of it. See below.
Thanks,
Mike
procedure P_CUSTOMER_INFO_GET(
CustomerNumber in varchar2
,ShipToSuffix in varchar2
,thecur out refcursor
is
-- variable declarations
mycur refcursor;
begin
open mycur for
select CORP_CODE
,CUST_NUMBER
,CUST_SHIP_TO_SFFX
,CUST_BILL_TO_SUFF
,CUST_AR_OFF_CODE
,CUST_NAME
,CUST_SHIP_BILL_IND
,CUST_SHIP_VIA_CODE
,CUST_CLASS_CODE
,CUST_TYPE_CODE
,CUST_PRICE_CODE
,DISC_MKUP_CODE
,TRADE_DISC_CODE
,CUST_N_D_ACCT_NO
,CUST_PRY_PRICE_AGR
,CUST_ADDR_1
,CUST_ADDR_2
,CUST_ADDR_3
,CUST_CITY
,CUST_STATE
,CUST_ZIP
,CUST_COUNTRY_CODE
,CUST_FAX_NO
,CUST_FAX_NO_EXP
,CUST_PHONE_NO
,CUST_PHONE_NO_EXP
,CUST_CRDT_LIM_CODE
,CUST_CREDIT_STATUS
,CUST_CRED_CARD_NO
,CUST_CC_EXP_DATE
,CUST_DUNNING_FLAG
,CUST_ID
,CUST_SP_FILE_IND
,CUST_ST_TAX_CODE
,LAST_MAINT_DATE
from customer_info
where CUST_NUMBER = CustomerNumber
and CUST_SHIP_TO_SFFX = ShipToSuffix;
-- send the cursor back
thecur := mycur; -
STORED PROCEDURE/REF CURSOR: How to output entire buffer
I wrote a Stored Procedure wherein I use a Cursor to extract multiple
rows and columns. I then write them into the buffer
(dmbs_output.put_line). But when I try to capture the entire result
into an OUT variable, I only get the last buffered line.
So how do I output the entire buffer- all rows and columns? In other words (maybe), how do I use dbms_output.get_lines() to assign value to an OUT variable?
Alternatively, using REF CURSOR as OUT variable, I added the following to "CREATE OR REPLACE PROCEDURE ... ()":
cursor_out_test OUT cursor_test
But when I tried:
DEFINE CURSOR TYPE cursor_test IS REF CURSOR RETURN table%ROWTYPE;
...or...
DECLARE TYPE cursor_test IS REF CURSOR RETURN table%ROWTYPE;
I still got syntax errors.
In one line, what I am trying to do is break the result array at the database level rather than at the application level.
Cheers, Bill
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/sqloperations.htm#LNPLS00605I did the following:
OPEN CURSOR x
LOOP
FETCH CURSOR x INTO col1, col2
(EXIT WHEN...)
variable_line := col1 || col2
END LOOP
CLOSE CURSOR
But after closing this cursor, variable_line contains only the last buffered line. I want all the looped lines (without using associative arrays, nested tables etc). So I guess I am just looking for some way to append data lines- adding chr(10) doesn't work either.
Cheers, Bill -
How to use a parameter passed to stored procedure in cursor?
I am rather new to Oracle stored procedures and I'm sure that
this is rather simple. Could someone tell me how to do the
following: I would like to pass the variable status into my
stored procedure and then use it in the where clause when
defining my cursor. I have the stored procedure working 100%
other than this small detail.
CREATE OR REPLACE PROCEDURE p_report_starwood_exhibita2(hno
VARCHAR2, cid INTEGER, kperiod INTEGER, status VARCHAR2, user
VARCHAR2) IS
BEGIN
DECLARE
CURSOR bid_cursor IS
SELECT bm.hotelid
FROM dbo.bidmaster bm
WHERE bm.channelid = cid
and bm.contractperiod = kperiod
and bm.bidstatus like '&status'
END;
Thank youI am rather new to Oracle stored procedures and I'm sure that
this is rather simple. Could someone tell me how to do the
following: I would like to pass the variable status into my
stored procedure and then use it in the where clause when
defining my cursor. I have the stored procedure working 100%
other than this small detail.
CREATE OR REPLACE PROCEDURE p_report_starwood_exhibita2(hno
VARCHAR2, cid INTEGER, kperiod INTEGER, status VARCHAR2, user
VARCHAR2) IS
BEGIN
DECLARE
CURSOR bid_cursor IS
SELECT bm.hotelid
FROM dbo.bidmaster bm
WHERE bm.channelid = cid
and bm.contractperiod = kperiod
and bm.bidstatus like '&status'
END;
Thank you You can do something like this
CREATE OR REPLACE PROCEDURE p_report_starwood_exhibita2(hno
VARCHAR2, cid INTEGER, kperiod INTEGER, status VARCHAR2, user
VARCHAR2) IS
BEGIN
DECLARE
CURSOR bid_cursor (p_status varchar2) IS
SELECT bm.hotelid
FROM dbo.bidmaster bm
WHERE bm.channelid = cid
and bm.contractperiod = kperiod
and bm.bidstatus like p_status
END;
and then in the BEGIN section do
open bid_cursor(status)
This should work.
Regards
Manoj -
Error when stored procedure returns cursor in pro c
Hi
I was trying to make work the stuff explained at
[m-2537153]
It executes a stored procedure from pro c that returns a cursor.
But when i compllie at pro c I get following error. My procedure name is TEST.
If i change the output parameter to a int value. It compiles ok.
PLS-S-00306, wrong number or types of arguments in call to 'TEST'
Error at line 34, column 5 in file E:\C\Test\tt.pc
TEST(:test_cursor);
+....1+
PLS-S-00000, Statement ignored
Semantic error at line 33, column 1, file E:\C\Test\tt.pc:
BEGIN
+1+
PCC-S-02346, PL/SQL found semantic errors
Can any one point out what could be the error?
I am working from oracle 8i client. which connects to oracle 9.0.1.
OS is win 2000 sp4This is my code
int main(int argc, char** argv)
+{+
EXEC SQL BEGIN DECLARE SECTION;
char user[]="scott";
char pwd[]="tiger";
char server[]="testdb";
char msg_buf[51|http://forums.oracle.com/forums/]+="";+
int intarg1;
int intId;
char strName[]="";
SQL_CURSOR tcr;
EXEC SQL END DECLARE SECTION;
+/* Register sql_error() as the error handler. */+
EXEC SQL WHENEVER SQLERROR DO sql_error("ORACLE error\n");
EXEC SQL CONNECT :user IDENTIFIED BY :pwd USING :server;
Printf("Connected to %s successfully",server);
EXEC SQL ALLOCATE :tcr;
EXEC SQL EXECUTE
BEGIN
TEST(:tcr);
END;
END-EXEC;
Procedure name is TEST and it like
CREATE OR REPLACE PROCEDURE TEST (crsdata out sys_refcursor)
as
BEGIN
open crsdata for select id,name from newtab;
END; -
RDBMS adapter, stored procedure and refcursor problem
Hi !
I am trying to use the RDBMS adapter for 8.1 SP2 to retreive data from a stored
procedure having an out parameter of the refcursor type. This service is impossible
to define in WLAI, any suggestions, sample code would be greately appreciated.
Regards,
Anders Mathisen
Unless you are running a really old version of Oracle, any weak ref cursor can just be declared SYS_REFCURSOR. Also, you can't use a weak ref cursor for %ROWTYPE. You can test the procedure in SQL*Plus by using it to populate a refcursor variable.
-
Oracle OLE DB Provider / Stored Procedure REF CURSOR errror
Post Author: robfurrball
CA Forum: Data Connectivity and SQL
All,I'm out of ideas on this and would appreciate any suggestions.I'm trying to use Crystal XI to connect to an Oracle 9i database using the Oracle OLE DB Provider (required to use this provider by a 3rd party program that fires off the report).If I connect using the Microsoft OLE DB Provider for Oracle, the report will return data. When connecting with the Oracle OLE DB Provider, I get the following:Database Connector Error: 'ADO Error Code: 0x80040e14
Source: OraOLEDB
Description: ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'SP_MOMGLOBCSHBAL_TEST'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
Native Error: 6550 [Database Vendor Code: 6550 ]' -
The procedure's only parameter is an IN OUT SYS_REFCURSOR, and the Oracle OLE DB Provider is version 9.2.0.7.0 Thanks,RobPost Author: robfurrball
CA Forum: Data Connectivity and SQL
Summary: After going
back and forth with Business Objects support they ruled that it was an issue
with the provider itself, recommended I contact Oracle for resolution, and
closed the case before I could comment back to them. I was unable to send this response to their
support team, so I'm posting it here in hopes that I can save others time/money
in the future.
My Response -
I appreciate your input and would have liked to comment further on the case management system before you closed the case. I'm a little surprised and disappointed that you recommend I contact Oracle directly about this issue.I would imagine that a company as large as Business Objects would have much better results dealing with Oracle to resolve an issue compared to an individual.Also, since you are able to connect to other objects (such as a table) in Crystal Reports using that provider, I would expect that you would want customers to be able to connect to stored procedures using it as well. Otherwise, it would seem appropriate to either alert customers of this defect through documentation, public message boards, and forums.Using Crystal to pull data from stored procedures in other databases and data providers made me think that was a viable option for this project. Since it was not documented as a limitation of Crystal and the provider, it has cost my organization a great deal of time and money trying to troubleshoot an issue I would have expected to be caught in Crystal Reports' internal quality assurance testing.------ This is the final note I received on my support case: -
Please note that the statement used to execute a procedure within ODBC/OLE DB is different from the native 'Oracle Server' statement.In ODBC or OLE DB, the call is '{CALL "SCHEMANAME"."TEST_PROCEDURE"(3)}' , when using native 'Oracle Server' the call is 'BEGIN "SCHEMANAME"."TEST_PROCEDURE"(:TEST_CURSOR, 1); END ;'In ODBC or OLE DB, the cursor is still used however it is not listed within the SQL Statement as in the Native connection. This is the behavior from Crystal Reports 9 forward that the cursor is not shown through ODBC/OLE DB.In addition to that as the issue is only with the Oracle OLE DB provider and I would suggest you to contact Oracle about this issue, since the issue occurs outside of Crystal Reports when using QTADO with a standard call, so it is not an issue between Crystal Reports and Oracle.The issue is only with Oracle OLE DB provider as the same Oracle stored procedure call works within QTADO with the MS Oracle OLE DB provider.As the issue is with the OLE DB Provider and not with Crystal Reports, we may not be able to proceed further. Hence, I am closing this case from Case Management System. -
Stored procedure with cursor as out parameter
Can any one help me by showing how to write a procedure with cursor as out parameter and caputuring it in java using jdbc.
Thanks in advance,
shravan bharadwajI know that in the SQLJ distribution (which is also downloadable) there is an example in the demo directory called RefCursDemo that shows the SQL code and how to call it - albeit from SQLJ and not JDBC. There may also be a demo in the JDBC distribution, though I am not sure about that.
-
Adding Records Using Stored Procedure (or Cursor?)
Also, I would like to have a second example of a stored procedure that will add random rows to a table (that is, create duplicates of information already in the table).
For example,
IF p_value1 = 'FIRST_VALUE' then
add this record (incl. seq_no for key);
ELSIF p_value2 = 'SECOND_VALUE' then
add that record (incl. seq_no for key);
and on and on.
This procedure should also be able to handle random insertion up to several thousand rows. So, I know that I need to loop, say:
while v_ctr < 1000
or
for 1...999
Much thanks to anyone who can help.
Many thanks to anyone who can help.<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Colin Berrouard ([email protected]):
You should look in a PL/SQl book,
There are a lot of examples that can help you
<HR></BLOCKQUOTE>
I have already, but when trying to self-learn without not any familiarity with certain concepts and being at most a visual learner, I'm not getting this concept at this point...hence the reason why I asked.
Thanks. -
Execute stored procedure before editing = Problem using DataTemplate
Héllo,
I'm working on a Publisher Report, in which I need to perform a pre treatment before editing the report.
The report is based on a data model "SQL Query", like this :
"select my_package.myfunction(:par01, :par02)
from system.dual;"
The function returns a cursor, with all the data I need to build the report. The first thing I tried is to add to this function the pre-treatment, which insert in several tables rows used by the function.
But I've got the error "ORA-14551: cannot perform a DML operation inside a query".
Is there a different way to do what I want ?
Thanks for your answers.
Edited by: jbg on 15 déc. 2010 07:10By searching on blogs, I found the data template solution. I created the following template :
<dataTemplate name="dtWeekly" dataSourceRef="ORCL2" defaultpackage="pk_btx_spe_weekly">
<dataQuery>
<sqlStatement name="Q1">
select libelle libelle from super.tmp_trace_pub
</sqlStatement>
</dataQuery>
<dataTrigger name="beforeReport" source="pk_btx_spe_weekly.pre_traitement()"/>
<dataStructure>
<group name="G_TEST" source="Q1">
<element name="libelle" value="libelle"/>
</group>
</dataStructure>
</dataTemplate>
the function pre_traitement() simply inserts a row in the "tmp_trace_pub" (I tested it directly in SQL*Plus, without any problem. I've got no errors, but the trigger doesn't seem to execute, and the XML generated is empty :
<?xml version="1.0" encoding="UTF-8" ?>
- <DTWEEKLY>
<LIST_G_TEST />
</DTWEEKLY>
Did I do something wrong ?
Thanks, -
Datamanagement and stored procedures give identity problems
Hi,
I'm getting the following error when I create an item with the data services.
The server returned an item without an identity. Either the server did not set the id properties, the id properties are misconfigured or id properties toString method returned nothing. id properties: '["sopId"]', returned item: 'uzbrussel.service.model::StandardOperatingProcedureImpl {
This results in my committed object still having the initial 0 for its id.
Configuration settings are:
<metadata>
<identity property="sopId" undefined-value="0"/>
</metadata>
<create-item>
<procedure name="medocp_SOP_Insert">
<procedure-param property-value="#sopId#" type="OUT"/>
<procedure-param property-value="#serviceId#"/>
<procedure-param property-value="#name#"/>
<procedure-param property-value="#code#"/>
<procedure-param property-value="#workAreaId#"/>
<procedure-param property-value="#categoryId#"/>
<procedure-param property-value="#motherProcedureId#"/>
<procedure-param property-value="#typeId#"/>
<procedure-param property-value="#subTypeId#"/>
<procedure-param property-value="#responsableId#"/>
<procedure-param property-value="#revisionTime#"/>
<procedure-param property-value="#electronic#"/>
<procedure-param property-value="#modifierId#"/>
</procedure>
</create-item>
The documentation says:
As an alternative, you can setup a procedure call in the database that does the insert and id select. For the create-item element only, you can designate the procedure-param as an OUT parameter, which means that the value is returned to the client in the ActionScript instance's property-value field.
But the UpdateCollectionMessage does have the right id:
[1] (mx.data.messages::UpdateCollectionMessage)#21
body = (Array)#22
[0] (mx.data::UpdateCollectionRange)#23
identities = (Array)#24
[0] (Object)#25
sopId = 1000016
position = 10
size = 1
updateType = 0That should work fine and each call will get a separate ref cursor as long as the app is written properly and is managing it's threads anbd handles properly. Are you seeing some behaviour that suggests this is not the case?
Chris
Maybe you are looking for
-
I was given an ipod and it has been disabled and I have tried to hook it up to itunes and it won't sync
-
CS4 not working correctly on 10.8
I can't open canon CR2 files in CS4 since my upgrade to 10.8 Bridge or Acrobat wont open at all. Here is a link from Adobe about compatibilty. Does not look good. http://www.adobe.com/products/creativesuite/faq.html#lion-os
-
Safari just hangs up and has to be restarted. My Macbook Pro has been doing great. Just iMac.
-
Group contacts cannot send mail
I created a group, and tried to send them an email, but got error message "invalid address." Also would like names not to show when I send. How to send?
-
Hi, so I have been able to upload to youtube successfully for the past six months but recently when I try to upload through FCPX it gets to 99% and then says that there has been an error and my video didn't upload. My google two step verification is