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
vijay
This 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));}
Similar Messages
-
How to manipulate data in multiple rows without using cursor??
Hi all,
I have a form in which there is a push button & 4 text fields.
Push button : Process
Text fields: Year, Month, Financial_To_Year, Financial_From_Date.
In database , there are tables like, CUSTOMER_MASTER, FD_ACCOUNT_MASTER, FD_ACCOUNT_DTL, CUSTOMER_YEARLY_INTEREST, etc.
In table FD_ACCOUNT_MASTER, there are columns, like CUST_CODE, FD_ACCT_NO, FD_AMOUNT, ACCT_OPEN_DT, ACCT_CLOSE_DATE, ACCT_TYPE, INTEREST_RATE, etc.
There are thousands of records in the table.
For Push button : Process , TRIGGER: When button pressed,
I have to do all the process of FD for all the FD_ACCOUNTS at once. Process means i have to calculate Interest for all the accounts, calculate interest monthly, quarterly, yearly and make the FD_Accounts disable after the date of ACCT_CLOSE_DATE is reached, make the accounts renewed , etc all the process.
But to do this process for multiple rows at once, we use cursor, but i don't want to use cursor as i feel its too tedious to do.
Is there any other way , where i do process of multiple records at once without using cursor??
Help me, Thank You.
Oracle Forms Builder 6i.
Oracle9i Enterprise Edition Release 9.2.0.1.0 - ProductionAn Update statement certainly can update sets of data instead single row updates:
UPDATE Statement
if you can't do it in a single statement you can use bulk processing as well:
PLSQL 101
cheers -
SELECT n. row without using cursors
For example, I retrieved 100 rows after executing a SELECT statement but I want to list only 20th row. How can I do this without using cursors?
The general approach to getting a set of rows would be to do something like
SELECT *
FROM (SELECT a.*, rownum rn
FROM (<<query with ORDER BY clause>>) a
WHERE rownum <= <<max>>)
WHERE rn >= <<MIN>>Depending on the particular requirements, you could also do something like
SELECT *
FROM (SELECT a.*, RANK() OVER (<<ORDER BY clause>>) rnk
FROM <<table>> a
WHERE <<rest of statement>>)
WHERE rnk = 20Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
I'm using JDev 11.1.1.6 and when I type a value into an af:inputListOfValues component and hit either the enter key or the tab key it will replace the value I entered with the first item in the LOV result set. If enter a value and just click out of the af:inputListOfValues component it works correctly. If I use the popup and search for a value it works correctly as well. I have a programmatic view object which contains a single transient attribute (this is the view object which is used to create the list of value component from) and then I have another entity based view object which defines one of its attributes as a list of value attribute. I tried using an entity based view object to create the LOV from and everything works as expected so I'm not sure if this is a bug when using programmatic view objects or if I need more code in the VOImpl. Also, it seems that after the first time of the value being replaced by the first value in the result set that it will work correctly as well. Below are some of the important code snippets.
Also, it looks like it only doesn't work if the text entered in the af:inputListOfValues component would only have a single match returned in the result set. For instance given the result set in the code: Brad, Adam, Aaron, Fred, Charles, Charlie, Jimmy
If we enter Cha, the component works as expected
If we enter A, the component works as expected
If we enter Jimmy, the component does not work as expected and returns the first value of the result set ie. Brad
If we enter Fred, the component does not work as expected and returns the first value of the result set ie. Brad
I also verified that I get the same behavior in JDev 11.1.1.7
UsersVOImpl (Programmatic View Object with 1 transient attribute)
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import oracle.adf.share.logging.ADFLogger;
import oracle.jbo.JboException;
import oracle.jbo.server.ViewObjectImpl;
import oracle.jbo.server.ViewRowImpl;
import oracle.jbo.server.ViewRowSetImpl;
// --- File generated by Oracle ADF Business Components Design Time.
// --- Wed Sep 18 15:59:44 CDT 2013
// --- Custom code may be added to this class.
// --- Warning: Do not modify method signatures of generated methods.
public class UsersVOImpl extends ViewObjectImpl {
private static ADFLogger LOGGER = ADFLogger.createADFLogger(UsersVOImpl.class);
private long hitCount = 0;
* This is the default constructor (do not remove).
public UsersVOImpl () {
* executeQueryForCollection - overridden for custom java data source support.
protected void executeQueryForCollection (Object qc, Object[] params, int noUserParams) {
List<String> usersList = new ArrayList<String>();
usersList.add("Brad");
usersList.add("Adam");
usersList.add("Aaron");
usersList.add("Fred");
usersList.add("Charles");
usersList.add("Charlie");
usersList.add("Jimmy");
Iterator usersIterator = usersList.iterator();
setUserDataForCollection(qc, usersIterator);
hitCount = usersList.size();
super.executeQueryForCollection(qc, params, noUserParams);
} // end executeQueryForCollection
* hasNextForCollection - overridden for custom java data source support.
protected boolean hasNextForCollection (Object qc) {
Iterator usersListIterator = (Iterator)getUserDataForCollection(qc);
if (usersListIterator.hasNext()) {
return true;
} else {
setFetchCompleteForCollection(qc, true);
return false;
} // end if
} // end hasNextForCollection
* createRowFromResultSet - overridden for custom java data source support.
protected ViewRowImpl createRowFromResultSet (Object qc, ResultSet resultSet) {
Iterator usersListIterator = (Iterator)getUserDataForCollection(qc);
String user = (String)usersListIterator.next();
ViewRowImpl viewRowImpl = createNewRowForCollection(qc);
try {
populateAttributeForRow(viewRowImpl, 0, user.toString());
} catch (Exception e) {
LOGGER.severe("Error Initializing Data", e);
throw new JboException(e);
} // end try/catch
return viewRowImpl;
} // end createRowFromResultSet
* getQueryHitCount - overridden for custom java data source support.
public long getQueryHitCount (ViewRowSetImpl viewRowSet) {
return hitCount;
} // end getQueryHitCount
@Override
protected void create () {
getViewDef().setQuery(null);
getViewDef().setSelectClause(null);
setQuery(null);
} // end create
@Override
protected void releaseUserDataForCollection (Object qc, Object rs) {
Iterator usersListIterator = (Iterator)getUserDataForCollection(qc);
usersListIterator = null;
super.releaseUserDataForCollection(qc, rs);
} // end releaseUserDataForCollection
} // end class
<af:inputListOfValues id="userName" popupTitle="Search and Select: #{bindings.UserName.hints.label}" value="#{bindings.UserName.inputValue}"
label="#{bindings.UserName.hints.label}" model="#{bindings.UserName.listOfValuesModel}" required="#{bindings.UserName.hints.mandatory}"
columns="#{bindings.UserName.hints.displayWidth}" shortDesc="#{bindings.UserName.hints.tooltip}" autoSubmit="true"
searchDesc="#{bindings.UserName.hints.tooltip}"
simple="true">
<f:validator binding="#{bindings.UserName.validator}"/>
</af:inputListOfValues>I have found a solution to this issue. It seems that when using a programmatic view object which has a transient attribute as its primary key you need to override more methods in the ViewObjectImpl so that it knows how to locate the row related to the primary key when the view object records aren't in the cache. This is why it would work correctly sometimes but not all the time. Below are the additional methods you need to override. The logic you use in retrieveByKey would be on a view object by view object basis and would be different if you had a primary key which consisted of more than one attribute.
@Override
protected Row[] retrieveByKey (ViewRowSetImpl viewRowSetImpl, Key key, int i) {
return retrieveByKey(viewRowSetImpl, null, key, i, false);
@Override
protected Row[] retrieveByKey (ViewRowSetImpl viewRowSetImpl, String string, Key key, int i, boolean b) {
RowSetIterator usersRowSetIterator = this.createRowSet(null);
Row[] userRows = usersRowSetIterator.getFilteredRows("UserId", key.getAttribute(this.getAttributeIndexOf("UserId")));
usersRowSetIterator.closeRowSetIterator();
return userRows;
@Override
protected Row[] retrieveByKey (ViewRowSetImpl viewRowSetImpl, Key key, int i, boolean b) {
return retrieveByKey(viewRowSetImpl, null, key, i, b); -
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?
TunkHi, 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 -
How to return a resultset in a stored procedure without using Cursor
Dear all,
I need to return a resultset in a stored procedure.
I know I can return a Cursor.
But because there are many complicate logics I need to carry out,
so I can finish all the logic in a SINGLE SQL select statement, so I think it can't
use Cursor as return value.
Does anybody know other approaches? Please help.
Thanks!Some basic techniques that one can use in SQL. These are merely to illustrate (simplistically) different approaches.
> field3 = select count(*) from table2,table1 where table2.id = table1.id
This can be done via an analytical function (refer to the SQL Reference) or very simply, as an in-line select as follows:
SQL> select
2 o.object_name,
3 (select count(*) from user_objects u where u.object_type = o.object_type) as "ONE OF",
4 o.object_type
5 from user_objects o
6 where o.object_name = 'LISTFILES';
OBJECT_NAME ONE OF OBJECT_TYPE
LISTFILES 8 PROCEDURE
So LISTFILE is "one of 8" procedures. I would however rather so this via an analytic function as these are a lot more flexible. Note the WITH clause that allows "modularisation" of SQL - kind of like creating "sub-SQL results" in a single SQL statement:
SQL> with DATASET1 as(
2 select
3 object_name,
4 count(distinct object_name) over (partition by object_type) as TOTAL_TYPES,
5 object_type
6 from user_objects
7 ),
8 DATASET2 as(
9 select
10 name,
11 text as SOURCE_LINE,
12 line as LINE_NO,
13 count(line) over (partition by name) as TOTAL_LINES
14 from user_source
15 )
16 select
17 object_name,
18 '1 of '||total_types||' '||object_type as "TYPE",
19 source_line as "1st LINE",
20 total_lines as "TOTAL LINES"
21 from DATASET1 ds1,
22 DATASET2 ds2
23 where ds1.object_name = ds2.name
24 and ds1.object_name = 'LISTFILES'
25* and ds2.line_no = 1
SQL> /
OBJECT_NAME TYPE 1st LINE TOTAL LINES
LISTFILES 1 of 8 PROCEDURE procedure ListFiles( cDirectory in varchar2 ) 3
SQL>
SQL is quite powerful and analytical functions allows all kinds of aggregation processing per row, accessing the leading or lagging rows' data, etc.
You need to play around with this to get to grips with it and how to apply it. -
Incorrect result set with using isnull() function in IQ 16
Hi team,
We have IQ 16 on HP UX.
When we use isnull() function in where clause we get incorrect result set if we do not use column name in the result set.
In first select we get result with one row but in second one we get an empty result set.
select ID, dat_start, dat_end, dat_stop
from table_test
where ID=1105935925
and isnull(dat_stop,dat_start) <> dat_end
select ID
from table_test
where ID=1105935925
and isnull(dat_stop,dat_start) <> dat_end
It depends on number of row or volume of data in table, It is possible to use option Revert_To_V15_Optimizer to get the correct result.
Do you have any different idea how to solve it?
Thanks Milos.We have tested two versions:
Sybase IQ/16.0.0.653/131122/P/sp03/ITANIUM/HP-UXi 11.31/64bit/2013-11-22 01:49:18
SAP IQ/16.0.0.807/140507/P/sp08/ITANIUM/HP-UXi 11.31/64bit/2014-05-07 21:11:45
Both versions have given same mistake.
We have not opened any support case for this issue because it is data depended issue. It is not easy to simulate it as an example.
Do you think we should open a support case for it?
Miloš -
Can we do it without using cursor ?
I have two tables. I have to insert records from master to detail table. Detail table has two columns Record_ref and Record_seq as primary key and these two columns has to be generated.
It has to be inserted like this.
for every policy_refer there can be more than one approval_ref. For policy_ref 1 having approval_ref 1,2,3 data in Record_Ref and Record_seq to be generated like this.
Record_ref Record_seq
1 1
1 2
1 3
++++++++++++++++++++++++++++++++++++++++++++++++
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
++++++++++++++++++++++++++++++++++++++++++++++++
Two tables are as follows
SQL> desc monthly_dec
Name Null? Type
POLICY_REFER VARCHAR2(14)
APR_SUBSI VARCHAR2(14)
NAME_INSURED VARCHAR2(120)
NAME_INSURED1 VARCHAR2(120)
EXPIRY_POLICY DATE
APPROVAL_REF VARCHAR2(9)
EXPIRY_DATE DATE
APPROVED_AMT NUMBER(11)
BUYER_REF VARCHAR2(13)
BUYER_NAME VARCHAR2(120)
BYR_OR_BNK_REF VARCHAR2(20)
TOR VARCHAR2(14)
UW_PCY_REF VARCHAR2(14)
USER_CODE VARCHAR2(8)
UND_ID VARCHAR2(9)
CREATE_DATE DATE
DEC_MONTH VARCHAR2(10)
CLOSE_FLAG VARCHAR2(1)
CLOSE_DATE DATE
MD_APL_CHK CHAR(1)
MD_SUB_CHK CHAR(1)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
SQL> desc TMP_PORTAL_MONTHLY_DEC
Name Null? Type
POLICY_REFER VARCHAR2(14)
APR_SUBSI VARCHAR2(14)
NAME_INSURED VARCHAR2(120)
NAME_INSURED1 VARCHAR2(120)
EXPIRY_POLICY DATE
APPROVAL_REF VARCHAR2(9)
EXPIRY_DATE DATE
APPROVED_AMT NUMBER(11)
BUYER_REF VARCHAR2(13)
BUYER_NAME VARCHAR2(120)
BYR_OR_BNK_REF VARCHAR2(20)
TOR VARCHAR2(14)
UW_PCY_REF VARCHAR2(14)
USER_CODE VARCHAR2(8)
UND_ID VARCHAR2(9)
CREATE_DATE DATE
CLOSE_FLAG VARCHAR2(1)
CLOSE_DATE DATE
DEC_MONTH VARCHAR2(10)
MD_UND_POST_FLAG CHAR(1)
MD_UND_POST_DATE DATE
MD_MAIL_FLAG CHAR(1)
MD_MAIL_DATE DATE
MD_SENT_BY VARCHAR2(9)
CURRENCY_OF_CONTRACT VARCHAR2(12)
TOTAL_VAL_SHIPMENTS NUMBER(14,4)
EXCHANGE_RATE NUMBER(14,4)
TOT_OF_M30DAYS NUMBER(14,4)
FINAL_CURRENCY NUMBER(14,4)
DEC_PORTAL_CREAT_DATE DATE
COPY_FLAG VARCHAR2(3)
SAVE_SUBMIT_FLAG NUMBER(1)
USR_REF_CODE VARCHAR2(50)
RECORD_REF NOT NULL NUMBER(10)
RECORD_SEQ NOT NULL NUMBER(10)Here is the sample data. I hope it helps. Here Record_ref is same but record_seq is changing. All the other data will be taken from master table. Policy_refer is not 1. It can be anything and one policy_refer can have multiple approval_ref. See that approval_ref is changing as APR-00001,APR-00002,APR-00003.
<strong>CSTP-AUS-00001</strong> A.B.CORP NULL 18-10-2008 PM 10:38:49 APR-00001 18-10-2008 PM 10:38:49 2450000 BYR-UK -00001 HSBC BYR-UK -00001 CSTP-AUS-00001 160022 UND-00001 18-10-2008 PM 10:38:49 18-10-2008 PM 10:38:49 USD 2450000.0000 1.2450 2450000.0000 18-10-2008 PM 10:38:49 1 <strong>1</strong>
<strong>CSTP-AUS-00001</strong> A.B.CORP NULL 18-10-2008 PM 10:39:24 APR-00002 18-10-2008 PM 10:39:24 2450000 BYR-UK -00001 HSBC BYR-UK -00001 CSTP-AUS-00001 160022 UND-00001 18-10-2008 PM 10:39:24 18-10-2008 PM 10:39:24 USD 2450000.0000 1.2450 2450000.0000 18-10-2008 PM 10:39:24 1 <strong>2</strong>
<strong>CSTP-AUS-00001</strong> A.B.CORP NULL 18-10-2008 PM 10:39:51 APR-00003 18-10-2008 PM 10:39:51 2450000 BYR-UK -00001 HSBC BYR-UK -00001 CSTP-AUS-00001 160022 UND-00001 18-10-2008 PM 10:39:51 18-10-2008 PM 10:39:51 USD 2450000.0000 1.2450 2450000.0000 18-10-2008 PM 10:39:51 1 <strong>3</strong>
CSTP-AUS-00002 A.B.CORP NULL 18-10-2008 PM 10:53:10 APR-00004 18-10-2008 PM 10:53:10 2450000 BYR-UK -00001 HSBC BYR-UK -00001 CSTP-AUS-00001 160022 UND-00001 18-10-2008 PM 10:53:10 18-10-2008 PM 10:53:10 USD 2450000.0000 1.2450 2450000.0000 18-10-2008 PM 10:53:10 2 1
Edited by: aadi on Oct 19, 2008 1:25 AM
Edited by: aadi on Oct 19, 2008 1:26 AM -
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. -
Stored procedure call returns null result set when using temp table in sp!
Here's a really odd problem...
SQL Server stored procedure called sp_Test takes 1 input INT. Here is the code I call it with
cStmt = connection.prepareCall("{call sp_Test(?)}");
cStmt.setInt(1, 44);
cStmt.execute();
rs = cStmt.getResultSet();When the body of the stored proc is
CREATE PROCEDURE sp_Test(@i_NodeID INT)
AS
BEGIN
SELECT node_id FROM tbl_NavTree
END
GOthe query works and I get all node_id back in rs
BUT when the body of the stored proc is
CREATE PROCEDURE sp_Test(@i_NodeID INT)
AS
BEGIN
CREATE TABLE #Descendants(
descendant_id INT
SELECT node_id FROM tbl_NavTree
DROP TABLE #Descendants
END
GOThe rs comes back as NULL. Really really weird if you ask me. I also tried removing the DROP TABLE line just in case the SELECT had to be the last statement but still NULL.
Final note is that BOTH the above stored proc bodies work when executed within SQL Server query analyser.
Must be JDBC .. what can it be!??DROP TABLE #DescendantsMS SQL Server - right?
Then don't drop the table.
From the MS docs for "create table"
Local temporary tables are visible only in the current session;
A local temporary table created in a stored procedure is dropped automatically when the stored procedure completes. The table can be referenced by any nested stored procedures executed by the stored procedure that created the table. The table cannot be referenced by the process which called the stored procedure that created the table. -
How should i use the two results sets in one single report data region?
Hi frnz,
I have to create a report using the below condition...
Here my given data set query gives you the two result sets ,so how should i use that two result sets information in single report....when i accessing that data set query it will take the values off the first result set not for the second result set.
without using sub report and look up functionality..... if possible
is there any way to achieve this.....Please let me know..
Thanks!You cant get both resultsets in SSRS. SSRS dataset will only take the first resultset
you need to either create them as separate queries or merge them into a single resultset and return with ad additional hardcoded field which indicates resultset (ie resultset1,resultset2 etc)
Then inside SSRS report you can filter on the field to fetch individual resultsets at required places. While merging you need to make sure metadata of two resultsets are made consistent ie number of columns and correcponding column data types should be same.
In absence of required number of columns just put some placeholders using NULL
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Performance to fetch result set from stored procedure.
I read some of related threads, but couldn't find any good suggestions about the performance issue to fetch the result set from a stored procedure.
Here is my case:
I have a stored procedure which will return 2,030,000 rows. When I run the select part only in the dbartisan, it takes about 3 minutes, so I know it's not query problem. But when I call the stored procedure in DBArtisan in following way:
declare cr SYS_REFCURSOR;
firstname char(20);
lastname char(20);
street char(40);
city char(20);
STATE varchar2(2);
begin DISPLAY_ADDRESS(cr);
DBMS_OUTPUT.ENABLE(null);
LOOP
FETCH cr INTO firstname,lastname,street, city, state;
EXIT WHEN cr%NOTFOUND;
DBMS_OUTPUT.PUT_LINE( firstname||','|| lastname||','|| street||',' ||city||',' ||STATE);
END LOOP;
CLOSE cr;
end;
It will take about 100 minutes. When I used DBI fetchrow_array in perl code, it took about same amount of time. However, same stored procedure in sybase without using cursor, and same perl code, it only takes 12 minutes to display all results. We assume oracle has better performance. So what could be the problem here?
The perl code:
my $dbh = DBI->connect($databaseserver, $dbuser, $dbpassword,
{ 'AutoCommit' => 0,'RaiseError' => 1, 'PrintError' => 0 })
or die "couldn't connect to database: " . DBI->errstr;
open OUTPUTFILE, ">$temp_output_path";
my $rc;
my $sql="BEGIN DISPLAY_ADDRESS(:rc); END;";
my $sth = $dbh->prepare($sql) or die "Couldn't prepare statement: " . $dbh->errstr;
$sth->bind_param_inout(':rc', \$rc, 0, { ora_type=> ORA_RSET });
$sth->execute() or die "Couldn't execute statement: " . $sth->errstr;
while($address_info=$rc->fetchrow_arrayref()){
my ($firstname, $lastname, $street, $city, $STATE) = @$address_info;
print OUTPUTFILE $firstname."|".$lastname."|".$street."|".$city."|".$STATE;
$dbh->commit();
$dbh->disconnect();
close OUTPUTFILE;
Thanks!
rulinThanks for you reply!
1) The stored procedure has head
CREATE OR REPLACE PROCEDURE X_OWNER.DISPLAY_ADDRESS
cv_1 IN OUT SYS_REFCURSOR
AS
err_msg VARCHAR2(100);
BEGIN
--Adaptive Server has expanded all '*' elements in the following statement
OPEN cv_1 FOR
Select ...
commit;
EXCEPTION
WHEN OTHERS THEN
err_msg := SQLERRM;
dbms_output.put_line (err_msg);
ROLLBACK;
END;
If I only run select .. in DBArtisan, it display all 2030,000 rows in 3:44 minutes
2) But when call stored procedure, it will take 80-100 minutes .
3) The stored procedure is translated from sybase using migration tools, it's very simple, in sybase it just
CREATE PROCEDURE X_OWNER.DISPLAY_ADDRESS
AS
BEGIN
select ..
The select part is exact same.
4) The perl code is almost exact same, except the query sql:
sybase verson: my $sql ="exec DISPLAY_ADDRESS";
and no need bind the cursor parameter.
This is batch job, we create a file with all information, and ftp to clients everynight.
Thanks!
Rulin -
Labeling points on XY graph with numbers. Trying to use cursor names.
I have found some example vis in the NI Developers Zone that label the points using Cursor Name attribute. I have some success, but results are not consistent. I need up to 100 labels...is there a limit to the number of cursors? Is there a way to initialize 100 cursors without using Cursor Legend? Sometimes the cursors do not appear or do not move...they don't seem to be consistent. Any other ideas to solve this problem? Would it be possible to show the number of the point when the cursor is moved to that point. I am using LabView 6.0. windows 2000.
Thanks.
Liz> Problem: When trying to change cursor position programatically using
> attribute notes, the cursor position will not change.
>
> I found this in the knowledgeBase. Solution: Unlock the cursor.
> Cursor position attributes are read-only when the cursor is locked.
> Liz
> Still looking for answer of a way to initialize 100 cursors with
> Cursor legend.
>
If you want to do things programmatically, like set the cursor text to
match the X or Y value of the point, read the value, format the string
and write it to the name of the cursor.
If you want to init 100 cursors interactively, you can popup on the edge
of the cursor legend and show the index. The cursor legend is simply an
array of clusters of cursor info. Set the index to 99 and type in a
name, value or something else. This will allocate 100 cursors. I'm not
sure if that is what you meant.
Greg McKaskle -
Query result set ordered incorrectly
Hallo,
I have this problem.
I have a table (lisitab) with a list of codes, for example:
A0001
A0002
AD063
AY064
In my java class I run a query (select lisi_codi from lisitab order by lisi_codi) and I expect the following order:
A0001
A0002
AD063
AY064
but I have this result:
AD063
AD064
A0001
A0002
What is strange it's that if I execute the query in SQL*Plus or other tools (PLSQLDeveloper for example) it works fine! When run my JDeveloper application I have the bad ordered result set.
My DB is Oracle 8.1.7 on Windows2000(SP2). The DB language is set as AMERICAN_AMERICA.WE8DEC.
The client is set with NLS_LANG AMERICAN_AMERICA.WE8DEC and I'm using Oracle OCI JDBC Drivers 8.1.7 deployed with JDeveloper 3.2.
I presume there's a bug (a BIG BUG!!!) into JDBC Drivers.
How can I work without trusting in order by ?
Could anyone help me?
Thanks
G.Grimoldi
null<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Joaquin Sanchez Jimenez ([email protected]):
Hi:
Could you send table description and complete query?. What version of JDBC and database ...
J.<HR></BLOCKQUOTE>
The table (lisitab) is very simple:
lisi_codi varchar2(16) not null (PK)
lisi_desc varchar2(40)
The select is:
select lisi_codi from lisitab order by lisi_codi
I'm working on Oracle 8.1.7 on Windows 2000 and JDBC drivers are Oracle JDBC 8.1.7 deployed with Jdeveloper 3.2.
I also tried with an Oracle 8.1.7 DB with charset WE8ISO8859P1 and a client with the same charset, but the result is same: bad ordered result set!
Is there anybody at Oracle who could tell me why and how to resolve (or workaround) this tedious and dangerous problem?
Thanks
null -
Sending multiple rows to result set
Hi,
I want multiple rows to be returned from my pl/sql procedure without using cursor?can I do it? Is there any package for this?
also When I use cursor variable how do I capture that return values?
regards
raghFirst Question:
grin. One really big string and a custom parser.
Seriously... I read something about PL/SQL tables being supported in a late/future release... is that true? Do we still use a ref cursor, or can we pass VARRAYS somehow back to Java?
Third question:
Posted earlier by Mark Tomlinson:
This one does it all. Nothing JDeveloper specific here, all JDBC.
* This sample shows how to call a PL/SQL function that opens
* a cursor and get the cursor back as a Java ResultSet.
import java.sql.*;
import java.io.*;
// Importing the Oracle Jdbc driver package makes the code more
readable
import oracle.jdbc.driver.*;
public class retrefcur_samp
public static void main (String args [])
// throws SQLException
try
// Load the driver
DriverManager.registerDriver(new
oracle.jdbc.driver.OracleDriver());
// Connect to the database
// You can put a database name after the @ sign in the
connection URL.
Connection conn =
DriverManager.getConnection ("jdbc:oracle:oci8:@ora8tst",
"scott", "tiger");
// Create the stored procedure
init (conn);
// Prepare a PL/SQL call
CallableStatement call =
conn.prepareCall ("{ ? = call java_refcursor.job_listing
// Find out all the CLERKs person
call.registerOutParameter (1, OracleTypes.CURSOR);
call.setString (2, "*");
call.execute ();
OracleResultSet rset = (OracleResultSet)call.getObject (1);
// Dump the cursor
while (rset.next ()){
System.out.println (rset.getString ("JOB"));
rset.close();
call.close();
} catch(SQLException esql) {
System.out.println("Trouble in river city ");
System.out.println(esql.toString());
// Utility function to create the stored procedure
static void init (Connection conn)
throws SQLException
Statement stmt = conn.createStatement ();
stmt.execute ("create or replace package java_refcursor as "
+
" type myrctype is ref cursor return
EMP%ROWTYPE; " +
" function job_listing (j varchar2) return
myrctype; " +
"end java_refcursor;");
stmt.execute ("create or replace package body java_refcursor
as " +
" function job_listing (j varchar2) return
myrctype is " +
" rc myrctype; " +
" begin " +
" open rc for select * from emp; " +
" return rc; " +
" end; " +
"end java_refcursor;");
stmt.execute ("create or replace package java_ref_clean as "
+
" type myrctype is ref cursor; " +
" function cleanup (cc myrctype) return
number; " +
"end java_ref_clean;");
stmt.execute ("create or replace package body java_ref_clean
as " +
" function cleanup (cc myrctype) return number
is "+
" result number; " +
" begin " +
" close cc; " +
" end; " +
"end java_ref_clean;");
null
Maybe you are looking for
-
I count on using the Firefox restore session feature. But it's stopped working. For the past couple of days, it hasn't worked a single time. (I haven't changed anything on my PC.) It just suddenly stopped working. Now it gives me an error message tha
-
How do I publish a website in two languages?
Hi! I'm pretty new to IWeb, I'm trying to publish my website in Spanish, and also in English. How do I do this without duplicating the buttons in the navigation bar? Say I want a flag to be the switch button, and then when I go to the Welcome page in
-
Where can I get map updates for my NV-u44?
My friend gave me a NV-U44 gps. Where can I get map updates for it?
-
Including AR Credit Memos in Query
Hello SQL Experts: My customer wants to show quantity, sales dollar amount, and tax amount for each warehouse and customer group. I am using the INV1/RIN1 tables for the figures since they do not want to see taxes, freight, other expenses, etc. in t
-
CmRcService Delayed Start (Remote Control Service)
Anyone know why Microsoft set the CmRcService service for a delayed start and not automatic? After a reboot of the remote computer, it is taking a few moments to connect. I am assuming that was done for a reason. Before I change the service on all of