Update Query with Results From another Procedure

I am not sure if you can do this or what the proper format of the command might look like.
I have a stored procedure which insert records into a database. I want to insert the records which are returned by calling another procedure. This other procedure returns a cursor object to a variable named o_rows. Can this be done using Oracle 8i?
Insert into MyTable
MyStoredProcedure(oRows);

You have a couple of options.
1) You can turn your stored procedure into a pipelined table function. This would allow you to do something like
INSERT INTO myTable
  SELECT *
    FROM TABLE( myStoredProcedure() );I don't believe that pipelined table functions were available in 8i, however.
2) The other option would be to fetch rows from the cursor and insert those into your table. Something like
LOOP
  FETCH oRows INTO col1, col2, col3, col4, ...
  INSERT INTO myTable( <<column list>> )
    VALUES( col1, col2, col3, col4 );Note that for simplicity I am omitting the declarations of the local variables col1, col2, etc. and the check to see whether the cursor was exhausted.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC

Similar Messages

  • Issue with Results from Another Query (Error on Null value)

    Hi All,
    We have a WebI report using "Result from Another Query" option of BO XI R3.1. The report was running fine till recently the dimension object using result from another query had a null value. Report suddenly throwed error as the query filters are invalid.
    Is there a way to make this filter optional if no data/null value is there ? Because we need those null values in report as well.
    Thank you for your time.
    Thanks & Regards
    LN

    Hi Vivek,
    It was not directly solved but I applied alternate logic to over come the issue.
    Here's what I did to overcome:
    I used a sub query in place of the whole result from another query.
    For Ex:
    Dim1 inlist result from another query1
    I made it as
    Dim1 inlist (Dim0)
    where Conditions.
    Here Dim0 is the object which we use for Result from another query and Conditions will be the necessary filter conditions to arrive proper Dim0.  Make sure proper context is formed for the sub query.
    Even though it resolved my problem, It introduces an new issue. It causes increase in query run time when huge set of data is returned from sub query.
    Please let me know if i haven't explained clearly.
    Hi Aris_BO,
    Sorry for not responding earlier.  The logic would probably make more queries null & not null. Thats why I was not advised to use it.
    Thanks
    LN

  • Query on results from another query

    Post Author: Duncan1980
    CA Forum: Crystal Reports
    Is it possible to query on the results from another query.  I have a query that produces a list of document numbers.  I want to use the output from that query as the filter criteria in a another query in the same Universe. 
    The output from the first query can be as much as 2000, so it would be very time consuming to cut and paste these into a filter.
    Both reports are built, but can not figure out how to link the first report output to the filtering criteria on the second report.  I
    I am using business objects XI release 2 web intelligence 11.5.3.417 enterprise.

    Hi Vivek,
    It was not directly solved but I applied alternate logic to over come the issue.
    Here's what I did to overcome:
    I used a sub query in place of the whole result from another query.
    For Ex:
    Dim1 inlist result from another query1
    I made it as
    Dim1 inlist (Dim0)
    where Conditions.
    Here Dim0 is the object which we use for Result from another query and Conditions will be the necessary filter conditions to arrive proper Dim0.  Make sure proper context is formed for the sub query.
    Even though it resolved my problem, It introduces an new issue. It causes increase in query run time when huge set of data is returned from sub query.
    Please let me know if i haven't explained clearly.
    Hi Aris_BO,
    Sorry for not responding earlier.  The logic would probably make more queries null & not null. Thats why I was not advised to use it.
    Thanks
    LN

  • Calling a procedure (with refcursor) from another procedure

    I have a procedure that returns refcursor (it's used by a Java application).
    I am able to run the proc via SQLPlus like below:
    var a refcursor;
    exec MY_PKG.get_content_prc(:a);
    print a;
    I would like to use/call this proc from another procedure and I am not able to, since arg is refcursor.
    create or replace procedure p
    is
    v refcursor;
    begin
    MY_PKG.get_content_prc(:v);
    end;
    Error I get is:
    SQL> show err
    Errors for PROCEDURE P2:
    LINE/COL ERROR
    4/3 PL/SQL: Item ignored
    4/7 PLS-00201: identifier 'CURSOR' must be declared
    6/5 PL/SQL: Statement ignored
    6/57 PLS-00320: the declaration of the type of this expression is
    incomplete or malformed
    Hope someone can direct me.
    Regards

    Because you are not using the right syntax.
    You need to do something like this
    LOOP
       /* Fetch from cursor variable. */
       FETCH emp_cv INTO emp_rec;
       EXIT WHEN emp_cv%NOTFOUND; -- exit when last row is fetched
       -- process data record
    END LOOP;This is from the PL/SQL User's Guide and Reference.
    I would recommend reading this fine manual, it is faster than guessing.

  • Query with Tables from another Database

    Hi.
    I have a problem with a Query that executes a stored procedure that inserts data in a Table from another DataBase. The problem is when I try to execute a Query with the data related of that table using the user parameters of SBO ('[%0]'....'[%3]'). I use the following parameters for reference to the Table:
    "....FROM [-BDName-].[dbo].[-TableName-] T1..... "
    Any suggestions? Thanks a lot....
    (Suggestions in English or Spanish)

    None

  • Update table with select from another table

    Hallo,
    I'd like to update table b with codes from a mapping table a.
    a has:
    town_id, town_code, town_name
    b has town_code, town_id, town_population, town_zip_code,...
    Table a has all the details - town_id, town_code and town_name and acts as the mapping between town_id and town_code
    In table b, town_code is null. I want to update the column b.town_code with town_code from table a where a.town_id = b.town_id.
    How will the update query look like?
    I tried
    UPDATE B SET town_code = (SELECT A.town_code FROM A,B WHERE A.town_id=B.town_id)
    and I get the error 'single-row subquery returns more than one row'
    Will appreciate your assistance

    This is what I did.
    First, I created and populated the TOWN_INFO table:
    CREATE TABLE "TOWN_INFO"
    (     "TOWN_ID" NUMBER,
         "TOWN_CODE" NUMBER,
         "E_MAIL" CHAR(15 BYTE)
    Table Created.
    insert all
    into TOWN_INFO (TOWN_ID, E_MAIL) values (3024,'[email protected]')
    into TOWN_INFO (TOWN_ID, E_MAIL) values (3040,'[email protected]')
    into TOWN_INFO (TOWN_ID, E_MAIL) values (3052,'[email protected]')
    into TOWN_INFO (TOWN_ID, E_MAIL) values (3065,'[email protected]')
    into TOWN_INFO (TOWN_ID, E_MAIL) values (3066,'[email protected]')
    select * from dual
    5 rows created.
    The following creates and populates the mapping table:
    CREATE TABLE "TOWN_MAPP"
    (     "TOWN_CODE" NUMBER,
         "TOWN_ID" VARCHAR2(255 BYTE),
         "TOWN_NAME" CHAR(6 BYTE)
    insert all
    into TOWN_MAPP (TOWN_ID,TOWN_CODE, TOWN_NAME) values (3024,'1001','TOWN_1')
    into TOWN_MAPP (TOWN_ID,TOWN_CODE, TOWN_NAME) values (3040,'1003','TOWN_3')
    into TOWN_MAPP (TOWN_ID,TOWN_CODE, TOWN_NAME) values (3052,'1002','TOWN_2')
    into TOWN_MAPP (TOWN_ID,TOWN_CODE, TOWN_NAME) values (3065,'1004','TOWN_4')
    into TOWN_MAPP (TOWN_ID,TOWN_CODE, TOWN_NAME) values (3066,'1006','TOWN_6')
    into TOWN_MAPP (TOWN_ID,TOWN_CODE, TOWN_NAME) values (3088,'1007','TOWN_7')
    into TOWN_MAPP (TOWN_ID,TOWN_CODE, TOWN_NAME) values (3020,'1009','TOWN_9')
    select * from dual
    7 rows created.
    And now the update query:
    UPDATE TOWN_INFO
    SET TOWN_CODE=(SELECT B.TOWN_CODE FROM TOWN_MAPP B, TOWN_INFO C
    WHERE B.TOWN_ID=B.TOWN_ID)
    SET TOWN_CODE=(SELECT B.TOWN_CODE FROM TOWN_MAPP B, TOWN_INFO C
    ERROR at line 2:
    ORA-01427: single-row subquery returns more than one row
    Thanx in advance
    Edited by: user9954260 on Apr 13, 2010 7:40 AM
    Edited by: user9954260 on Apr 13, 2010 7:44 AM

  • How to run an update query on results from a spreadsheet

    Hey there,
    I am new to this kinda thing.
    I received a spreadsheet that has 2 tabs, 1 is called SQL Results, and has a ton of data. 1 is called SQL Statement and has a select statement in the first cell.
    I was told to run an update query using the spreadsheet, and was given this:
    = CONCATENATE("Update CARDMEMBERISSUE set CURRSTATUSCD = 'ACT', DATELASTMAINT = sysdate where AGREENBR = ",A2," and MEMBERNBR = ",B2," and ISSUENBR = ",C2,";")
    = CONCATENATE("Insert into CARDMEMBERISSUEHIST (AGREENBR, MEMBERNBR, ISSUENBR, EFFDATETIME, CARDSTATCD, STATREASON, DATELASTMAINT, DATESENT) values (",A2,",",B2,",",C2,",sysdate,'ACT',null,sysdate,null);"
    I am not sure what to do or how to run this.
    This is the what the lines in the spreadsheet look like, including column header, A1 is blank.
    A B C etc
         AGREE NBR      MEMBERNBR ISSUE NBR CURRSTATUSCD PREFIX CARD NBR AGREETYPCD OWNER PERS NBR     EXT CARD      ISSUE DATE     
    2     12          1     44     ISS g     22 22 19/10/2011

    The =concatenate bits are Excel formulae. Assuming they correctly written, they will generate a set of individual sql statements. The first concaenatewill generate a set of update statements against the CardMemberIssue table, and the seond will generate a set of insert statement to the CardMemberIssueHist table.
    You should be able to just paste the generated statements into whatever tool you are using to run sql to execute them. Before you do that though, make sure that you issue:
    alter session set cursor_sharing=force;before pasting anything in.
    john

  • Update Nulls With Value from Another Row

    Good Morning,
    I word for a car manufacturer. I am pulling an excel spreadsheet into SQL 2012.The spreadsheet lists one line for each dealer, each carline. So if there are 6 carlines and 65 dealers there will be 390 lines. when the spreadsheet gets to me it looks like
    this:
    Dealer          
    Carline         District         Data         Data         Data
    East Side Craworld Model1
    1 0
    0
    Model2
    1 0 0
    Model3
    1 0
    0 0
    So the Dealer is only listed once. When I pull this into SQL the blank lines are nulls and I want them to be the Dealer name in there. How can I accomplish this with an update.
    Just one thing more. When I programmed in access, I would loop through a table and set a variaiable =Dealer name and not change the variable until the next not null row and then make that the new variable all the while making nulls=the variable. Is there
    a way to accomplish that here.

    The only issue is this file will eventually be a feed and an ftp agent will grab the feed place it somewhere and and there will be a stored package to import it.
    Can I do an update on a null field with the field from the previous record, or am I dealing witht he ordering thing again. I found this code. Will it work?
    select Date
    , GroupId
    , case
    when Comment is not null then Comment
    else
    select Comment
    from YourTable yt2
    where yt1.GroupId = yt2.GroupId
    and yt2.Comment is not null
    and yt2.Date < yt1.Date
    and not exists
    select *
    from YourTable yt3
    where yt1.GroupId = yt2.GroupId
    and yt2.Comment is not null
    and yt3.Date < yt2.Date and yt2.Date < yt1.Date
    ) end as Comment
    from YourTable yt1

  • Combine query, result from another query on SAP BI query Universe?

    Hello all,
    We are using SAP BI queries as datasource for our universes. Is the combined query option disabled for webi reports written on such universes?
    result from another query - is this option active for such webi reports? I see both these options greyed out so wanted to check.
    One last thing what is really difference between subquery and results from another query? subquery - you can use filters from that one data provider only right? or can you use a different data provider/report in sub query?
    Thanks a lot for all the replies.

    Hi,
    in BO 3.1 Combined query and result from another query options are not available in webi report on OLAP Universes  (SAP BW Universe.)
    Thanks,
    Amit

  • Results from another Query - not available

    HI,
    My environment is Business Objects XI 3.1 SP2 Edge series , i have  below quereis with web Intelligence Reports
    1. not available  the functions/options  Results from another Query(Any) or Results from another Query(ALL) at Query Level.
    2. not getting list of Values for pronpt until i refresh values for prompt?
    Please suggest me is there any fix packs available for the same to availle that functionality.
    Best Regards,
    Reddeppa K

    not getting list of Values for pronpt until i refresh values for prompt?
    There is option called  "Automatic refresh before use"  for the object properties available in the universe designer.
    Please check the box for the object you are using for populating the list of values and export the universe.
    not available the functions/options Results from another Query(Any) or Results from another Query(ALL) at Query Level.
    There is a limitation for the query on query functionality that the both the queries can-not be from the OLAP universe.
    I guess the query which needs to be filtered should be built on universe from the relational data base.
    Regards,
    Rohit

  • Can we use Result from another query in Webi using Bex uery universe?

    Hi,
    Can we use Result from another query filter option in Webi to create a report using a Bex Query universe?
    I need to create a report using two universes, one is Bex Query Universe and the other is Orcle universe. I have two queries, one is using Oracle universe; the other using Bex Query universe. I need to pass the Oracle data from the Oracle query to the Bex Query query to get the matched data from SAP Bex query.
    I used Result from another query in the query filter panel for the query using Bex query universe. But I got an error saying that 'A filter contains a wrong value. you cannot run this query. (Error: WIS 00007). The data used in the filter on both sides are the same. they are char.
    I have tested by using two queries from the same Bex query universe to see if the Result from another query filter option works. And I got the same error.
    Has anyone run into the same issue and if this is possible and what should be the solution?
    Thanks in advance!
    Edited by: BO_Haiyan on Oct 6, 2010 3:47 PM

    In that situation:
    Create two queries : Oracle and BW query.
    @ Report:
    As you have to see result set from both the Dataproviders, correct? To achieve thise one must have common dimension objects to merge them at report and use Objects those are coming from both queries to use them in single Table/Report.
    Unless you don't use Merge Dimensions, you don't get a chane to use both queries objects in single Table/Report. (It will give tooltip saying: You can't drop here -- Incompatable Objects)
    In case, if you don't have common dimensions, change object definitions to Detail objects, for those required.
    Hope it helps you.
    Thank You!!

  • Unicode String Issue while Using Results from Another Query

    Hi All,
    In a webi report i have 2 queries say Sales Out and Investment. I need to have only those chains which are in Investement in Sales Out.
    So in Sales Out query i am using the option Results from another Query. The Chain values are in Unicode format.
    Though in universe i have Set Parameter Unicode_String ='Yes', this does not get applied when using option Results from another Query.
    Is there any solution to resolve this problem.
    Thanks
    Madhura

    leonhardtk wrote:
    I need to take values from the column of one table that meets certain critera, and create inserts into another table that includes this data.
    For example...
    {code}
    select emp_last_name from emp where emp_first_name like 'B%';
    Duncan
    Fitzgerald
    Johnson
    Smith
    {code}
    I then want to insert these values into another table:
    {code}
    insert into My_table values (
    sequence.nextval,99,99,[last_name]);
    {code}
    In the example above, I need it to insert a new row into My_table for where the "last_name" is each of the names from the select statement above (Duncan, Fitzgerald,Johnson,Smith).
    Based on other similar forum questions it looks like I should be doing something like:
    {code}
    INSERT INTO MY_TABLE
    (SELECT sequence.nextval,
                    99,
                    99,
                   (select EMP_LAST_NAME
                    FROM EMP
                    WHERE EMP_FIRST_NAME LIKE 'B%')
    {code}
    But this (obviously) doesn't work!
    Appreciate any assistance on this!
    KSL.
    Hi,
    Created this test data
    create table plch_test (name varchar2(50));
    insert into plch_test values('AKSHAY');
    insert into plch_test values('RAHUL');
    insert into plch_test values('APARNA');
    output
    1    AKSHAY
    2    RAHUL
    3    APARNA
    created another destnation table(in your case "my table")
    create table plch_test_1 (id number,name varchar2(50));
    created another sequence to generate employee ids
    create sequence test_seq;
    Now populated the desination table
    insert into plch_test_1(select test_seq.nextval,name from plch_test);
    verify the destination table
    select * from plch_test_1
    1    AKSHAY
    2    RAHUL
    3    APARNA
    Hope this helps
    Regards,
    Achyut Kotekal

  • Add a new employee - Connection is busy with results for another command

    Hi all,
    I try to add a new employee in my SAP Business One system, but I get an error message like that : [Microsoft][SQL Native Client] Connection is busy with results for another command * (HEM5) (HEM5)
    So I try to see if I get the same message when I update an employee, and I don't get this message.
    Do you have an idea, why I get this error message when I add a new employee ?
    Message was edited by:
            Marc Riar

    Hello,
    I am afraid there maybe two users / workstations using the same user code and one of them is creating (add) and other is update. Try to ask the users/wrokstations.
    Another way out is try to run this query :
    select * from HEM5
    Rgds,
    JM
    http://groups.yahoo.com/group/SBO_Knowledge_Village
    [email protected]

  • How to call one procedure from another procedure

    Hi all,
    Could anyone give me clue how to call a procedure contains out parameters
    from another procedure.
    I had following procedures.
    1)
    create or replace procedure INS_PUR_ORDER
    p_poamt in number,
    p_podate in date,
    p_poid out number
    is
    begin
    select pkseq.nextval into p_poid from dual;
    insert into pur_order(poamt,podate,poid)
    values (p_poamt,p_podate,p_poid);
    end;
    2)
    create or replace procedure INS_PUR_ORDER_DETAIL
    p_pounits in number,
    p_poddate in date,
    p_poid in number)
    is
    begin
    Insert into pur_order_detail(podid,pounits,poddate,poid)
    values(pdseq.nextval,p_pounits,p_poddate,p_poid);
    end;
    I need to write a 3rd procedure which calls above two procedures.
    like
    call first procedure ,basing on the return value
    i.e if p_poid != 0 then
    we need to call second procedure
    in the loop.
    thanks in advance.
    rampa.

    Not sure what are you doing, you can not assign cursor to another cursor, may be you are looking for this?
    SQL> create or replace procedure proc1 ( result out sys_refcursor)
      2  is
      3  
      4  begin
      5     open result for
      6       select 'HELLO WORLD' from dual ;
      7  end proc1 ;
      8  /
    Procedure created.
    Elapsed: 00:00:00.01
    SQL> create or replace procedure proc2
      2  is
      3     l_cursor sys_refcursor ;
      4  begin
      5     l_cursor := proc1 ;
      6   
      7  
      8     open l_cursor;
      9     fetch l_cursor into l_text;
    10     dbms_output.put_line(l_text);
    11     close l_cursor;
    12  
    13  
    14  end proc2 ;
    15  /
    Warning: Procedure created with compilation errors.
    Elapsed: 00:00:00.01
    SQL> show error;
    Errors for PROCEDURE PROC2:
    LINE/COL ERROR
    5/4      PL/SQL: Statement ignored
    5/16     PLS-00306: wrong number or types of arguments
             in call to 'PROC1'
    6/4      PLS-00201: identifier 'L_TEXT' must be
             declared
    6/4      PL/SQL: Statement ignored
    8/4      PLS-00382: expression is of wrong type
    8/4      PL/SQL: SQL Statement ignored
    9/4      PL/SQL: SQL Statement ignored
    9/24     PLS-00201: identifier 'L_TEXT' must be
             declared
    10/4     PL/SQL: Statement ignored
    10/25    PLS-00201: identifier 'L_TEXT' must be
             declared
    ---- this is the correct waySQL>ed
      1  create or replace procedure proc2
      2  is
      3     l_cursor sys_refcursor ;
      4     l_text varchar2(100);
      5  begin
    ---- procedure call
      6     proc1(l_cursor); 
    7    -- open l_cursor;
      8     fetch l_cursor into l_text;
      9     dbms_output.put_line(l_text);
    10     close l_cursor;
    11* end proc2 ;
    SQL> /
    Procedure created.
    Elapsed: 00:00:00.01
    SQL> set serveroutput on
    SQL> execute proc2;
    HELLO WORLD
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.00
    SQL>

  • Update query with CL_SQL_STATEMENT class

    Hi all,
    I'm trying to execute an update query with ADBC classes in order to modify two parameters (n_doc and processed) from a row with the following instructions:
          l_con_ref = cl_sql_connection=>get_connection( 'DB_7879' ).
          l_stmt_ref = l_con_ref->create_statement( ).
         CONCATENATE 'update' gv_table ' set n_doc= ? processed = ''X'' where id_ordn = ? '  INTO l_stmt SEPARATED BY space.
          GET REFERENCE OF materialdocument INTO l_dref.
          l_stmt_ref->set_param( l_dref ).
          GET REFERENCE OF ps_zmm_mov-id_ordn INTO l_dref.
          l_stmt_ref->set_param( l_dref ).
          l_stmt_ref->execute_update( l_stmt ).
    However, I got the error ORA-0933: SQL command not properly ended. I guess this error occurs because I am trying to update two parameters with a single query since using the following CONCATENATE instruction
         CONCATENATE 'update' gv_table ' set n_doc= ? where id_ordn = ? '  INTO l_stmt SEPARATED BY space.
    results ok.
    Does anybody know if it is possible to modify two parameters with only one update query with ADBC classes?
    Thank you in advance!

    Hi Suhas,
    Based on Oracle, I see it conforms almost completely ISO/IEC 9075 ([Oracle and Standard SQL|http://download.oracle.com/docs/cd/B10501_01/server.920/a96540/ap_standard_sql.htm#10293])
    UPDATE seems to conform completely [UPDATE SET clause|http://download.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_108a.htm#2087215]
    So using a comma to separate columns is true for every SQL language that conforms ISO/IEC 9075
    Sandra
    PS: of course SAP's "Open SQL" language does not conform at all

Maybe you are looking for

  • Problems with String

    Hey All, I have this string "Straw? No, too stupid a fad, I put soot on warts" I am going to test is this string is a palindrome. Thi string is, but I run it through my program it says it is not because of the "?" and ",". How to take that string run

  • Mail app crashes when opening on original iPhone

    My teenage son's mail app keeps crashing when he tries to open it on his original iPhone. It has been happening since 2.0, with neither of the latest updates fixing the problem. He has been a jailbreaker with his phone in the past. I have never jailb

  • JDBC Thin-Driver and Oracle Stored Procedure

    I've got a Oracle stored procedure which returns a Oracle record. How can I retrieve the record in java using the JDBC Thin-Driver ? Record: TYPE messagerec IS RECORD (log_level VARCHAR(2), timestamp VARCHAR2(19), text VARCHAR2(200));

  • Select options range table to be passed to Assistance class

    Hi Guru's, I have an assistance class where I have to write all my select queries. I have a selection screen with multiple Select options (as input fields). Now I want to pass the select options range table to assistance class. Please let me know if

  • End to end walkthough for setting up Power Q&A with my own data?

    I've uploaded a simple workbook and clicked "Add to Power Q&A". The web page responds "Added to Q&A", but when I click the "Ask with Power Q&A" link at the top right, I just get the splash screen. I tried clicking the "use my own data" button on the