Select schema via cursor

I am working with a database in which all schemas have the same tables. I am trying to write a PL/SQL routine that will loop through each schema, query a table in that schema, and insert that data into a master table (simplified explanation). I can get a cursor that contains all the schemas, but I can't figure out how to set the schema name from a cursor.
sample code ... (not working)
declare
cursor schemaCrsr is select SCHEMA_NAME from MASTER.SCHEMA_TABLE;
begin
for mySchemaCrsr in schemaCrsr loop
insert into MASTER.TABLE_X
select * from mySchemaCrsr.TABLE_X;
end loop;
end;
What is the correct syntax for "mySchemaCrsr.TABLE_X" to enable this? Or is there another way to accomplish this?
Thanks

Chris,
I'm using Oracle version 8.1.6 now, so I can't tell if this will work in Oracle version 7.3.4 or not, but I think I remember using something similar in Oracle version 8.0.5. Please try the code below and let us know if it works for you or not.
Also, posting on this forum causes spaces to be added between concatenation symbols where they don't belong, so anywhere you see a space between | and |, remove the space, before running the code.
Any time that you are using some sort of variable to represent a schema name or table name or column name at run time, you have to use some sort of dynamic sql. Execute immediate is a new type of dynamic sql. DBMS_SQL is an older method.
Barbara
DECLARE
CURSOR schemacrsr
IS
SELECT schema_name
FROM master.schema_table;
cursor_name INTEGER;
rows_inserted INTEGER;
BEGIN
FOR myschemacrsr IN schemacrsr
LOOP
cursor_name := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE
(cursor_name,
'INSERT INTO master.table_x SELECT * FROM '
| | myschemacrsr.schema_name
| | '.table_x',
DBMS_SQL.NATIVE);
rows_inserted := DBMS_SQL.EXECUTE (cursor_name);
DBMS_SQL.CLOSE_CURSOR (cursor_name);
END LOOP;
END;
null

Similar Messages

  • Which method is better, the SELECT .. CURSOR(.. , or the Queries in loop

    I have a table t1, this table has 1 to many relation with
    tables t2,t3. t2,t3 do not have any direct relation with eachother.
    I have to read all data in all tables, what do you prefer
    from the following. I am using 10g release 2 but if there
    is some better way in 11g I can go for it also.
    Also generalize this for t2,t3,t4,t5,... etc.
    Method 1.
    FOR i in (SELECT * FROM T1) LOOP
    FOR j in (SELECT * FROM t2 WHERE t2.x=t1.x)LOOP
    ...process data...
    END LOOP
    FOR k in (SELECT * FROM t3 WHERE t3.x=t1.x)LOOP
    ...process data...
    END LOOP
    END LOOP;
    Method 2
    FOR i in
    (SELECT t1.*,
    CURSOR(select * from t2 where t2.x=t1.x),
    CURSOR(select * from t3 where t3.x=t1.x)
    FROM t1) LOOP
    ... process data...
    END LOOP
    Which one will be the faster and why.
    Thanks

    Your question is meaningless.
    Why? Because...
    > There is no way to join all these 3 tables correctly, because joining will
    produce reduandant rows.
    and...
    > its impossible to join all three tables here
    and then you show Method 1 and 2 as options.
    Guess what.
    You have coded a nested loop join in both!
    So just what makes your hack of a join in PL/SQL so much superior than an "impossible" nested loop join in SQL?
    Your problem is not joining.. it is conceptual and design fundamentals. Your approach says that the problem should be approached by discarding the fundamental concept of joining data in a RDBMS.. and thinking of row-by-row slow-by-slow serialised processing.
    Join. Use parallel processing. Either PQ or self-rolled via PL/SQL. There are loads of tools in the Oracle toolbox to address this type of problem.
    Message was edited by:
    Billy Verreynne

  • Database selection with invalid cursor !

    hi experts,
        When  execute SAP BW processchar, it occur some system error: (sm21)
    Database selection with invalid cursor
    The database interface was called by a cursor (in a FETCH or CLOSE
    cursor operation) that is not flagged as opened. This can occur if a
    COMMIT or ROLLBACK was executed within a SELECT loop (which closes all
    opened cursors), followed by another attempt to access the cursor (for
    example, the next time the loop is executed).
    this error occur when apply bw support package 19.
    sap notes 1118584 Solution is: Import Support Package 17 . but my support package is 19.
    how can i solve this error?
    thanks,
    xwu.

    I am only assuming things, but it might be worth to look closely if you were experiencing an ORA- error during the execution. This could have caused a rollback and thus closed the cursor. Please check the job log, the workprocess trace (dev_wX file) and the system log SM21 and ST22 as well.
    Besides that check the oracle alertlog and the usertrace destination.
    Best regards, Michael

  • Database selection with invalid cursor with MaxDB database

    Hi Experts,
    I encountered the this error:
    "Database selection with invalid cursor
    The database interface was called by a cursor (in a FETCH or CLOSE
    cursor operation) that is not flagged as opened. This can occur if a
    COMMIT or ROLLBACK was executed within a SELECT loop (which closes all
    opened cursors), followed by another attempt to access the cursor (for
    example, the next time the loop is executed)."
    We are using bw support package 19 early this month. Previously is working fine but this problem occured from the last 2 days.
    We are using MaxDB database.
    Really appreciate any speedy responds.

    Hi,
    We finally resolved the issue.
    The solution:
    We check the RFC connection test in SM59. There are connection error.
    There is an error that related J2EE_ADMIN user.
    SO we reset the J2EE_ADMIN id in SU01.
    The problem goes away.
    Many thanks

  • Load data error: Database selection with invalid cursor (sm21)

    hi experts,
    when I execute processchar, it occur some system error:
    "Database selection with invalid cursor ",
    "Documentation for system log message BY 7 :
    The database interface was called by a cursor (in a FETCH or CLOSE
    cursor operation) that is not flagged as opened. This can occur if a
    COMMIT or ROLLBACK was executed within a SELECT loop (which closes all
    opened cursors), followed by another attempt to access the cursor (for
    example, the next time the loop is executed). "
    the error msg occur when apply bw support package19.
    data from DSO to CUBE, Transferred Recodes is not zero, but Added Recodes is zero.
    Request status always yellow, process is running.
    current sys info: BI7 and BW19, BASIS17,PI_BASIS17, the database is oracle10g R2.
    thanks for your help.

    I have solved this issue, The Oracle checkpoint not complete.
    thanks,
    xwu.

  • Processchar occur error:  Database selection with invalid cursor (sm21)

    hi,
       when I execute processchar, it occur some system error:
    "Database selection with invalid cursor ",
    "Documentation for system log message BY 7 :
    The database interface was called by a cursor (in a FETCH or CLOSE
    cursor operation) that is not flagged as opened. This can occur if a
    COMMIT or ROLLBACK was executed within a SELECT loop (which closes all
    opened cursors), followed by another attempt to access the cursor (for
    example, the next time the loop is executed). "
    the error msg occur when apply bw support package19.
    data from DSO to CUBE, Transferred Recodes is not zero, but Added Recodes is zero.
    Request status always yellow, process is running.
    current sys info: BI7 and BW19, BASIS17,PI_BASIS17, the database is oracle10g R2.
    thanks for your help.

    I have solved this issue , The Oracle checkpoint is not complete.
    thanks,
    xwu.

  • Database selection with Invalid Cursor error in RSDRI_INFOPROV_READ

    Hi Everyone.
    I am using RSDRI_INFOPROV_READ Function module for reading data from a multiprovider.
    Logic of the code is as following
    while <more data>
    CALL RSDRI_INFOPROV_READ reading data in E_T_DATA
    Append lines of E_T_DATA to EO_T_DATA.
    If total lines of data in EO_T_DATA > 200000
    <save EO_T_DATA in a file using GUI_DOWNLOAD>
    <clear EO_T_DATA>
    EndIF
    EndWhile.
    As soon as number of record exceed 200000 first file is saved, but after that next data call results in error.
    Error says "Database selection with invalid cursor".
    I suspect that this because of call to FM GUI_DOWNLOAD. While calling this FM after RSDRI_INFOPROV_READ causes system to commit and again the cursor is tried to open in next call casuing it to fail.
    But it is imperative for me to save data in file at regular intervals as data volume is huge.
    Any pointers in this direction will be helpful.

    Hi Everyone.
    I am using RSDRI_INFOPROV_READ Function module for reading data from a multiprovider.
    Logic of the code is as following
    while <more data>
    CALL RSDRI_INFOPROV_READ reading data in E_T_DATA
    Append lines of E_T_DATA to EO_T_DATA.
    If total lines of data in EO_T_DATA > 200000
    <save EO_T_DATA in a file using GUI_DOWNLOAD>
    <clear EO_T_DATA>
    EndIF
    EndWhile.
    As soon as number of record exceed 200000 first file is saved, but after that next data call results in error.
    Error says "Database selection with invalid cursor".
    I suspect that this because of call to FM GUI_DOWNLOAD. While calling this FM after RSDRI_INFOPROV_READ causes system to commit and again the cursor is tried to open in next call casuing it to fail.
    But it is imperative for me to save data in file at regular intervals as data volume is huge.
    Any pointers in this direction will be helpful.

  • I have a new Macbook Pro.  Had just selected link via safari and the compuuter locked-up.  It won't turn off...don't seem to have an option (no contol,alt,delete like PC).  How do I unlock/reboot?

    I have a new Macbook Pro.  Had just selected search via Safari and computer locked-up.  How do I unlock/reboot?  On/off doesn't do anything...no  cont/alt/delete option like PC, no easy battery removal available.  What's the secret?

    Hold down Option Command Escape at the same time... from the drop down Menu choose  Force Quit Safari.
    Or,
    Click the Apple menu icon top left in your screen. From the drop down menu click Force Quit.

  • Dataguard setup for selected schemas

    Version:10.2, 11.2
    Platform : Solaris 5.10
    In our Production DB, we have some schemas which we do not want to be replicated at the standby site. Logical backup is enough for these schemas.
    Instead of replicating the entire database, Is there a way we could set up dataguard in which the logs are shipped only for selected schemas?

    With a Physical Standby Database , you always 'replicate' your whole Primary. With Logical Standby, though, you could exclude certain schemas from the 'replication'.
    Another option would be - as already mentioned by others - to do a regular replication with Streams or Golden Gate and only replicate the schemas resp. objects that you deem important.
    However, I would recommend that you review the requirement to exclude 'unimportant' schemas from your Standby Database. It makes the whole setup more complicated than necessary.
    Just go with Physical Standby and ignore those schemas - why bother?
    Kind regards
    Uwe Hesse
    http://uhesse.wordpress.com

  • Iphone will not let me select music via genres in itunes

    hello forum. can anyone pls tell me how to make the ipod on my iphone choose music from my genres. in itunes i can select music via genres but when i sync to my iphone the genre button always displays that there is no music in that particular genre even though all my genres are listed. i have also ticked the box in itunes advanced tabs to let itunes organise the music folder.

    yes yes and yes. but now the movie has completely disappered from my iTunes and from my iPhone. I had 16 days and 19 hours left to watch my movie when I started it, and after I started it I still had 23 hours to complete it. Now it is completely gone.

  • Logic Pro 9 - Not able to select plugins via Inserts / Audio Units.

    Hi
    I have the program Logic Pro 9 version 9.1.6 (1700.43) (32- bit)
    I use plugins like for example SampleTank and Realstrat . Everything has until recently worked fine, but I now have a problem.
    When I choose a plugin I usually put the mouse on the box 'Inserts', press ALT and then a menu appears. Here I, among many menu items, at the bottom see ' Audio Units ' . At this point I usually could choose, for example SampleTank , .. but now I can only choose Apple features. That is to say - I can not choose my plugins in this menu anymore.
    I've been around online and search . Here I was recommended to delete a file called com.apple.audiounits.cache . I have done this, but the problem is not solved.
    I also have updated the operating system with latest MacOSX10.7.5 update . This has not helped .
    All my plugins are also visible in Logic Audio Units Manager, and I can see that they are being loaded when Logic starts up.
    The plugins also still works in projects created within the problem occurred. That is, - I can open for example SampleTank in a track in a project that is created and a half years ago.
    So the exact problem is that I, in new projects, is not able to select plugins via Inserts / Audio Units .
    Can you help me solve this problem?
    Regards Henrik

    Hekke44 wrote:
    I do not think it is very user friendly, I must say.
    For users of this system, it must surely be obvious that you very often have to choose musical instruments, also from instrument plug-ins.
    Yes, often. That is why it is very obvious and simple for any experienced user.
    Hekke44 wrote:
    Why on earth is it so complicated to choose a musical instrument? If you are not currently using this system every day, you forget the such a detail about having to press down for several seconds to select an instrument.
    I do not think it is complicated at all. And you do not have to press down for several seconds. I just timed, it is 0.4 seconds of clickholding. The holding is functional:  you won't load a new instrument (and possiblly loose any work you had done on your sound) just because you accidentally clicked on a slot.
    Hekke44 wrote:
    There should be a nice big green button on the screen that read 'Select musical instrument', - then a menu where you can choose whether it should be one of Logics musical instruments, or a plugin instrument.
    It would be user-friendly.
    What is your view about these things?
    You are basically saying it should be dumbed down to the level of some "any-kid-or-adult-idiot-can-use-it-out-of-the-box" smartphone app. I think you are overlooking that this is a Pro program, not a toy. I think you try to blame the software for the fact that you didn't know how to operate it. You're avoiding responsability. That's my view.

  • Alias required in SELECT list of cursors to avoid duplicate column names

    I got some error messages while compiling the following.
    DECLARE
         alert_id                              NUMBER;
         CURSOR cur_search IS SELECT c.item_description,
         d.name modelname,
         SUM(b.quentaty),
         SUM(b.balence)
         FROM      item_procurement_history_dtl a,
                        item_procurement_history b,
                        item_master c,
                        model_master d
         WHERE a.item_code = b.item_code
         AND a.lot_no = b.lot_no
         AND a.item_code = c.item_code
         AND b.modelcode = d.modelcode
         AND (c.item_description LIKE '%'||:blk_stock_search_fields.item_name||'%' OR :blk_stock_search_fields.item_name IS NULL)
         AND (d.name LIKE '%'||:blk_stock_search_fields.modelname||'%' OR :blk_stock_search_fields.modelname IS NULL)
         AND (a.status = :blk_stock_search_fields.status OR :blk_stock_search_fields.status IS NULL)
         GROUP BY c.item_description, d.name
         ORDER BY c.item_description, d.name;
    BEGIN
         GO_BLOCK('blk_stock_search_fields');
         CLEAR_BLOCK(NO_VALIDATE);
         FOR i IN cur_search LOOP
         :blk_stock_search_data.item_name                := i.item_description;
              :blk_stock_search_data.modelname               := i.modelname;
              :blk_stock_search_data.tot_qty                    := i.tot_qty;
              :blk_stock_search_data.available_qty     := i.available_qty;
              NEXT_RECORD;
         END LOOP;
         FIRST_RECORD;
         GO_ITEM('blk_stock_search_fields.pb_search');
    END;
    The error is as follows :-
    Error 403 at line 23 column 2
    Alias required in SELECT list of cursors to avoid duplicate column names.
    What will be the solution for this error?
    Thanx and Regards,
    Vikas

    Vikas,
    The problem is that you are referencing a column name in your LOOP that does not exist in your CURSOR. Therefore, Oracle has interpreted this to its BEST guess Exception. This can be resolved as follows:
    DECLARE
       alert_id NUMBER;
       CURSOR cur_search IS
          SELECT c.item_description,
                 d.name modelname,
                 /* You need to ALIAS the product of the SUM() so you can reference it by name.*/
                 SUM(b.quentaty) AS tot_qty,
                 /* Same issue here, you must ALIAS the SUM() of Balance in order to reference it by a name.*/
                 SUM(b.balence) as available_qty
            FROM item_procurement_history_dtl a,
                 item_procurement_history b,
                 item_master c,
                 model_master d
           WHERE a.item_code = b.item_code
             AND a.lot_no = b.lot_no
             AND a.item_code = c.item_code
             AND b.modelcode = d.modelcode
             AND (c.item_description LIKE '%'||:blk_stock_search_fields.item_name||'%' OR :blk_stock_search_fields.item_name IS NULL)
             AND (d.name LIKE '%'||:blk_stock_search_fields.modelname||'%' OR :blk_stock_search_fields.modelname IS NULL)
             AND (a.status = :blk_stock_search_fields.status OR :blk_stock_search_fields.status IS NULL)
           GROUP BY c.item_description, d.name
           ORDER BY c.item_description, d.name;
    BEGIN
       GO_BLOCK('blk_stock_search_fields');
       CLEAR_BLOCK(NO_VALIDATE);
       FOR i IN cur_search LOOP
          :blk_stock_search_data.item_name := i.item_description;
          :blk_stock_search_data.modelname := i.modelname;
          :blk_stock_search_data.tot_qty := i.tot_qty;
          :blk_stock_search_data.available_qty := i.available_qty;
          NEXT_RECORD;
       END LOOP;
       FIRST_RECORD;
       GO_ITEM('blk_stock_search_fields.pb_search');
    END;Just an observation. Also, There are some misspellings in your cursor. Does this match your table?
    Hope this helps.
    Craig...

  • Selecting xml-messages from ORABPEL-schema via SQL

    Hi,
    i want to select xml documents via SQL from the ORABPEL schema.
    Can anybody help, how to do this?
    There is the table xml_document, which has the columns:
    DOCKEY
    DOMAIN_REF
    BIN_CSIZE
    BIN_USIZE
    BIN
    MODIFY_DATE
    BIN_FORMAT
    Bin is of type blob....

    "Installation Monkey", did you ever find a solution or sample code to access and decipher the Audit_trail.LOG contents through a query or using SQL lob calls?
    I have looked all over, tried decoding the hex code (into a second layer of gibberish), and found nothing other than pointers to the API bpels.
    Thank you for any information.

  • Select schemas from relational model on import from data dictionary option

    Hi All,
    I have one relational model with 3 diferent schemas,
    I want to compare one of my schemas with the data dictionary I have in a database,
    I select the import option in the general file menu, select from data dictionary option,
    select the connection from my database,swap target model checked,select a physical model and select the objects i want to compare from the database,
    My problem is that the result is the comparison between all the objects in my model and the objects in the database that I have selected,
    what I really want is to compare a list of objects in my model to a list of objects in my database,
    this could be possible? or always need to compare all the objects of the model?
    Thanks in advance

    Hi jbellver,
    there is no any development in DM 3.1.0.691 on that problem. In production release you'll be able to compare objects in subview with database or just to select several objects and compare them with database. And of course "generate in DDl" filtering still can be used - it works at "Compare dialog" level.
    Philip

  • I am trying to highlight text on multiple pages, but Adobe will not autoscroll via cursor.

    I am trying to highlight text on multiple pages, but when I select the text and bring the cursor to the bottom of the screen Adobe does not advance the document. How do I make it so I can highlight from page to page without having to release the mouse button?
    Also, how do I get adobe to realize that there is a header and footer on each page, but the actual text in the file is in two columes. Is there a way to make this clear and embade it in the document so other programs recognize this too?

    Regarding your first question, change the view to Single Page Continuous.

Maybe you are looking for

  • How can I have a collective AWR report for RAC database in 10gR2 and 11gR1?

    Plz correct me here awrrpt.sql takes the snapshot at the instance level and incase we have 5 instances we have to take 5 awr reports for a particular period.correct??? If above is true ,any wayout to collect a single collective AWR report for RAC dat

  • ISO Boot Camp Windows 8.1 Install

    Hi, I just purchased Windows 8.1 from the Microsoft Store as a digiital download. It came as an .exe, so using a friend's PC I installed the Media Creator program from Microsoft in order the generate the files needed to boot install from a flash. The

  • Preview video not working

    I recently purchased iMovie 09, and up until today it was working fine. Now, videos don't play in the project preview window or in full screen. They play as I scroll through them, and they play in the preview window if the clip isn't in the project,

  • HT1688 where did I find my iphone photos on my computer?

    Hpow do I find iPhone photos on my compter? I just sync the phone.

  • CF Flash Forms issue with IE

    Hello, I just created a CF Flash Form and it works fine. BUT I have to do an extra click to access my flash form. How do I get rid of this extra click? Is there any special script that I should be pasting into my code? Any suggestion is welcome. Than