How to return Multiple ResultSets Using Callable Statement

hi everybody,
while i was working with callable statements i came across a problem of how to fetch Multiple Resultsets by means of Stored Procedures written for tables in Oracle.
If any one can help me, pls do help me with a detailed explanation, and if possible do get me a example source code too.
khumaar

I have a similar problem with oracle and jdbc:
I want to send a sql query like:
sqlQuery = "select n1, n2 from table1; select n1, n2
from table2"
I used a prepared statement, but when I call
.execute(sqlQuery)
oracle doesn't like this,
can someone help on this?Try putting a begin/end around it. Play with the syntax first in sqlplus.
You do realize that you MUST extract using the syntax for extracting multiple result sets correct? It will NOT work as one result set.

Similar Messages

  • How to return multiples values useing functions

    Hi to all,
    I am using functions to return multiple values of two rows or multiple rows.
    For example emp id = 100 and i need to return the value for this(empid) input and output of this first_name and salary.
    I am tried in this way below but got errors (ORA-00932: inconsistent datatypes: expected NUMBER got HR.EMP_TYPE)
    create or replace type emp_type as object(first_name varchar2(20),salary number);
    create or replace function f1(empid in number)
    return emp_type
    as
    emp_record emp_type;
    begin
    select first_name,salary into emp_record.first_name,emp_record.salary from employees where employee_id = empid ;
    return emp_record;
    end;
    select f1(100) from dual;

    Sql is Sql and plsql is plsql. Though we can almost use all the sql objects inside a plsql code but vice versa is not always possible. Since plsql is tightly integrated with sql , if you return a number/date/varchar2 datatype values from plsql code to sql code,there is nothing wrong .Sql acknowledges this return type and knows well about how to handle it .But plsql record is a plsql specific datatype ,oracle was not built keeping in mind the fact that people will be creating difference types of records in plsql .So if you return a plsql datatype into a sql statement (which is processed by a sql engine) ,you need to tell oracle that I have written a plsql code which is going to return a record type so that sql engine can interpret it well.
    So all you need to do is create record in sql (known as object in sql ),when you make one, the entry is going to be shown in user_types views. Now use it like any other data type. I assume that the forum link provided in the above post is the best one to understand.
    Thanks,
    Rahul

  • How to add multiple columns using select statement

    Hi friends
    i have two TABLES
    one table Contain only unique Agent code(23,45,56,88)
    second table contain same Agent Code,orderdate & sum(amount)
    now i want to add columns in table 1 according to date and update the amount in that column
    for example if i select start date 1st july 2014 and end date is 15 july 2014
    then i want result 
    select agentcode,amount as 01july2014,amount as 02nd july2014 up to 15th july
    Please HELP.....

    >> I have two TABLES <<
    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
    use ISO-8601 formats. You failed on this too!  Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on SQL forums. Ignorance is fine, but why do you have bad manners? The rules are posted at the front of the forum! 
    >> one [nameless, unknown] table Contain only unique Agent code(23, 45, 56, 88) <<
    You do not know the difference between a code and an identifier!
    CREATE TABLE Agents
    (agent_id INTEGER NOT NULL PRIMARY KEY); 
    >> second table contain same Agent Code, order_date & SUM(order_amount) <<
    Wrong again! The SUM() is an aggregate function and cannot be in a column. Tables have keys
    CREATE TABLE Orders
    (agent_id INTEGER NOT NULL
       REFERENCES Agents(agent_id),
     order_date DATE NOT NULL,
     order_amt DECIMAL (8,2) NOT NULL,
     PRIMARY KEY (agent_id, order_date));
    >> now I want to add columns in table 1 according to date and update the amount in that column <<
    NO! The running total is a computed column. We do not store them.
    >> for example if I select start date 1st July 2014 [sic: 2014-07 -01] and end date is 15 July 2014 [sic: 2014-07-15] <<
    If you have ever read a book on SQL, you would know the correct display format for dates! It is the only one in the ANSI/ISO Standards. 
    SELECT agent_id, order_date,
           SUM(order_amt) 
           OVER (PARTITION BY agent_id
                    ORDER BY order_date
                  ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)
           AS order_amt_runtot
      FROM Orders
     WHERE order_date BETWEEN '2014-07-01' AND '2014-07-15'; 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • How can I return multiple values using Oracle 9i Web Services ?

    Hi, Is it possible to return multiple parameters using WebServices in general ? And if yes, how do we do it using Oracle 9i WebServices ?
    At my client usually I call
    return_value = SoapClient.MehtodName(param1, param2, param3)
    If i need more than one return_value...how do we handle that ?
    Thanks,
    -Krishna

    Anyone has any ideas about this ?
    And also if i want a collection in one of the input parameters...how to do that ?
    Does Oracle WS have any such support ? Or we have devise our own way like sending it by separators or something like that ?
    Thanks,
    Krishna

  • How to retrieve multiple columns using "returning" in the Insert query.

    hi,
    wanted to know how to retrieve multiple columns using "returning" in the Insert Query.
    For retrieving one column we write the query as follows:
    Insert into TABLE values(1,2,3,4) returning COLUMN1 into PARAMETER
    But can we retrive multiple columns in the same query?
    am using oracle 10g and coding in .NET

    Hi,
    You can definetely get multiple values from a single query using the 'returning' clause.
    Eg : insert into emp (empno, ename, job, deptno) values (7324,'ADAM','MARKETING',30) returning ename, deptno into var1, var2; PN : var1 & var2 to be declared as varchar2 & number respectively.
    More insight into the 'RETURNING' clause in this link.
    http://www.samoratech.com/PLSQL/swArtPLSQLReturn.htm
    Regards,
    Bhanu.

  • Calling stored procedure and returning multiple resultsets

    Hello,
    Is it possible to create a procedure that return multiple result sets?
    e.g.
    procedure GetDataFromTables() is
    begin
    select * from table_one;
    select * from table_two;
    end GetDataFromTables;
    And I want to call this procedure that returns multiple resultsets (one for table_one and another for table_two)
    I have referred to the OCCI sample occiproc.cpp, but I am not sure how to handle multiple resultsets.
    Your help is highly appreciated.

    Thank You,
    Got the REF cursor in storedproc.cpp.
    But as it is documented, getCursor() gets the REF CURSOR value of an OUT parameter as a ResultSet.
    So, is it true that if I have to write a procedure that selects * from 50 tables (50 SQL statements) , I have to set 50 OUT parameters to get the result sets.?
    Is there any better way of doing this?
    e.g. in DB2, we can open multiple cursors in the procedure body and then get the result set one after another.
    CREATE PROCEDURE get_staging_data ()
    RESULT SETS 1 <no. of result sets>
    LANGUAGE SQL
    BEGIN ATOMIC
    DECLARE L_SQL varchar(5000);
    DECLARE c CURSOR WITH RETURN TO CLIENT FOR L_STMT;
    SET L_SQL = '';
    SET L_SQL = 'SELECT * FROM ';
    SET L_SQL = L_SQL || IN_Tab_Name ;
    SET L_SQL = L_SQL || ' WHERE VERIFY_FLAG=''S'' FOR READ ONLY OPTIMIZE FOR 2000 ROWS' ;
    PREPARE L_STMT FROM L_SQL;
    OPEN c; < can open multiple cursors in the prodedure body>
    END

  • Calling a procedure/function in CO using Callable Statement

    Hi,
    Please help me in understanding this:
    __method1__
    BEGIN
    :1 := Package.Function(
    param1 => :2"
    ,param2 => :3"
    ,param3 => :4"
    ,param4 => :5"
    END;
    method2
    BEGIN
    Package.Function(:1, :2, :3, :4, :5);"
    END;
    Whats the significance of using method1?
    I have seen the callable statements written as in method1 but, the parameters passed are not in order and not all params are passed.
    When i tried writing similar code, I got "Invalid Column Index" exception. Please let me know how to overcome this.
    Thanks

    Hi,
    You can call a function using Callable Statement as
    public String checkprimarycontact(String pri_loc_id,String org_id,String party_id)
    int p_location_id = 0;
    int p_org_id = 0;
    int p_party_id = 0;
    p_location_id = Integer.parseInt(pri_loc_id);
    p_org_id = Integer.parseInt(org_id);
    p_party_id = Integer.parseInt(party_id);
    String priflag = "";
    try
    Connection conn1 = getOADBTransaction().getJdbcConnection();
    CallableStatement cstmt1 = conn1.prepareCall("{? = call GET_PRIMARY_FUNCTION(?,?,?)}");
    cstmt1.registerOutParameter(1,Types.VARCHAR);
    cstmt1.setInt(2,p_location_id);
    cstmt1.setInt(3,p_org_id);
    cstmt1.setInt(4,p_party_id);
    cstmt1.execute();
    priflag = cstmt1.getString(1);
    catch(Exception e1)
    e1.printStackTrace();
    return priflag;
    Thanks,
    Gaurav

  • [UIX] How To: Return multiple values from a LOV

    Hi gang
    I've been receiving a number of queries via email on how to return multiple items from a LOV using UIX thanks to earlier posts of mine on OTN. I'm unfortunately aware my previous posts on this are not that clear thanks to the nature of the forums Q&A type approach. So I thought I'd write one clear post, and then direct any queries to it from now on to save me time.
    Following is my solution to this problem. Please note it's just one method of many in skinning a cat. It's my understanding via chatting to Oracle employees that LOVs are to be changed in a future release of JDeveloper to be more like Oracle Forms LOVs, so my skinning skills may be rather bloody & crude very soon (already?).
    I'll base my example on the hr schema supplied with the standard RDBMS install.
    Say we have an UIX input-form screen to modify an employees record. The employees record has a department_id field and a fk to the departments table. Our requirement is to build a LOV for the department_id field such that we can link the employees record to any department_id in the database. In turn we want the department_name shown on the employees input form, so this must be returned via the LOV too.
    To meet this requirement follow these steps:
    1) In your ADF BC model project, create 2 EOs for employees and departments.
    2) Also in your model, create 2 VOs for the same EOs.
    3) Open your employees VO and create a new attribute DepartmentName. Check “selected in query”. In expressions type “(SELECT dept.department_name FROM departments dept WHERE dept.department_id = employees.department_id)”. Check Updateable “always”.
    4) Create a new empty UIX page in your ViewController project called editEmployees.uix.
    5) From the data control palette, drag and drop EmployeesView1 as an input-form. Notice that the new field DepartmentName is also included in the input-form.
    6) As the DepartmentName will be populated either from querying existing employees records, or via the LOV, disable the field as the user should not have the ability to edit it.
    7) Select the DepartmentId field and delete it. In the UI Model window delete the DepartmentId binding.
    8) From the data controls palette, drag and drop the DepartmentId field as a messageLovInput onto your page. Note in your application navigator a new UIX page lovWindow0.uix (or similar) has been created for you.
    9) While the lovWindow0.uix is still in italics (before you save it), rename the file to departmentsLov.uix.
    10) Back in your editEmployees.uix page, your messageLovInput source will look like the following:
    <messageLovInput
        model="${bindings.DepartmentId}"
        id="${bindings.DepartmentId.path}"
        destination="lovWindow0.uix"/>Change it to be:
    <messageLovInput
        model="${bindings.DepartmentId}"
        id="DepartmentId"
        destination="departmentsLov.uix"
        partialRenderMode="multiple"
        partialTargets="_uixState DepartmentName"/>11) Also change your DepartmentName source to look like the following:
    <messageTextInput
        id=”DepartmentName”
        model="${bindings.DepartmentName}"
        columns="10"
        disabled="true"/>12) Open your departmentsLov.uix page.
    13) In the data control palette, drag and drop the DepartmentId field of the DepartmentView1 as a LovTable into the Results area on your page.
    14) Notice in the UI Model window that the 3 binding controls have been created for you, an iterator, a range and a binding for DepartmentId.
    15) Right click on the DepartmentsLovUIModel node in the UI Model window, then create binding, display, and finally attribute. The attribute binding editor will pop up. In the select-an-iterator drop down select the DepartmentsView1Iterator. Now select DepartmentName in the attribute list and then the ok button.
    16) Note in the UI Model you now have a new binding called DCDefaultControl. Select this, and in the property palette change the Id to DepartmentName.
    17) View the LOV page’s source, and change the lovUpdate event as follows:
    <event name="lovSelect">
        <compound>
            <set value="${bindings.DepartmentId.inputValue}" target="${sessionScope}" property="MyAppDepartmentId" />
            <set value="${bindings.DepartmentName.inputValue}" target="${sessionScope}" property="MyAppDepartmentName" />
        </compound>
    </event>18) Return to editEmployees.uix source, and modify the lovUpdate event to look as follows:
    <event name="lovUpdate">
        <compound>
            <set value="${sessionScope.MyAppDepartmentId}" target="${bindings.DepartmentId}" property="inputValue"/>
            <set value="${sessionScope.MyAppDepartmentName}" target="${bindings.DepartmentName}" property="inputValue"/>     
        </compound>
    </event>That’s it. Now when you select a value in your LOV, it will return 2 (multiple!) values.
    A couple things to note:
    1) In the messageLovInput id field we don’t use the “.path” notation. This is mechanism for returning 1 value from the LOV and is useless for us.
    2) Again in the messageLovInput we supply “_uixState” as an entry in the partialTargets.
    3) We are relying on partial-page-refresh functionality to update multiple items on the screen.
    I’m not going to take the time out to explain these 3 points, but it’s worthwhile you learning more about them, especially the last 2, as a separate exercise.
    One other useful thing to do is, in your messageLovInput, include as a last entry in the partialTargets list “MessageBox”. In turn locate the messageBox control on your page (if any), and supply an id=”MessageBox”. This will allow the LOV to place any errors raised in the MessageBox and show them to the user.
    I hope this works for you :)
    Cheers,
    CM.

    Thanks Chris,
    It took me some time to find the information I needed, how to use return multiple values from a LOV popup window, then I found your post and all problems were solved. Its working perfectly, well, almost perfectly.
    Im always fighting with ADF-UIX, it never does the thing that I expect it to do, I guess its because I have a hard time letting go of the total control you have as a developer and let the framework take care of a few things.
    Anyway, I'm using your example to fill 5 fields at once, one of the fields being a messageChoice (a list with countries) with a LOV to a lookup table (id , country).
    I return the countryId from the popup LOV window, that works great, but it doesn't set the correct value in my messageChoice . I think its because its using the CountryId for the listbox index.
    So how can I select the correct value inside my messageChoice? Come to think of it, I dont realy think its LOV related...
    Can someone help me out out here?
    Kind regards
    Ido

  • How to get multiple records using fn-bea:execute-sql()

    Hi,
    I created Proxy service(ALSB3.0) to get records from DB table. I have used Xquery function(fn-bea:execute-sql()). Using simple SQL query I got single record, but my table having multiple records. Please suggest how to get multiple records using fn-bea:execute-sql() and how to assign them in ALSB variable.
    Regards,
    Nagaraju
    Edited by: user10373980 on Sep 29, 2008 6:11 AM

    Hi,
    Am facing the same issue stated above that I couldnt get all the records in the table that am querying in the Proxyservice.
    For example:
    fn-bea:execute-sql('EsbDataSource', 'student', 'select Name from StudentList' ) is the query that am using to fetch the records from the table called StudentList which contains more than one records like
    Id Name
    01 XXX
    02 YYY
    03 ZZZ
    I tried to assign the result of the above query in a variable and while trying to log the variable, I can see the below
    <student>
    <Name>XXX</Name>
    </student>
    I want to have all the records from my table in xml format but it's not coming up. I get the value only from the first row of my table.
    Please suggest.
    regards,
    Venkat

  • How to upload multiple files using wicket

    Hai,
    how to upload multiple files using wicket at a single browse.
    any suggestion?
    Thanks in advance

    You have to do this your self by either (as vinod said) using a different component (not present in adf) or implementing this:
    1) allow the user to select multiple filenames (somehow)
    2) zip them together
    3) upload the zip
    4) unpack the zip on the server
    5) work with the files
    Timo

  • How to generate multiple sheets using xml publisher

    Hi,
    how to generate multiple sheets using xml publisher.
    Thanks,
    Nur

    http://lmgtfy.com/?q=how+to+generate+multiple+sheets+using+xml+publisher

  • 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.

  • How to use Callable statements.

    Hi.
    I'm just new in using JSP. I just want to ask how to call stored procedures (ex. from SQL Server) using the Callable statements. A sample code will be very helpful......
    Ex. I have these parameters for my stored proc:
    name = "sentiments"; //value will always vary
    add = "NJ"; //value will always vary
    stored proc name is => usp_updateFile
    Thank you very much for your time.

    See http://developer.java.sun.com/developer/onlineTraining/Database/JDBC20Intro/JDBC20.html#JDBC2013_4

  • Statement closed when using callable statements with oracle xe

    hi all, i've got this problem with oracle express edition 10g. I am using also oc4j v10.1.2.0.2. When working with a normal oracle database it was working fine (i think the code was the same, it's some time since i last tried, but you can see the code is very simple).
    So i just create a callable statement like this:
    CallableStatement cs = con.prepareCall(sentencia.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.HOLD_CURSORS_OVER_COMMIT);
    and then when trying to access the statement to register an out parameter like this
    cs.registerOutParameter(1, parámetros[0].getTipo());
    it gives this error:
    java.sql.SQLException: Statement was closed
    It's puzzling me because, as i said before, i think the same code was working ok with a normal oracle database.
    Any idea what can it be?
    cheers

    Ah okay, sorry I've re-read your post.
    I believe you need to create a clob object that encapsulates your xml file.
    I've never done this but I would image it involves creating a class that implements the clob interface and passing an instantiation of this class to the callablestatement.
    Let me know how you get on.

  • How to create updateable resultset using sql with "order by"

    Dear all,
    I'm using the Derby database to hold a table of stock prices. After the table is populated, I want to do some calculations and store the result in a column.
    I get the resultset using the following code
    Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = stmt.executeQuery(select history_id, value, days from history where ticker = '" + ticker + "' order by value_date"); {code} When I then try to update the "days" field, I get an SQLException telling me that the resultset is not updatable. However, if I remove the "order by" clause, I am able to update the data, but then my algorithm does not work as I need to traverse the data in a specific order. The quesion is: how do I create an updatable resultset using a sql-statement with an order by clause? Kind regards Karl Martin Lund                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    jschell wrote:
    Seems rather obvious to me that the exception specifically tells you that you can't do that.OP: I would guess it's because ORDER BY forces the database to read all the result rows into a temporary area, sort them, and then return them from this temporary area, as opposed to streaming the results. The extra step probably makes updateable result sets more difficult (or maybe not possible), so they opted not to do it.

Maybe you are looking for

  • DTP in BW7.0

    Hi guys With discussion with one of my colleagues...we came upon question--Whats the benefit or thought of using DTP in BI7.0 when compared to Infopackage in BW3.X.... I said...DTP in BI7.0 gives many options like...Direct Acess DTP..Error stack DTP.

  • Motion Project does not look good in FCP

    I am using FCP 5.0 and Motion2. I made a lower third title graphic in Motion. When I embed the clips back into FCP they look pixalated. They do not look as good as they did originally. Does anyone have a solution?

  • Send email

    Hi all I am trying to send email through forms I am using the following command at when button pressed But i couldn't see that email is going any help please Host('rwrun60.exe c:/example.rdf oracle/oracle@oracle destype=mail desname= [email protected

  • HT201263 my iphone doesn't activate due to activation sever temporarily unavailable, what do i do?

    hi, i recently upgrade my iphone, and now i can't ativate it because it keep on saying taht the activation sever is temporarily unavailable and once on i tune 11. it doesn't restart and  keep on asking me to restart later or contact apple customer se

  • When can I order!?

    So I live in Stratford and have been hoping for BT Infinity to come to my area forever and a day. The dates keep being pushed back (I believe initially it was March 2011, then June 2011, September 2011, December 2011, March 2012 and now 30 June 2012.