Test Result set procedure with cursor
i am really new for oracle and i don't know how to test my result set procedure in oracle.
i am now working on Oracle 10g Express Edition.
my procedure is below.
create or replace procedure "GETORDERSBYCATALOGUECODE"
(p_cataloguecode IN VARCHAR2, p_cursor IN OUT SYS_REFCURSOR )
is
begin
open p_cursor for SELECT OrderID, NumberOrdered, CostCharged
FROM OrderDetails
WHERE CatalogueCode=p_cataloguecode;
end;
i am not sure how can i work with the the cursor and the procedure to display cursor data in Oracle 10g Express Web Admin?
Tunk
Hi, test the following statement in command line:
SQL>VAR ordercursor REFCURSOR;
SQL>EXECUTE GETORDERsBYCATALOGUECODE('001',:ordercursor);
SQL>print :ordercursor;
I+n your code, the error is OPEN ORDERCURSOR, the ORDERCURSOR cursor is open by default.+
Your correct code is:
declare
ordercursor SYS_REFCURSOR;
orderid NUMBER;
numberordered NUMBER;
costcharged BINARY_DOUBLE;
begin
GETORDERsBYCATALOGUECODE('001',ordercursor);
DBMS_OUTPUT.ENABLE(20000);
DBMS_OUTPUT.PUT_LINE('Order Number, Number Ordered, Cost Charged');
LOOP
FETCH ordercursor INTO orderid, numberordered, costcharged;
exit when ordercursor%notfound;
DBMS_OUTPUT.PUT_LINE(orderid || ', ' || numberordered || ', ' || costcharged);
END LOOP;
CLOSE ordercursor;
end;
Roberto.
Edited by: user584812 on Dec 23, 2008 3:47 PM
Similar Messages
-
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. -
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.
-
Consider the Following Code with j2sdk1.4.0_01/jakarta-tomcat-4.0.1
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("Jdbc:Odbc:IMSMC","sa","");
String sql="select * from <Table Name> ";
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
*************Some Code ******************
catch (Exception ex) {
ex.printStackTrace();
}//End of catch
}//End of Try
The Tomcat automatically shuts down If I'm using Scrollable
Result Set and the following Error Occurs.
Error
Unexpected Signal : EXCEPTION_ACCESS_VIOLATION occurred at PC=0x6D366658
Function=[Unknown.]
Library=c:\j2sdk1.4.0_01\jre\bin\client\jvm.dll
NOTE: We are unable to locate the function name symbol for the error
just occurred. Please refer to release documentation for possible
reason and solutions.
Current Java thread:
at sun.jdbc.odbc.JdbcOdbc.setStmtAttrPtr(Native Method)
at sun.jdbc.odbc.JdbcOdbc.SQLSetStmtAttrPtr(JdbcOdbc.java:4676)
at sun.jdbc.odbc.JdbcOdbcResultSet.setRowStatusPtr(JdbcOdbcResultSet.java:4473)
at sun.jdbc.odbc.JdbcOdbcResultSet.initialize(JdbcOdbcResultSet.java:171)
at sun.jdbc.odbc.JdbcOdbcStatement.getResultSet(JdbcOdbcStatement.java:423)
- locked <02A1FE80> (a sun.jdbc.odbc.JdbcOdbcStatement)
at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(JdbcOdbcStatement.java:253)
at org.apache.jsp.DocumentsPendingReport$jsp._jspService(DocumentsPendingReport$jsp.java:127)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:202)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:201)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2344)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:462)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1011)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1106)
at java.lang.Thread.run(Thread.java:536)
Dynamic libraries:
0x00400000 - 0x00406000 c:\j2sdk1.4.0_01\bin\java.exe
0x77F80000 - 0x77FFB000 C:\WINNT\system32\ntdll.dll
0x7C2D0000 - 0x7C332000 C:\WINNT\system32\ADVAPI32.dll
0x7C570000 - 0x7C623000 C:\WINNT\system32\KERNEL32.DLL
0x77D30000 - 0x77D9E000 C:\WINNT\system32\RPCRT4.DLL
0x78000000 - 0x78045000 C:\WINNT\system32\MSVCRT.dll
0x6D330000 - 0x6D445000 c:\j2sdk1.4.0_01\jre\bin\client\jvm.dll
0x77E10000 - 0x77E6F000 C:\WINNT\system32\USER32.dll
0x77F40000 - 0x77F79000 C:\WINNT\system32\GDI32.dll
0x77570000 - 0x775A0000 C:\WINNT\system32\WINMM.dll
0x75E60000 - 0x75E7A000 C:\WINNT\system32\IMM32.DLL
0x6CA60000 - 0x6CA68000 C:\WINNT\system32\LPK.DLL
0x66650000 - 0x666A4000 C:\WINNT\system32\USP10.dll
0x6D1D0000 - 0x6D1D7000 c:\j2sdk1.4.0_01\jre\bin\hpi.dll
0x6D300000 - 0x6D30D000 c:\j2sdk1.4.0_01\jre\bin\verify.dll
0x6D210000 - 0x6D228000 c:\j2sdk1.4.0_01\jre\bin\java.dll
0x6D320000 - 0x6D32D000 c:\j2sdk1.4.0_01\jre\bin\zip.dll
0x6D2D0000 - 0x6D2DD000 C:\j2sdk1.4.0_01\jre\bin\net.dll
0x75050000 - 0x75058000 C:\WINNT\system32\WSOCK32.dll
0x75030000 - 0x75044000 C:\WINNT\system32\WS2_32.DLL
0x75020000 - 0x75028000 C:\WINNT\system32\WS2HELP.DLL
0x74FD0000 - 0x74FEE000 C:\WINNT\system32\msafd.dll
0x75010000 - 0x75017000 C:\WINNT\System32\wshtcpip.dll
0x6D250000 - 0x6D25A000 C:\j2sdk1.4.0_01\jre\bin\JdbcOdbc.dll
0x0BDC0000 - 0x0BDF2000 C:\WINNT\system32\ODBC32.dll
0x71780000 - 0x7180A000 C:\WINNT\system32\COMCTL32.dll
0x782F0000 - 0x78538000 C:\WINNT\system32\SHELL32.dll
0x70BD0000 - 0x70C34000 C:\WINNT\system32\SHLWAPI.DLL
0x76B30000 - 0x76B6E000 C:\WINNT\system32\comdlg32.dll
0x1F850000 - 0x1F866000 C:\WINNT\system32\odbcint.dll
0x0BF00000 - 0x0BF5E000 C:\WINNT\System32\SQLSRV32.dll
0x41090000 - 0x410BD000 C:\WINNT\System32\SQLUNIRL.dll
0x77800000 - 0x7781E000 C:\WINNT\System32\WINSPOOL.DRV
0x76620000 - 0x76631000 C:\WINNT\system32\MPR.DLL
0x77820000 - 0x77827000 C:\WINNT\system32\VERSION.dll
0x759B0000 - 0x759B6000 C:\WINNT\system32\LZ32.DLL
0x779B0000 - 0x77A4B000 C:\WINNT\system32\OLEAUT32.dll
0x77A50000 - 0x77B3C000 C:\WINNT\system32\ole32.dll
0x75170000 - 0x751BF000 C:\WINNT\System32\NETAPI32.dll
0x7C340000 - 0x7C34F000 C:\WINNT\System32\SECUR32.DLL
0x751C0000 - 0x751C6000 C:\WINNT\System32\NETRAP.DLL
0x75150000 - 0x7515F000 C:\WINNT\System32\SAMLIB.DLL
0x77950000 - 0x7797A000 C:\WINNT\system32\WLDAP32.DLL
0x77980000 - 0x779A4000 C:\WINNT\System32\DNSAPI.DLL
0x769A0000 - 0x769A7000 C:\WINNT\system32\NDDEAPI.DLL
0x1FA20000 - 0x1FA36000 C:\WINNT\System32\sqlsrv32.rll
0x0C390000 - 0x0C3A9000 C:\WINNT\system32\odbccp32.dll
0x0C3B0000 - 0x0C3BF000 C:\WINNT\system32\DBNETLIB.DLL
0x75500000 - 0x75504000 C:\WINNT\system32\security.dll
0x782D0000 - 0x782EF000 C:\WINNT\system32\msv1_0.dll
0x77440000 - 0x774B8000 C:\WINNT\system32\CRYPT32.DLL
0x77430000 - 0x77440000 C:\WINNT\system32\MSASN1.DLL
0x77BF0000 - 0x77C01000 C:\WINNT\system32\ntdsapi.dll
0x782C0000 - 0x782CC000 C:\WINNT\System32\rnr20.dll
0x77340000 - 0x77353000 C:\WINNT\system32\iphlpapi.dll
0x77520000 - 0x77525000 C:\WINNT\system32\ICMP.DLL
0x77320000 - 0x77337000 C:\WINNT\system32\MPRAPI.DLL
0x773B0000 - 0x773DF000 C:\WINNT\system32\ACTIVEDS.DLL
0x77380000 - 0x773A3000 C:\WINNT\system32\ADSLDPC.DLL
0x77830000 - 0x7783E000 C:\WINNT\system32\RTUTILS.DLL
0x77880000 - 0x7790E000 C:\WINNT\system32\SETUPAPI.DLL
0x7C0F0000 - 0x7C151000 C:\WINNT\system32\USERENV.DLL
0x774E0000 - 0x77513000 C:\WINNT\system32\RASAPI32.DLL
0x774C0000 - 0x774D1000 C:\WINNT\system32\RASMAN.DLL
0x77530000 - 0x77552000 C:\WINNT\system32\TAPI32.DLL
0x77360000 - 0x77379000 C:\WINNT\system32\DHCPCSVC.DLL
0x777E0000 - 0x777E8000 C:\WINNT\System32\winrnr.dll
0x777F0000 - 0x777F5000 C:\WINNT\system32\rasadhlp.dll
0x77920000 - 0x77943000 C:\WINNT\system32\imagehlp.dll
0x72A00000 - 0x72A2D000 C:\WINNT\system32\DBGHELP.dll
0x690A0000 - 0x690AB000 C:\WINNT\system32\PSAPI.DLL
Local Time = Sat May 01 11:30:40 2004
Elapsed Time = 5
# HotSpot Virtual Machine Error : EXCEPTION_ACCESS_VIOLATION
# Error ID : 4F530E43505002D5
# Please report this error at
# http://java.sun.com/cgi-bin/bugreport.cgi
# Java VM: Java HotSpot(TM) Client VM (1.4.0_01-b03 mixed mode)
Also No Error is Thrown with j2sdk1.4.0
If I'm using Not using Scrollable Result Set, No Error is Thrown.
Error is Thrown only with Scrollable Result set and with j2sdk1.4.0_01Did you forget to put the SQL statement in when you used createStatement? I added it below:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("Jdbc:Odbc:IMSMC","sa","");
String sql="select * from <Table Name> ";
Statement stmt=conn.createStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
Does the JDBC-ODBC bridge driver accomodate any of these settings you're trying?
The problem shouldn't have anything to do with Tomcat. Sounds like a JDBC driver issue to me. Try to reproduce the error without Tomcat, and then see if adding the SQL corrects things at all.
I'd read the docs to see if the bridge driver has these features. I don't think it's up to the full standard. -
Result set without using cursor in Oracle
Hi,
I am very much new to oracle. we have a JDBC code and SQL Server procedure and which works fine. Now that we want to implement the same in Oracle also.we deceided not to change the JDBC but to change Stored Procedure and schema.
Assume for Eg there is a stored procedure in SQL Server that return a simple query from table
say
creat procedure Test
as
begin
select * from Accounts
return
end
This procedure returns all the rows in the Accounts table and corresponding java code the fetch all the rows from ResultSet.
CallableStatement cStmt = con.prepareCall("{ call test ? }" );
cStmt.setInt( 1 , id_ );
ResultSet rs = cStmt.executeQuery();
while( rs.next() )
// get all the rows
will give all the rows from the table account.
Now that we want to implement the same in Oracle.
I just want to know, does Oracle provides any way to write a pl/sql or Procedure that returns resultset not as a cursor, but i should work with existing code.
I don't want to declare like the below code
CallableStatement cStmt = con.prepareCall("{? = call BrowseAccount.getRefCursor }");
cStmt.registerOutParameter(1, OracleTypes.CURSOR);
cStmt.execute();
ResultSet rs = null;
rs = (ResultSet)cStmt.getObject(1);
while (rs.next() )
// get the resultset
If anybody have any suggestion or sample code will be really appreciated
thanks
vijayThis is from the Oracle JDBC FAQ at http://otn.oracle.com/tech/java/sqlj_jdbc/htdocs/jdbc_faq.htm#_51_ :
How do the JDBC drivers support Oracle REFCURSOR datatypes?
The Oracle JDBC driver supports bind variables of type REFCURSOR. A REFCURSOR is represented by a JDBC ResultSet. Use the getCursor method of the CallableStatement to convert a REFCURSOR value returned by a PL/SQL block into a ResultSet. JDBC lets you call a stored procedure that executes a query and returns a results set. Cast the corresponding CallableStatement to oracle.jdbc.driver.OracleCallableStatement to use the getCursor method.
Importing classes from the oracle.jdbc.driver package makes programs more readable. Here is a simple example. The samples subdirectory of the distribution has additional examples.
import oracle.jdbc.driver.*;
CallableStatement cstmt;
ResultSet cursor;
// Use a PL/SQL block to open the cursor
cstmt = conn.prepareCall
("begin open ? for select ename from emp; end;");
cstmt.registerOutParameter (1, OracleTypes.CURSOR);
cstmt.execute ();
cursor = ((OracleCallableStatement)cstmt).getCursor (1);
// Use the cursor like a normal ResultSet
while (cursor.next ())
{System.out.println (cursor.getString (1));} -
Result set problem with GROUP BY
hi there, this should be the simplest of queries but.........
when run, the list size is 13, this is the number of letting units in the table. it appears not to be grouping by the property id.if it was doing this there should only be 8 rows. having said this, the while loop should output the count of each row, it does this 8 times with the correct counts. it then crashes with a invalid curser error. it appears the query is workig correctly but the resultset thinks its got 13 rows when it only has 8.
accessing ms access db
using jdbc:odbc
heres the code
searchResults = stmt.executeQuery(
"SELECT Count(*) AS FreeUnits " +
"FROM letting_units " +
"GROUP BY letting_units.property_id");
searchResults.last();
listSize = searchResults.getRow();
searchResults.beforeFirst();
System.out.println(listSize);
while (searchResults.next())
System.out.println(searchResults.getString(1));
hope someone can help me
cheers
andyIt's not the problem with GROUP BY. You should use scrollable result set to move in both directions (forward and backward).
In your code
searchResults.beforeFirst(); line may return false. So you will get the searchResults.next() false. Once you move forward in non-scrollable cursor cannot come back. So when you create the statement object use TYPE_SCROLL_INSENSITIVE or TYPE_SCROLL_SENSITIVE constants provided in the ResultSet. -
Scrollable result set fails with doubles
Hi there,
i have a strange behaviour using the 10g thin JDBC driver:
Using a scrollable result set the driver fails reading a BINARY_DOUBLE value from the result set with rs.getDouble(column) as long as the value is not null. The SQLException reports "Conversion to double failed".
When i use a forward-only result set instead, the value can be retrieved without any error. Can anyone explain this or give a workaround?
Thanks in advance,
ThorstenThorstenS,
ScrollableResultSet stores BINARY_DOUBLE column as oracle.sql.BINARY_DOUBLE & since, oracle.sql.BINARY_DOUBLE does not have method to convert to double you are seeing this error.
The workaround would be to do,
rs.getBINARYDOUBLE(1).stringValue()
& please file an enhancement request against Jdbc.
=
Ashok -
Select clause inside a Procedure with cursor
Good Moring guys,
I run into a problem that is giving me serious troubles.... I have a Select clause:
SELECT count(*)
FROM TD004_ENT_ORGAO_UO TD004
WHERE TD004.CODG_ENTIDADE = 1121742
AND TD004.NUMR_ANO_EXERCICIO = 2011
AND TD004.CODG_ORGAO = 02
AND TD004.CODG_UO = 001
My table is empty and this query returns a count = 0, so far so good but, when I'm using this same query inside a Procedure that implements a cursor, I'm implementing a way of controling when to or not insert the records of this cursor in my table:
OPEN cDIMENSAO;
LOOP
FETCH cDIMENSAO INTO EXERCICIO, CODG_ORGAO, NOME_ORGAO, CODG_UO, NOME_UO, CODG_ENTIDADE, SK_ENTIDADE;
EXIT WHEN cDIMENSAO%NOTFOUND;
begin
v_count := 0;
SELECT count(*) into V_COUNT
FROM TD004_ENT_ORGAO_UO TD004
WHERE TD004.CODG_ENTIDADE = CODG_ENTIDADE
AND TD004.NUMR_ANO_EXERCICIO = EXERCICIO
AND TD004.CODG_ORGAO = CODG_ORGAO
AND TD004.CODG_UO = CODG_UO;
IF V_COUNT = 0 THEN
INSERT INTO APLIC.TD004_ENT_ORGAO_UO(SK_ENT_ORGAO_UO, NUMR_ANO_EXERCICIO, CODG_ORGAO, NOME_ORGAO, CODG_UO, NOME_UO, CODG_ENTIDADE, SK_ENTIDADE, DATA_CARGA)
VALUES (APLIC.SK004_ENT_ORGAO_UO.NEXTVAL, EXERCICIO, CODG_ORGAO, NOME_ORGAO, CODG_UO, NOME_UO,CODG_ENTIDADE,SK_ENTIDADE,v_data_carga);
COMMIT;
END IF;
The problem occurs here, my v_count controler just returns 1 even if the record isnt inside my table, is like the Where clasue is being ignored. What can be done ??
I'm using the Oracle XE 11g.
Thnks all.See below. Where clause will never ignore any condition
Note: you need handle null values specially
SQL>
SQL> select * from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
CORE 11.2.0.2.0 Production
TNS for Linux: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production
SQL>
SQL> set serveroutput on;
SQL>
SQL> DECLARE
2 CURSOR c1
3 IS
4 WITH dmn
5 AS (SELECT 1 col1, 'TEST' col2, NULL col3 FROM DUAL
6 UNION ALL
7 SELECT 2 col1, 'TESTING' col2, 'COL3' col3 FROM DUAL
8 UNION ALL
9 SELECT 3 col1, 'TESTING123' col2, 'COL3' col3 FROM DUAL
10 )
11 SELECT *
12 FROM dmn;
13
14 v_col1 VARCHAR2 (10);
15 v_col2 VARCHAR2 (10);
16 v_col3 VARCHAR2 (10);
17 v_count NUMBER;
18 BEGIN
19 OPEN c1;
20
21 LOOP
22 FETCH c1
23 INTO v_col1, v_col2, v_col3;
24 EXIT WHEN c1%NOTFOUND;
25
26 WITH txn
27 AS (SELECT 1 col1, 'TEST' col2, NULL col3 FROM DUAL
28 UNION ALL
29 SELECT 2 col1, 'TESTING' col2, 'COL3' col3 FROM DUAL
30 )
31 SELECT COUNT (*)
32 INTO v_count
33 FROM txn
34 WHERE col1 = v_col1
35 AND col2 = v_col2
36 AND nvl(col3,'##') = nvl(v_col3, '##');
37
38 DBMS_OUTPUT.put_line ('V_count = ' || v_count);
39 IF v_count = 0
40 THEN
41 DBMS_OUTPUT.put_line ('Insert is processed for ' || v_col1);
42 ELSE
43 DBMS_OUTPUT.put_line ('Insert is Ignored for ' || v_col1);
44 END IF;
45 v_count := 0;
46 END LOOP;
47 END;
48 /
V_count = 1
Insert is Ignored for 1
V_count = 1
Insert is Ignored for 2
V_count = 0
Insert is processed for 3
PL/SQL procedure successfully completed.
Thanks,
GPU -
Toplink storedProcedure/funtion + PL/SQL Procedure with cursor
Hi,
I am working on Toplink storedProcedure but, I am not getting any output. I go through the Oracle Tutorial but, still I am not getting any alternative.
please, anyone help out....
Thanking You,
regards,
sufianHello Sufian,
You seem to have a few threads trying to get a Stored proc working. In How to work with Toplink + PL/SQL Procedure + Cursor
you mention you get an error when executing, have you gotten past this exception? You may want to turn on TopLink logging to see the statement TopLink is creating and sending to the driver. Please see
http://www.oracle.com/technology/products/ias/toplink/doc/1013/main/_html/sescfg004.htm
If you are not familar with how to turn on logging.
Also, are you able to get results from a stored procedure that returns data instead of a cursor?
Best Regards,
Chris -
I have the following code:
CREATE OR REPLACE PROCEDURE RENTALPAYMENTS( p_PROPERTY_DETAIL_ID LMR_PROPERTY_DETAILS.LMR_PROPERTY_DETAIL_ID%TYPE )
IS
CURSOR property_detail_cur IS SELECT RENT, BOND, START_DATE, LEASE_PERIOD, PAYMENT_INTERVAL, PROP_PROPERTY_ID, TEN_TENANT_ID
FROM LMR_PROPERTY_DETAILS WHERE LMR_PROPERTY_DETAIL_ID = p_PROPERTY_DETAIL_ID;
v_rent LMR_PROPERTY_DETAILS.RENT%TYPE;
v_bond LMR_PROPERTY_DETAILS.BOND%TYPE;
v_startdate LMR_PROPERTY_DETAILS.START_DATE%TYPE;
v_lease_period LMR_PROPERTY_DETAILS.LEASE_PERIOD%TYPE;
v_payment_interval LMR_PROPERTY_DETAILS.PAYMENT_INTERVAL%TYPE;
v_property_id LMR_PROPERTY_DETAILS.PROP_PROPERTY_ID%TYPE;
v_tenant_id LMR_PROPERTY_DETAILS.TEN_TENANT_ID%TYPE;
BEGIN
OPEN property_detail_cur;
LOOP
FETCH property_detail_cur INTO v_rent, v_bond, v_startdate, v_lease_period, v_payment_interval, v_property_id, v_tenant_id;
DBMS_OUTPUT.PUT_LINE('RENT: '||v_rent);
DBMS_OUTPUT.PUT_LINE('BOND: '||v_bond);
DBMS_OUTPUT.PUT_LINE('START DATE: '||v_startdate);
DBMS_OUTPUT.PUT_LINE('LEASE PERIOD: '||v_lease_period);
DBMS_OUTPUT.PUT_LINE('PAYMENT INTERVAL: '||v_payment_interval);
DBMS_OUTPUT.PUT_LINE('PROPERTY ID: '||v_property_id);
DBMS_OUTPUT.PUT_LINE('TENANT ID: '||v_tenant_id);
EXIT WHEN property_detail_cur%NOTFOUND;
END;
It should be obvious looking at the code what I am attempting to do.
I get the following error when running on the SQL Commandline in Oracle APEX:
Error at line 35: PLS-00103: Encountered the symbol ";" when expecting one of the following:
loop
It highlights line 3.It should be obvious looking at the code what I am attempting to do.There could be a difference with what your code does, and what you are attempting to do... 'cause what your code does is not compile, and that is probably not what your attempting to do... ;)
Anyway, you are missing the END LOOP;
The way you go through the cursor is row-by-row (a.k.a slow-by-slow), and you don't need al those local variables:
CREATE OR REPLACE PROCEDURE RENTALPAYMENTS( p_PROPERTY_DETAIL_ID LMR_PROPERTY_DETAILS.LMR_PROPERTY_DETAIL_ID%TYPE )
IS
begin
for rec in (
SELECT RENT, BOND, START_DATE, LEASE_PERIOD, PAYMENT_INTERVAL, PROP_PROPERTY_ID, TEN_TENANT_ID
FROM LMR_PROPERTY_DETAILS
WHERE LMR_PROPERTY_DETAIL_ID = p_PROPERTY_DETAIL_ID
loop
DBMS_OUTPUT.PUT_LINE('RENT: '||rec.rent);
DBMS_OUTPUT.PUT_LINE('BOND: '||rec.bond);
DBMS_OUTPUT.PUT_LINE('START DATE: '||rec.startdate);
DBMS_OUTPUT.PUT_LINE('LEASE PERIOD: '||rec.lease_period);
DBMS_OUTPUT.PUT_LINE('PAYMENT INTERVAL: '||rec.payment_interval);
DBMS_OUTPUT.PUT_LINE('PROPERTY ID: '||rec.property_id);
DBMS_OUTPUT.PUT_LINE('TENANT ID: '||rec.tenant_id);
end loop;
END;
/.. not tested of course... -
I wanted to have a cursor in my procedure having results from different tables and different databases. I successfully created the query and compiled it using the procedure builder. However, when i was about to create it as stored procedure in iSQLplus, it displayed a warning. It says "Procedure created wuth compilation error." The first error is "PLS-00341: declaration of cursor 'SUBJ_CUR' is incomplete or malformed"
Here's a piece of my code:
PROCEDURE assess(STUD_ID VARCHAR2, STUD_YEAR NUMBER, STUD_TYPE CHAR) IS
CURSOR subj_cur IS
SELECT e.student_id, s.subject_id, s.subj_code, s.subject_title, s.units, s.pay_units,
d.department_name, s.tuition_fee_type, s.lab_fee_type, f.year, f.amount
FROM regist.enrol e, regist.offering o, regist.subject s,
fee_details f, regist.student st, regist.department d
WHERE (e.student_id = STUD_ID) AND (e.offering_id = o.offering_id) AND
(o.subject_id = s.subject_id) AND (f.fee_no = s.tuition_fee_type) AND
(st.student_id=e.student_id) AND ((f.year = STUD_YEAR) OR (f.year=0)) AND
(s.department_id = d.department_id);
regist and system are databases.
Can anyone tell me where did I go wrong?
I resorted though in creating views, however I still received an error. It says, "Insufficient privileges"
Help me please..... I really need it badly..First of all, I've no experience with iSQLplus. I'm just wondering in which database the table fee_details is: system or regist? You didn't prefix the table.
-
Error in procedure with cursor which has a select query in NVL
cursor has a select statement in the NVL functiion
sample query in given
SELECT fu.user_name Core_ID,
fu.description User_Name,
fu.LAST_LOGON_DATE LAST_LOGON_DATE,
TRUNC(SYSDATE) - TRUNC(fu.LAST_LOGON_DATE) DAYS_SINCE_LAST_LOGON,
NVL((SELECT 'YES' FROM custmot.moto_rma_approvers mra
WHERE mra.primary_approver = fu.user_name),'NO') PRIMARY_RMA_APPROVER,
NVL((SELECT 'YES' FROM custmot.moto_rma_approvers mra
WHERE mra.secondary_approver = fu.user_name), 'YES', 'ALL RESPONSIBILITIES',
DECODE(fu.employee_id, NULL, 'USER ACCOUNT', 'ALL RESPONSIBILITIES' ))) END_DATE_WHAT
FROM apps.fnd_user fu
This query runs fine when it is run seperately. But when its defined in cursor in a procedure it throws up the following error.
"Encountered the symbol "SELECT" when expecting one of the following:
( - + mod not null others <an identifier>
<a double-quoted delimited-identifier> <a bind variable> avg
count c"
can you please help us with thisI noticed your statement has one additional end-bracket at the end. Probably this is just a typo. It should read like this:
SELECT fu.user_name core_id,
fu.description user_name,
fu.last_logon_date last_logon_date,
TRUNC (SYSDATE) - TRUNC (fu.last_logon_date) days_since_last_logon,
NVL ((SELECT 'YES'
FROM custmot.moto_rma_approvers mra
WHERE mra.primary_approver = fu.user_name), 'NO')
primary_rma_approver,
NVL ((SELECT 'YES'
FROM custmot.moto_rma_approvers mra
WHERE mra.secondary_approver = fu.user_name),
'YES',
'ALL RESPONSIBILITIES',
DECODE (fu.employee_id,
NULL, 'USER ACCOUNT',
'ALL RESPONSIBILITIES'
) end_date_what
FROM apps.fnd_user fuIf that doesn't help, you may make your cursor dynamic:
OPEN c FOR 'SELECT fu.user_name core_id,
fu.description user_name,
fu.last_logon_date last_logon_date,
TRUNC (SYSDATE) - TRUNC (fu.last_logon_date) days_since_last_logon,
NVL ((SELECT ''YES''
FROM custmot.moto_rma_approvers mra
WHERE mra.primary_approver = fu.user_name), ''NO'')
primary_rma_approver,
NVL ((SELECT ''YES''
FROM custmot.moto_rma_approvers mra
WHERE mra.secondary_approver = fu.user_name),
''YES'',
''ALL RESPONSIBILITIES'',
DECODE (fu.employee_id,
NULL, ''USER ACCOUNT'',
''ALL RESPONSIBILITIES''
) end_date_what
FROM apps.fnd_user fu'; -
Excution of a PL/SQL procedure with CURSOR for big tables
I have prepared a proceudre that uses CURSOR to make a complex query for tables with big number of records, something like 900'000. And the execution failed; ORA-01652:impossible to extend the temporary segment of 64 in the space of storage TEMP.
Any sugestion.This brings us to the following question: How could I calculate the bytes required by a cursor?. It is a selection of certain fields of very big tables. Let's say that the fields are NUMBER(4), NUMBER(8) and CHAR(2). The fields are in 2 relational tables of 900'000 each. What size is required for a procedure like this.
Your help is really appreciated. -
Help need for procedure with "cursor in a cursor"
Hi
Iam using two cursors in my procedure.
Create SP_sample as
cursor C1 is
select a from A
cursor C2 is
select
a,bc,d from A,B where A.a=B.a
Begin
For Cur_rec C1 loop
For Cur_rec1 C2 loop
"SELECT QUERY"
end loop
end loop
end
1)the "SELECT QUERY" is working fine in Toad or sql editor.
2)The procedure is compiled without any errors
But when I am executing the procedure I am getting the error
ORA-01403: no data found
ORA-06512: at the line where "SELECT QUERY" is starting
ORA-06512: at line 1
can you please suggest what are the things I should be checking.
ThanksCould you provide a more complete example of what you are doing.
Your example is vague on the details, and it appears that you have 2 cursors both selecting from table A that you are looping through in a nested fashion, but your inner cursor is not correlated with your outer cursor. Also you have skimped on the details of the select you are trying to perform in the inner most loop of your code, and there is no indication that it has any correlation to the two outer cursors, and to top it off you have completely left out any syntactic punctuation.
why not rewrite your code thusly:
declare
cursor c1 is select a from a;
cursor c2(p_a a.a%type) is select bc, d from b where b.a = p_a;
begin
for cur_rec in c1 loop
for cur_rec1 in c2(cur_rec.a) loop
select ...
into ...
from ....
where ??= cur_rec.a
and ??=cur_rec1.bc
and ??=cur_rec1.d;
end loop;
end loop;
end; -
Return a Result set from a cursor
Is it necessary to create a temporary table to show the rows I want? there is another way?
Ex.:
DECLARE
CURSOR c1 is
SELECT ename, empno, sal FROM emp
ORDER BY sal DESC;
my_ename VARCHAR2(10);
my_empno NUMBER(4);
my_sal NUMBER(7,2);
BEGIN
OPEN c1;
FOR i IN 1..5 LOOP
FETCH c1 INTO my_ename, my_empno, my_sal;
EXIT WHEN c1%NOTFOUND;
INSERT INTO temp VALUES (my_sal, my_empno, my_ename);
COMMIT;
END LOOP;
CLOSE c1;
END;
SELECT * FROM temp ORDER BY col1 DESC;No cursor or temp table needed. Note the difference between dense_rank() and rank().
sql>select *
2 from (select ename, empno, sal, dense_rank() over (order by sal desc) rank
3 from emp)
4 where rank <= 5;
ENAME EMPNO SAL RANK
KING 7839 5000 1
SCOTT 7788 3000 2
FORD 7902 3000 2
JONES 7566 2975 3
BLAKE 7698 2850 4
CLARK 7782 2450 5
6 rows selected.
sql>select *
2 from (select ename, empno, sal, rank() over (order by sal desc) rank
3 from emp)
4 where rank <= 5;
ENAME EMPNO SAL RANK
KING 7839 5000 1
SCOTT 7788 3000 2
FORD 7902 3000 2
JONES 7566 2975 4
BLAKE 7698 2850 5
5 rows selected.
-- and the non-analytic function approach
sql>select *
2 from (select ename, empno, sal
3 from emp
4 order by sal desc)
5 where rownum <= 5;
ENAME EMPNO SAL
KING 7839 5000
SCOTT 7788 3000
FORD 7902 3000
JONES 7566 2975
BLAKE 7698 2850
5 rows selected.
Maybe you are looking for
-
Hi All, I need to fetch data from a view. The size of the view is huge. If select statements are used, the time taken is large which results in dump. Could anybody suggest me as to how I can extract data from this view? Regards, Pavan.
-
.m4v file icons have become solid white in Finder under iTunes 10.6.3
Hi there, I just discovered this little annoyance... I thought I'd seen the last of it under a prior version of iTunes, but it may have come back. iTunes video files (.m4v container files) have suddenly defaulted to a plain white icon in the Finder -
-
Adobe PDF iFilter SQL Server 2008 R2 Full Text not working
Unable to get the SQL Server 2008 R2 to index PDF files for full-text searching. Environment: Windows 7 SP1 Enterprise 64-bit, SQL Server 2008 R2 Express SP3 64-bit, Adobe Reader 11.x Installed PDF iFilter 64 (11.0.01) from http://www.adobe.com/suppo
-
Router blocks random IP or Domain Addresses
This appears to be a rather unusual problem and has only been noticed in the past month. Suddenly without any apparent warning, certain web sites are no longer accessible. This was first noticed when I was unable to access my pop3 email from the www.
-
Hi, I am trying to create an PO Confirmation in EBP using BAPI_CONFEC_CREATE,but unsuccessful.Can any one tell me what parameters i should be passing or if i am using the right BAPI or is there any other way of achiving this. Thanks Raghu