Create a cursor or collection from a table that is unknown at designtime

Hi All,
I have a bit of a problem: I have to loop through a table (by means of a cursor, collection, refcursor - does not matter - any way that is possible is fine), but I do not know which table at design/compiletime. PLSQL does not want to let me use %rowtype unless the table already exists at compiletime, but I need to write a generic function to migrate data from one datamodel to another (two different applications).
In other words:
type Tc_OOMTable is ref cursor;
c_OOMTable Tc_OOMTable;
rec_OOMTable c_OOMTable%rowtype;
sqltext varchar(1024);
BEGIN
initialize(OOMTab, G3ETab);
sqltext := 'select * from ' || OOMTable;
--loop through all elements in OOMTable
open c_OOMTable for sqltext;
loop
fetch c_OOMTable into rec_OOMTable;
exit when c_OOMTable%notfound;
I would like to be able to pass a tablename to the OOMTable variable. Is that possible at all? If so, how can I do that?
If this is not possible: could I use the ROWNUM and loop through a table like this:
FOR j IN 1..NumRows
LOOP
select * from <my table name> where rownum=j;
--process the row here...
END LOOP;
TIA,
Stefan

Dave,
There are a couple of things: I know the applications that both datasets are coming from/going to, so I know a number of columns that the apps add to the table. I do not know what the user has added for his/her own reasons.
Secondly, I use user_tab_columns to compare the columns between the two tables, including data type, data length/scale/precision if applicable, and store the matching columns in a varray of records.
If I don't write a generic function I'll have to write code for every table, which is what I'm trying to prevent. I'll have a look at DBMS_SQL, see if that does for me what I want.
Thanks,
Stefan

Similar Messages

  • ISO help using SharePoint Designer 2010 to create an External Content Types from a table that has many columns

    I am trying to create an external content type for a specific list. The problem is that there are so many columns (more than 200) that I get the error:
    The operation(s) generation creates an SQL query which exceeds the length limit in Business Data
    Connectivity Metadata Store. The operation(s) will not be generated. Recreate
    the operation(s) with less number of columns in the configuration.
    I tried turning off a dozen columns and I am still getting this error. I am nearing the limit of the "extra" columns I can eliminate.
    What is the actual limit on number of columns?
    Thank you.

    Hi,
    From my research, it seems to be the limitation in response TTL and response size. To confirm
    it, would you please check the detailed errors logged in ULS log? <o:p></o:p>
    If you identified the threshold has be reached, you may follow this link to increase
    the threshold according to your business requirement.<o:p></o:p>
    http://blogs.msdn.com/b/bcs/archive/2010/02/16/bcs-powershell-introduction-and-throttle-management.aspx
    Miles LI TechNet Community Support

  • Create a new table from another table that exists ussing a stored procedure

    Hi,
    I want to know if is posibble to create a new table from another table that exists ussing a stored procedure. This new table is created from other table that exists in the DB.
    (in the next code the table tbl1 exist into the schema of the DB, but temp_tbl1 does not exist, it must be created by the procedure)
    create or replace procedute temp is
    temp_tbl1 tbl1%TYPE; //the temp_tbl1 will have the same type of tbl1
    begin
    create table temp_tbl1 as (select * from tbl1);
    end temp;
    thanks very much

    cat wrote:
    Hello,
    I think my problem is not about this grant, because if I execute this as an "anonymous procedure":
    DECLARE
    BEGIN
    EXECUTE IMMEDIATE 'CREATE TABLE Abonus (id NUMBER, amt NUMBER)';
    END;
    It runs ok
    But if I do:
    CREATE OR REPLACE procedure temp as
    BEGIN
    EXECUTE IMMEDIATE 'CREATE TABLE Abonus (id NUMBER, amt NUMBER)';
    END;
    I have the error
    ORA-01031: Insufficient privileges
    ORA-06512: at "temp", line 3Anonymous blocks are treated as "Invoker's Rights" from a privilege perspective whereas stored programs by default are treated as "Definer's Rights". Therefore using anonymous blocks is not a valid test to check this.
    The simplest form of checking this issue is by executing
    SET ROLE NONE;and then to run your statement/code block in question interactively. Using this approach you get in your session the effective rights of a "Definer's Rights" stored program, i.e. only privileges that you got granted directly to your user.
    You can revert to the default setting by issuing
    SET ROLE ALL;For more information regarding this topic, read e.g. the documentation:
    http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/subprograms.htm#LNPLS00809
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • How to exclude records from one table that is contained in a second table

    I am trying to create a Crystal report that excludes records from one Table that is contained in a second table using the != link option and it is not working. I've tried all of the different enforce options, and it is still not excluding those records. Does anyone have any suggestions of what I'm doing wrong or any other suggestions how I can obtain the results I need?
    Thanks in advance!

    Have you tried by Command ?
    Thanks,
    Gordon

  • Hello all, I bouhgt a TV serial using my apple tv2 and my Apple ID information: all good. But then I got an e-mail from apple saying that an "unknown" user downloaded con ten using my apple ID. Nobosy stoled anything. How do I get my particular apple TV2

    Hello all, I bouhgt a TV serial using my apple tv2 and my Apple ID information: all good. But then I got an e-mail from Apple saying that an "unknown" user downloaded content using my apple ID. Nobody stoled anything. How do I get my particular apple TV2 to recognize my apple ID account so it knows it is me who is buying. Thank you so much.

    Dear AC,
    Thank you so, so much for this answer. I did go into my Apple ID account through iTunes store and associated my devices to my Apple ID account. I did this by working on my computers (a mac mini and a mac air) and my two devices (iPhone and iPad). Thus there is a statemente saying "4 devices are associated with this apple ID and can download your purchases from iTunes in the iCloud". So whenever I use them to purchase anything, iCloud knows it is me through my devices so I do not get no e-mail warming me my account might be being used by a stranger.
    So, how do I associate my apple Tv2 to my apple ID account? I went to its settings and could not find any way of doing it. Can you continue helpling me? Please.
    Thank you so so much

  • Create cursor with data from multiple tables

    Hi,
    I need to create a cursor that contains fields from different tables.
    For example:
    Table 1                  Table 2                    Table 3                Table 4
    Col 1 (PK)              Col 2 (Pk)                  Col 4 (Pk)            Col 9 (PK)
    Col 2                     Col 3  (Pk)               Col 5 (PK)            Col 11
    Col 3                     Col 6                     Col 8                 Col 12
    Col 4                     Col 7                     Col 9
    Col 5                                               Col 10
    Col 13
    Col 14I've created the following:
    CURSOR c_test IS
       SELECT a.col 1,
                    a.col 13,
                    a.col 14
                    b.col 6
                    b.col 7
                    c.col 8
                    c.col 10
                    d.col 9
                    d.col 11
       FROM table1 a, table2, b, table3 c, table4 d
       WHERE (b.col 2,  b.col 3, c.col 4, c.col 5) =
                          SELECT a.col 1
                                       a.col 2
                                       a.col 3
                                       a.col 4
                          FROM table1 a
                          WHERE a.col 1 = '123456');But how can I get also the correct data (col 9 and col 11) of table d?
    What's missing in my where clause?
    Hope this is a bit clear.
    Regards,
    Ken

    Something like this:
    CURSOR c_test IS
       SELECT a.col1,
              a.col13,
              a.col14,
              b.col6,
              b.col7,
              c.col8,
              c.col10,
              d.col9,
              d.col11
       FROM table1 a
       JOIN table2 b
       ON  a.col1 = b.col2
       AND a.col2 = b.col3
       AND a.col1 = '123456'
       JOIN table3 c
       ON  a.col3 = c.col4
       AND a.col4 = c.col5
       JOIN table4 d
       ON  a.col1 = d.col9;Check on a.col1 = d.col9, don't whether that's right.

  • Creating XML file using data from database table

    I have to create an xml file using the data from multiple table. The problem That i am facing is the data is huge it is in millions so I was wondering that is there any efective way of creating such an xml file.
    It would be great if you can suggest some approach to achieve my requirement.
    Thanks,
    -Vinod

    An example from the forum: Re: How to generate xml file from database table
    Edited by: Marco Gralike on Oct 18, 2012 9:41 PM

  • How to create a vertical bar chart from a table? (PHP, HTML and CSS)

    Hi everyone,
    I have created a table and wish to proceed to do it even better in terms of analysis pattern. I want
    to create a vertical bar chart from the created table but I dunno how to start it.
    Here is the code for the table:
    <?php
    $gpa11=$_REQUEST['gpa11'];
    $gpa12=$_REQUEST['gpa12'];
    $gpa21=$_REQUEST['gpa21'];
    $gpa22=$_REQUEST['gpa22'];
    $gpa31=$_REQUEST['gpa31'];
    $gpa32=$_REQUEST['gpa32'];
    $gpa41=$_REQUEST['gpa41'];
    $gpa42=$_REQUEST['gpa42'];
    $gpa51=$_REQUEST['gpa51'];
    $gpa52=$_REQUEST['gpa52'];
    ?>
    <!doctype html>
    <html lang="en">
       <head>
          <meta charset="utf-8">
          <meta name="viewport" content="width=1024">
          <title>Feng Mentor Mentee</title>
       </head>
       <body>
          <div id="wrapper">
             <div class="chart">
                <h3>GPA Performance Graph</h3>
                <table id="data-table" border="1" cellpadding="10" cellspacing="0"
                summary="The performance of students throughout the years in university">
                   <thead>
                      <tr>
                         <td> </td>
                         <th scope="col">Year 1</th>
                         <th scope="col">Year 2</th>
                         <th scope="col">Year 3</th>
                         <th scope="col">Year 4</th>
                         <th scope="col">Year 5</th>
                      </tr>
                   </thead>
                   <tbody>
                      <tr>
                         <th scope="row">Sem 1</th>
                         <td><?php echo $gpa11;?></td>
                         <td><?php echo $gpa21;?></td>
                         <td><?php echo $gpa31;?></td>
                         <td><?php echo $gpa41;?></td>
                         <td><?php echo $gpa51;?></td>
                      </tr>
                      <tr>
                         <th scope="row">Sem 2</th>
                         <td><?php echo $gpa12;?></td>
                         <td><?php echo $gpa22;?></td>
                         <td><?php echo $gpa32;?></td>
                         <td><?php echo $gpa42;?></td>
                         <td><?php echo $gpa52;?></td>
                      </tr>
                   </tbody>
                </table>
             </div>
          </div>
       </body>
    </html>
    Here's the look:
                                                              GPA Performance Graph                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
    Year 1
    Year 2
    Year 3
    Year 4
    Year 5
    Sem 1
    Sem 2
    Please help me on this because this is my 1st project on php.

    Hi
    Are you using BI query? If yes then follow the steps -
    1. Take Sales org in rows of BI query. & take invoice type & Key figure in Columns.
    2. In VC use this query & drag chart from the output of this query.
    3. Right click on chart & go to 'Configure Element'. There select Chart Type as 'Bar chart'
    4. Below that you will get default option as clustered, there you select 'Stacked'
    5. Create Data series as per your requirement.
    6. Arrange proper layout of the model & then deploy.
    You will get required output in stacked format.
    Regards
    Sandeep

  • Problem creating a datablock with columns from 2 tables...

    Hello guys, i have a problem in creating a datablock with columns from 2 different tables. I try to create the datalock manually and in the Query Data Source Type Property i choose FROM clause query, and in the query data source name property i type my sql statement with the columns i want to display.After that i place the items that the datablock will contain , manually from the painter. However , when i run the application, the datablock doesn't display the items from the database. Am i doing something wrong?
    Thanx in advance,
    Regards,
    Bill.

    Never mind Peter, I found the error. I forgot to make execute_query for the datablock, so this was the reason why the items weren't displayed to me.
    Thanx anyway a lot for your advices and your time you spent !

  • Creating a Query with Data from 4 Tables.

    Hey guys. I'm having a small problem figuring out the best way for me to handle this query.
    I'm trying to make a query which outputs the amount of appointments a GP has furfilled, and the total amount allowed.
    I have 4 tables, for each I'm just gonna list the relevent columns:
    Appointment: ID, Patient_ID.
    Patient: ID, GP_ID.
    GP: ID, Trust_ID.
    Trust: ID, Quota.
    Appointment table has 400 entries (2 per patient atm).
    Patient table has 200 entries.
    GP Table has 30 entries (GP's can be assigned to more than one person) .
    Trust table has 6 entries.
    What I need to do is, look at the appointment table and get the number of times each patient has an appointment.
    Go through the patient table, and find out which GP the patient in the appointment belongs to.
    Add each occurance to the correct GP.
    Find out which Trust each GP belongs to, and add the total for each GP to the correct Trust.
    Check the quota in the Trust table, to see if the total is more than the allowed.
    I can't seem to think of an easy or simple way for me to do this. Can anyone help please? Many thanks.

    Hi,
    That sounds like a job for JOIN.
    To check the quotas against the total, use the SUM function; either the aggregate SUM or the analytic SUM, depending on your requirements.
    Sorry this answer is so vague, but that's the bes I can do with the information provided so far.
    Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved. In this case, between 2 and 10 rows of data per table should be enough to show what you need to do.
    Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    Always say which version of Oracle you're using.

  • Create release not picking data from Requisition table

    Hi All,
    I have imported release data from 11i to R12 through Requisition import program. Data got imported successfully. I have updated BLANKET_PO_HEADER_ID and BLANKET_PO_LINE_NUM column in po_requisition_lins_all table. Then I have ran Create Release Concurrent Program but that program Not picking the release from Requisition table.
    Can any one face this issue...Please let me know what thing i missing while doing this.
    Thanks.

    According to what I understand from your question, you have the Req successfully created but the the release is not happening when you run the create releases program.
    You have to have a ASL for this item with release property as Automatic Release and the BPO document number attached in the ASL attributes.
    Let me know if you have this setup or not.
    Karthik.

  • Can we create a BAM data Object from two tables

    Hi ,
    I want to pull the data from two tables and create a BAM data object, Is it possible in BAM?
    Do the needful
    Regards,
    Francis

    The sample way is using AQ on database. You can create a database view to join the tables. And create AQ on the view, create a ems to listen on the queue.

  • Create Big XML files ( extract ) from Relational Tables

    Experts: I need to create a big XML extract more than 5Gb , from relations tables using SQLX. I read the excellent FAQ given by MDrake in the following thread.
    https://forums.oracle.com/thread/418001
    Question
    1) Is it better to use XML schema, My XML output format is pretty much going to be static, so I can register an XML schema .
    2) Does Registering the XMLschema help with better memory management. I recall I used to get out of memory exception when I generated xml documents on oracle 10g using DBMS_XMLGEN.
    3) Can I generate this 5 Gb of XML file using oracle's default DOM parser?
    Thanks
    Kevin

    Hi Kevin,
    1) Is it better to use XML schema, My XML output format is pretty much going to be static, so I can register an XML schema .
    2) Does Registering the XMLschema help with better memory management. I recall I used to get out of memory exception when I generated xml documents on oracle 10g using DBMS_XMLGEN.
    No, an XML schema won't help for the generation.
    It is useful though if you're looking for the opposite task, i.e. loading an XML file into database tables.
    3) Can I generate this 5 Gb of XML file using oracle's default DOM parser?
    What is the default DOM parser ? Do you mean DBMS_XMLDOM APIs?
    Since you want to generate XML, there's not much to parse.
    Generally, using SQL/XML functions is the way to go.
    You may still hit some performance/memory issues while reaching such a size, especially with large XMLAgg aggregation context.
    If you do, you may switch to chunk generation instead. I've got some pretty good result with this approach and the parallel query feature.

  • Create Trigger to insert records from one table to another

    I created the below trigger to move data from one table to another after records have been inserted from another table to that table. What I need done is that each time records have been inserted into TEST_TBL, one of these actions codes should be implimented: U-update, N-insert, D-delete and inserted into TEST_TBL1. But each time I run the script, I get bunch of errors. Please see the script below: - Your help will be appreciated.
    create or replace
    trigger POWER_tr
    after update or insert or delete ON test_tbl
    for each row
    begin
    if updating then
    insert into test_tbl1
    (idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, action_code, date_added
    VALUES
    (idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, 'U', sysdate);
    ELSif INSERTING then
    insert insert into test_tbl1
    (idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, action_code, date_added
    VALUES
    (idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, 'N', sysdate);
    ELSIF deleting then
    insert into test_tbl1
    (idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, action_code, date_added
    VALUES
    (idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, 'D', sysdate);
    END IF;
    END POWER_tr;
    Thank you,
    Albert Zaza
    Edited by: azaza on Mar 1, 2009 4:14 PM

    Hello
    At the end of trigger show errors / and post what errors are you getting exactly?
    Here is a simple example for your reference, this will save old values in history table; you can replace it with new values if that's what do you want.
    CREATE OR REPLACE TRIGGER TRG_DU
       AFTER DELETE OR UPDATE
       ON EMPLOYEE    REFERENCING NEW AS New OLD AS Old
       FOR EACH ROW
    DECLARE
    BEGIN
       IF UPDATING
       THEN
          INSERT INTO employee_hist
            VALUES   ('UPDATE',
                      :OLD.empid,
                      :OLD.name,
                      :OLD.deptid);
       ELSIF DELETING
       THEN
          INSERT INTO employee_hist
            VALUES   ('UPDATE',
                      :OLD.empid,
                      :OLD.name,
                      :OLD.deptid);
       END IF;
    EXCEPTION
       WHEN OTHERS
       THEN
          -- Consider logging the error and then re-raise
          RAISE;
    END TRG_DU;
    /Regards
    Edited by: OrionNet on Mar 1, 2009 7:27 PM

  • How to dynamically create selecItems in a pgae from a table

    To those who may be able to help:
    I am using JDeveloper 10.1.3.4. In my application, I need to put a number of selectItem tags such as radio buttons on a page. What is difficult about this is that it can not be known in advance how many radio buttons there will be, because is depends on how many rows will be selected from a table, even though it is known that the number of selected rows will not exceed 3. I am considering using the radio button because it looks better on the page, and the user must select only one.
    A few sample rows from the table:
    TERM    AVAILABLE  SWITCHED
    200809  N          OFF
    200902  N          ON
    200906  Y          ON
    200909  Y          ONThe SQL of the view object from this table/(entity object) is:
    SELECT Terms.TERM
    FROM TERMS Terms
    WHERE AVAILABLE = 'Y' AND SWITCHED = 'ON'I am able to drag the selected two rows from the data control palette. But it is just a table. What I need is to ask the user to select one of them. What is the easiest way to achieve that?
    Many thanks for your help!
    Newman

    Hi, Sireesha,
    I almost succeed in the backing bean, except one last line when adding the new SelectItem into the list. Here is the code:
        private List<SelectItem> termList;
        public void setTermList(List<SelectItem> termList) {
            this.termList = termList;
        public List<SelectItem> getTermList() {
            return termList;
            FacesContext fc = FacesContext.getCurrentInstance();
            ValueBinding vb =    fc.getApplication().createValueBinding("#{data}");
            BindingContext bc = (BindingContext)vb.getValue(fc);
            DCDataControl dc = bc.findDataControl("ZBOVModuleDataControl");
            ApplicationModule am = (ApplicationModule)dc.getDataProvider();
            ZBOVModuleImpl zbovam = (ZBOVModuleImpl)am;
            TermsForStudentsImpl termsOpen = (TermsForStudentsImpl)zbovam.getTermsForStudents1();
            System.out.println("Number of rows: " + termsOpen.getEstimatedRowCount());
            long size = termsOpen.getEstimatedRowCount();
            for (int i = 0; i < size; i++) {
                Row currRow = termsOpen.getRowAtRangeIndex(i);
                String term = (String)currRow.getAttribute("Term");
                String termDesc = translateTerm(term);
                SelectItem selectItem = null;
                selectItem = new SelectItem(term, termDesc);
                // The code runs fine except when the one line below is uncommented
                //termList.add(selectItem);
                System.out.println(term + ": " + termDesc);
        public String translateTerm(String yyyymm) {
            String year = yyyymm.substring(0,4);
            String semester = null;
            String month = yyyymm.substring(4,6);
            if (month.equals("02")){
                semester = "Spring";
            } else if (month.equals("06")) {
                semester = "Summer";
            } else if (month.equals("09")) {
                semester = "Fall";
            return semester + " " + year;
        }The page in the front is blank except one line of static text, and nothing in the page binds to the termList in the backing bean yet. When the line {color:red}termList.add(selectItem);{color} is commented out, the page runs and the console prints out:
    09/08/17 03:17:25 Number of rows: 3
    09/08/17 03:17:25 200809: Fall 2008
    09/08/17 03:17:25 200902: Spring 2009
    09/08/17 03:17:25 200906: Summer 2009But uncommenting that line will cause a NullPointer error, and the error message says that the SelectTerm class can not be instantiated (I wrap round the long line of error message in the browser into several shorter lines):
    javax.servlet.jsp.JspException: javax.faces.FacesException:
       javax.faces.FacesException: Can't instantiate class: 'zbov.viewcontroller.backing.student.SelectTerm'..
       class zbov.viewcontroller.backing.student.SelectTerm : java.lang.NullPointerExceptionI am stuck here. Do you have any idea what is wrong and how to get around this?
    Thank you for helping.
    Newman

Maybe you are looking for