Getting ResultSet from Oracle procedure
I am trying to get a ResultSet object by executing a stored procedure in Oracle.
The ResultSet is one of the parameters of this procedure. Typical code:
CallableStatement st = cn.prepareCall("{ call sc_getkeyfieldinfo(?,?) }");
st.setMaxRows(2); //this doesnt do anything
st.setString(1, "T11_2003_1");
st.registerOutParameter(2, OracleTypes.CURSOR);
st.execute();
ResultSet rs = (ResultSet) st.getObject(2);
while (rs.next()) {
System.out.println(rs.getString(1));
How would I get only certain number of rows in my ResultSet ? The setMaxRows on a callable statement did not do anything. Neither does the setFetchSize().
When we get a ResultSet directly by executing a query from a Statement, these maxSize and fetchSize parameters set there do the job and return a ResultSet of specified size(# of rows). But on a CallableStatement it didn't do anything.
Anyone knows how to achieve this ?????
Amit
I'm not sure there is a way to do it automatically in the driver.
Two possible ways are:
(A) Limit the number of rows selected in the stored procedure, potentially by adding another parameter indicating the number of rows you'd like. Modify the select to do something like and rownum < 10(B) Only process the number of rows that you actually want; this may be less than ideal if the total set of records from which you're choosing a limited number if large. E.g.
int count = 0;
while (count++ <= 2 && rs.next()) {
// Process the row
}I'd be interested to know exactly what happens in the Oracle dirver when you use "setMaxRows" anyway... does it modify your query or does it simply stop returning results after that number.
Tim
Similar Messages
-
How to get resultset from oracle procedure use ejb3
how to get resultset from oracle procedure use ejb3
i know oracle procedure should like this
Create or replace PROCEDURE resultset_test(
aaa IN NUMBER,
bbb OUT sys_refcursor) ....
but what s the ejb3 scripts looks like? please give me an example or link~
ths- there are no EJB3 scripts, only compiled application code
- the part of the EJB spec that deals with databases is called the Java Persistence API, but likely you are just looking for the JDBC API.
Now you should know what to Google to get your "example script": "java jdbc oracle procedure" -
Getting resultset from stored procedures..
hi all,
i have got some very fundamental doubts regarding Oracle Stored Procedures and calling it from java.. i want the resultset to be returned from sp and for that i used to following sp and java code.
package
====
CREATE OR REPLACE package
curs_types as
type EmpCurType is REF CURSOR RETURN emp%ROWTYPE;
end curs_types;
procedure
======
procedure
single_cursor(curs1 IN OUT curs_types.EmpCurType)
AS
BEGIN
OPEN curs1 FOR SELECT * FROM emp;
END single_cursor;
java code for calling sp
=========
String sql = "{call single_cursor(?)}";
CallableStatement cstmt1 = con.prepareCall(sql);
cstmt1.registerOutParameter(1, OracleTypes.CURSOR);
cstmt1.execute();
rs = (ResultSet)cstmt1.getObject(1);
while(rs.next())
{ String empno=(String)rs.getString(1);
and it worked properly but the problem is i dont want all the fields from the table emp..i mean, if i change the query inside the sp from "select * from emp" to "select ename,empno from emp" then that sp is showing compilation errors.. is it possile to return a cursor from sp that contains specific fields ??
wat is the procedure to return a cursor that contain datas from multiple tables ???
can any1 help me with this ??? plz mail me on [email protected]
thanks in advance
raj.>
and it worked properly but the problem is i dont want
all the fields from the table emp..i mean, if i
change the query inside the sp from "select * from
emp" to "select ename,empno from emp" then that sp is
showing compilation errors.. You have a cursor with specific fields, so you have to fill all of them in.
is it possile to return
a cursor from sp that contains specific fields ??
Yes. See your Oracle docs.
wat is the procedure to return a cursor that contain
datas from multiple tables ???Yes. Same as a select from multiple tables. -
How to get a resultset from Stored Procedures
How to efficiently and portably get resultsets from Oracle stored procedures? Oracle does not seem to follow JDBC standards here. A standard way in Oracle is to use a ref cursor and call getObject() on CallableStatement. However, Oracle seems to get all the data in the resultset in getObject(), which is inefficient and leads to large memory usage when the resultset is large.
Another way in Oracle is to use getCursor() on an OracleCallableStatement, which is efficient but not portable across different application servers. For example, in WebSphere, this OracleCallableStatement is not available if we want WebSphere to manager the datasource.
Any ideas will be greatly appreciated. Please email to [email protected]Oracle JDBC did not support return a result set, if you are using Oracle 9i, you can use pipeline function, then using the TABLE() function the get the row.
Good Luck.
Welcome to http://www.anysql.net/en/ -
Returning rowcount and resultset from stored procedure
Hello,
In SQL Server you can return multiple resultsets from stored procedure by simple SELECT statement. But in Oracle, you have to use SYS_REFCURSOR.
Sample code:
CREATE OR REPLACE PROCEDURE sp_resultset_test IS
t_recordset OUT SYS_REFCURSOR
BEGIN
OPEN t_recordset FOR
SELECT * FROM EMPLOYEE;
END sp_resultset_test;
Is there any other way in Oracle 10 or 11 ?
Thank You.What is the requirement? Oracle is far more flexible than SQL-Server... with numerous features that do not exist in SQL-Server. (Fact)
One of the biggest mistakes you can make is to treat Oracle like SQL-Server... trying to match feature A1 in SQL-Server to feature B3 in Oracle.
Does not work that way.. rather then stick to SQL-Server as SQL-Server does SQL-Server specific features far better than Oracle.
So instead of trying to map what a T-SQL stored proc to do to an Oracle ref cursor (even to the extent of using that very silly sp_ prefix to name the proc), tell us the problem and requirements... That way we can tell you what Oracle features and options are best used to solve that problem - instead of competing in some unknown feature comparison event with SQL-Server. -
Sending mail from oracle procedure
Hi Experts,
I want to send mail from oracle Procedure. Anybody please help me out.
Thanks.BEGIN
UTL_MAIL.send(sender => '[email protected]',
recipients => '[email protected],[email protected]',
cc => '[email protected]',
bcc => '[email protected]',
subject => 'UTL_MAIL Test',
message => 'If you get this message it worked!');END; -
Get date from Oracle when local time zone is different from Oracle time zon
Hi!
Local machine time zone= +2
Oracle time zone= +1
I set date to Oracle using java.sql.Date.
From application I save date at 00:30 clock and send e.g. 28.06.2002, but in Oracle date is save as 27.06.2002 01:00 (hour=01 , I suppose that is because java.sql.Date hasn't time the Oracle set it time = time zone=+1) And when I get date from Oracle I get incorrect date. In SQL I don't use date masks. Maybe solution is to use java.sql.Timestamp object (when save date to Oracle) instead of java.sql.Date?
But if I save date at e.g. 01:00 clock and send e.g. 28:06.2002 in Oracle, date is save as 28.06.2002 01:00 and when I read from Oracle I get correct date.
Thank you.Hi!
Local machine time zone= +2
Oracle time zone= +1
I set date to Oracle using java.sql.Date.
From application I save date at 00:30 clock and send
e.g. 28.06.2002, but in Oracle date is save as
27.06.2002 01:00 (hour=01 , I suppose that is because
java.sql.Date hasn't time the Oracle set it time =
time zone=+1) Presumably you are using setTimestamp() to store the value. If you are explicitly using a varchar (string) then you will have to correct the timezone your self.
And when I get date from Oracle I get
incorrect date. In SQL I don't use date masks. Maybe
solution is to use java.sql.Timestamp object (when
save date to Oracle) instead of java.sql.Date?The method setDate/getDate store a 'date' which is not the same as a 'date and time' for which setTimestamp/getTimestamp are used.
But if I save date at e.g. 01:00 clock and send e.g.
28:06.2002 in Oracle, date is save as 28.06.2002
01:00 and when I read from Oracle I get correct date.
Thank you. -
How to get information from Oracle's views
Hi,
I need to get information from Oracle's views about:
* in which table's column is set index
* what type of index is on this column
* name of a trigger which exist on a table
* type of trigger (before, after etc)
* trigger status (enable, disable)
Thanks for help.Hi..
One of the best way to know which views to use is doing select * from dict where table_name like 'xxx';
For example in your case you needed to know about the indexes and triggers so
SQL> select * from dictionary where table_name like 'DBA_IND%';
TABLE_NAME COMMENTS
DBA_INDEXES Description for all indexes in the database
*DBA_IND_COLUMNS COLUMNs comprising INDEXes on all TABLEs and CLUSTERs*
DBA_IND_EXPRESSIONS FUNCTIONAL INDEX EXPRESSIONs on all TABLES and CLUSTERS
DBA_INDEXTYPES All indextypes
DBA_INDEXTYPE_COMMENTS Comments for user-defined indextypes
DBA_INDEXTYPE_ARRAYTYPES All array types specified by the indextype
DBA_INDEXTYPE_OPERATORS All indextype operators
DBA_IND_PARTITIONS
DBA_IND_SUBPARTITIONS
DBA_IND_STATISTICS Optimizer statistics for all indexes in the database
10 rows selected.
SQL> select * from dictionary where table_name like 'DBA_TRI%';
TABLE_NAME COMMENTS
DBA_TRIGGERS All triggers in the database
DBA_TRIGGER_COLS Column usage in all triggers
Reading the comments you can know which view to use, then describe the view and use what you need -
How to get data from Oracle to SAP
Hi All,
I want to get data from Oracle to my internal table in SAP,
I worked on puting the data from SAP to Oracle, it's working fine...
Can anybody suggest the code for accessing from Oracle with 4 primary keys in oracle.
regards
manishhi
good
there is two things in sap open sql and native .if you ll use the open sql than you can access any database.
thanks
mrutyun -
Submitting xml publisher not producing output file when submiting from Oracle Procedure
When Running XML publisher program from Oracle Procedure, Program not generating output file, but same XML publisher program running from Concurrent program runs and produces the output file.
Here is the code
CREATE OR REPLACE PROCEDURE apps.wmmgd_sepa_formats (
p_return_msg OUT VARCHAR2,
p_return_code OUT NUMBER,
p_payment_batch IN VARCHAR2 ---,
--- p_bank_name in varchar2
IS
name: wmmgd_sepa_formats
purpose: this procedureis to create SEPA payment formats
revisions:
ver date author description
1.0 6/11/2013 V Gongireddy Created the Procedure
l_ret BOOLEAN;
l_req_id NUMBER;
v_org_id NUMBER;
v_cntr NUMBER;
v_file_name fnd_concurrent_requests.outfile_name%TYPE;
v_language VARCHAR2 (20);
BEGIN
SELECT fnd_profile.VALUE ('ORG_ID')
INTO v_org_id
FROM DUAL;
fnd_file.put_line (fnd_file.LOG, 'org id ' || v_org_id);
fnd_file.put_line (fnd_file.output, 'Start org id ' || v_org_id);
FOR i IN 1 .. 10000
LOOP
v_cntr := v_cntr + 1;
END LOOP;
l_ret :=
fnd_request.add_layout ('SQLAP',
' WMMGDSEPAFORMATXSL',
'en',
'US',
'XML'
IF l_ret = TRUE
THEN
BEGIN
fnd_file.put_line (fnd_file.output,
'Payment batch ' || p_payment_batch
l_req_id :=
fnd_request.submit_request ('SQLAP',
'WMMGDSEPAFORMAT',
FALSE,
p_payment_batch
v_cntr := 0;
FOR i IN 1 .. 10000
LOOP
v_cntr := v_cntr + 1;
END LOOP;
p_return_msg := 'Request submitted. ID = ' || l_req_id;
p_return_code := 0;
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
p_return_msg :=
'Payment Request set submission failed - unknown error: '
|| SQLERRM;
p_return_code := 2;
fnd_file.put_line (fnd_file.LOG,
'the_request_id ' || l_req_id || p_return_msg
END;
END IF;
END wmmgd_sepa_formats;
Thanks in advanceAnd metalink note 1100253.1 states that this issue (java.lang.StackOverflowError) might be caused by a too large set of data to be sorted in the layout file. Recommendation is to removed the sort from the layout file and instead sort the data already in the data definition.
regards,
David. -
Getting resultset from out parameter ref cursor
hi,
i have written one procedure which return one refcursor as out parameter.
when i am calling that proceduer how can i retrive that resultsets in my current program.
ex
DECLARE
type A is ref cursor;
B A;
x NUMBER :=0;
BEGIN
APPSEARCH(NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,B);
FOR i in b
loop
x:= x+1;
end loop;
DBMS_OUTPUT.PUT_LINE('ANS '||x);
END;
but it is giving error
please advice
thanks
sivaThanks alessandro,
SQL> DECLARE
2 type A is ref cursor;
B A;
3 4 C b%rowtype;
5 d NUMBER;
6 BEGIN
7 APPSEARCH(NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,B);
8 loop
9 fetch b into c;
10 exit when b%notfound;
11 DBMS_OUTPUT.PUT_LINE('ANS '||c%rowcount);
12 end loop;
13 close b;
14 END;
15 /
C b%rowtype;
ERROR at line 4:
ORA-06550: line 4, column 4:
PLS-00320: the declaration of the type of this expression is incomplete or
malformed
ORA-06550: line 4, column 4:
PL/SQL: Item ignored
ORA-06550: line 9, column 17:
PLS-00320: the declaration of the type of this expression is incomplete or
malformed
ORA-06550: line 9, column 4:
PL/SQL: SQL Statement ignored
ORA-06550: line 11, column 35:
PLS-00320: the declaration of the type of this expression is incomplete or
malformed
ORA-06550: line 11, column 6:
PL/SQL: Statement ignored
i dont know how to transfer the resultset from the procedure refcursor out parameter to my local cursor variable please help -
Getting resultset from some other java program
how could i getting resultset from some other java program?
plza resultset is directly linked to your (prepared) query.
for performance(and synchronization) reasons, you do want to retrieve the data as fast as possible and then release it. -
JSON - get data from Oracle table
Hi all,
I hope it is correct thread...
My need is to get data from oracle table using JSON and show output at html table. I'm very new to JSON (got some experience in PL/SQL and basic html knowledge). Could someone direct me to manual or give me simple example?JSON is a way to format data, not a way to fetch data. Call it an alternative to XML.
Are you perhaps talking about doing an ajax request to fetch data? -
How get support from oracle for reports6i
how get support from oracle for reports6i
If you have support contract with Oracle, you can use this site:
http://www.metalink.oracle.com
or for more information
http://www.oracle.com/support/premier/global-support-resolution/metalink.html -
When a program gets disconnected from ORACLE?
Hi all,
I have written an proc program .I have to handle the disconnection from oracle in the
middle of a program.
Can any one tell me what are the majour/important cases in which a program gets disconnected from oracle and also how to test these cases.
Please help me in this regard ,
Thanks in advance,
Trinath Somanchi,
Hyderabad.there is some OP report after Windows update Dec 2014 macro stop responding ( I cant confirm if this is also related to your issue) its because security update for Office maybe conflict with the active-x that you are installed
try to
Close Excel
Start Windows Explorer.
Select your system drive (usually C:)
Use the Search box to search for *.exd
Delete all the files it finds.
Start Excel again
Open that file and save it, and try open at Windows 7
to get more detail about this issue, I suggest also contact Office forum
this case also will be solve installing kb3025036
good luck
Maybe you are looking for
-
iMac internal drive locks up after trying to play a DVD. CD's work properly. All preference settings are correct. I have tried several different DVD's that work in other drives. Drive is : HL-DT-ST DVDRW GA11N. After spinning wheel of doom goes away,
-
I just purchased a Macbook Pro but unable to set up dual display with samsung syncmaster 2033 via DVI to HDMI port. Thank you in advance for help.
-
How to open a e-card in attachment?
Jam trying to open an e-card in a email.
-
How to reduce render time?
I have created two separate events in FCP X that are both completely done and fully rendered. I now want to combine them onto one timeline and then send them to Compressor to burn a DVD for a client. It is frustrating to have to wait for this new 3
-
Default word processor??
How can I set Pages (or Word, for that matter) as the default word processor for opening attached documents in Mail? They always used to open automatically in Word, but someone has changed the settings somehow and now everything opens in TextEdit!!