PL/SQL cursor question (possible to pass in the table name?)

I want to pass the name of a table to a cursor and select from that,
Is this possible in PL/SQL?
CURSOR get_rows(table_name IN VARCHAR2) IS
SELECT * FROM table_name;
     The actual sql statement that will be used is more complex.
     I have 18 tables for which the same query would work varrying only in the name of the table.
I get an error when I try to do the above.

>
I am not quite sure how you can derive anything from the design given the example that has all other details stripped out
>
What Justin said is pretty clear
>
If you are really doing a SELECT * and you have 18 different tables, it seems unlikely that all tables would always have exactly the same set of columns. If they do, that is almost certainly an indication that the data model is incorrect.
>
A data model that includes 18 tables with the same set of columns has something wrong with it. You explained that by clarifying that it is only TWO columns in each of the 18 tables that is the same. Perhaps the tables have one-to-many relationships and the two columns are the key columns. That is different.
>
The 'select *' will actually pull back only two columns, both of which are primary keys (long). I need to select all rows into a data structure that is global that I can iterate through at a later time. So given that I can use a ref cursor and have a dynamic table name, how would I select into a data structure that is of two primary keys and make that global to be used in another method at a later time?
>
Why not use an actual table to store the column data? An index-organized table would be perfect for that use and won't use up valuable user memory.
And by global do you mean the data needs to be accessible by a different session than the one that collected the data?
And what do you mean by 'later'? Tomorrow or next week?
The use case you describe sounds like you are having to update primary key values in tables that have parent-child foreign key constraints. Is that what you are doing? Can you do this offline and defer or disable the constraints, perform an update (rather than insert/delete) and then reenable the constraints?

Similar Messages

  • Invalid table name when pass in the table name as variable in dynamic sql

    Hi,
    I need to create a stored procedure which will return a list of data to my java application like the following.
    first, select the table name from the first table.
    For example : SELECT T_NAME FROM MDR_SMSTABLES
    second, select the data from the table which returned by first select statement
    For example : SELECT * FROM T_NAME.
    I use dynamic sql with cursor to select the data. But it returns "java.sql.SQLException: ORA-00903: invalid table name"
    I fetch the table name to varchar2. I think this might the cause it returns me the this error. But i don't know what type should i put for the table name other then varchar2.
    val2 VARCHAR2(200);
    OPEN cv FOR
    SELECT T_NAME FROM MDR_SMSTABLES WHERE T_DATE=d_dt_sent;
    FETCH cv INTO val2;
    WHILE cv%FOUND
    LOOP
    OPEN refcur FOR
    'SELECT * FROM :t WHERE MID = :m' USING val2, msg_id;
    EXIT WHEN refcur IS NOT NULL;
    FETCH cv INTO val2;
    END LOOP;
    As my stored procedure is quite long, so i just paste some of the code here. Hope the information is enough. Can anyone please help?
    Thanks

    DECLARE
    val2 VARCHAR2 (200);
    cv sys_refcursor;
    refcur sys_refcursor;
    BEGIN
    OPEN cv FOR
    SELECT table_name
    FROM user_tables
    WHERE table_name IN ('EMP', 'DEPT');
    FETCH cv INTO val2;
    WHILE cv%FOUND
    LOOP
    OPEN refcur FOR 'SELECT * FROM '||val2;
    EXIT WHEN refcur IS NOT NULL;
    FETCH cv INTO val2;
    END LOOP;
    END;

  • Can the table name in a cursor be parameterized?

    I would like to do the following in pl/sql
    Procedure my_proc ( varchar2 table_name) is
    CURSOR my_cursor ( table_name VARCHAR2 ) IS SELECT some_column FROM table_name ;
    i.e. parameterize the table name. I know it is possible to parameterize the SELECT cause by doing the above but, as written, my example will not compile. So, I'm wondering if it is even possible to create a cursor like this.
    Thanks for any help/advice,
    -=beeky

    I wanted to add that I have no control over the database design. The reason I want to parameterize a cursor is to allow a single procedure to do exactly the same thing to six tables. These tables contain data for different geographic regions and are supplied by an outside party. My script essentially merges these tables into our relational model.
    Thanks again to all who replied,
    -=beeky

  • How to pass the table name dynamically in xml parsing

    Hi All,
    I have created one procedure for parsing xml file which is working perfectly.
    FORALL i IN t_tab.first .. t_tab.last
             INSERT INTO Test_AP VALUES t_tab(i);Now I want to put the table name dynamically+. For that I have added one query and modify above code as follow:-
    I have already declare dml_str varchar2(800) in declaration part.
    Query is as follows:-
    select table_name into tab_name from VERSION_DETAILS where SUBVERSION_NO=abc;  -- here abc is variable name which contains values.
    FORALL i IN t_tab.first .. t_tab.last
              dml_str := 'INSERT INTO ' || tab_name || ' values :vals';
              EXECUTE IMMEDIATE dml_str USING t_tab(i);But it's not working. How I will resolve this or through which way I achieved the intended results. Anyone can guide me on this matter.
    Thanks in advance for your help...

    Hi,
    But it's not working.Don't you think it would help to give the error message?
    Put the assignment before FORALL.
    FORALL only accepts one subsequent DML statement (static or dynamic SQL) :
    dml_str := 'INSERT INTO ' || tab_name || ' values :vals';
    FORALL i IN t_tab.first .. t_tab.last          
    EXECUTE IMMEDIATE dml_str USING t_tab(i);

  • Using column value is it possible to find the table name in the database?

    Hi all,
    using column value is it possible to find the table name in the database?
    guys i need the table value
    Note:
    oracle-9i
    for example:
    i don't know NIC(column value) in which table in the database.
    Thank you,
    with regards,
    JP.
    Edited by: Guest on Feb 27, 2012 5:42 AM

    Hi,
    As far as I understand what you are asking for I would suggest 4 data dictionaries that will help you to know the table name from the column names
    1. USER_TAB_COLS
    2. ALL_TAB_COLS
    3. DBA_TAB_COLS
    4. COLS
    These can give you detail information about the columns and respective tables at user, schema, dba level. Further information on the table can be found by querying ALL_OBJECTS table giving table_name as Object_name, or you can join the data dictionaries too.
    To know about various data dictionaries avalible in Oracle please query select * from cat;
    Let us know if you need further assistance.
    Twinkle

  • Is it possible to change Overridden Qualified Table Name in code?

    Hi,
    Environment: Crystal Reports XI R2, 2008, Sql Server 2005
    I had about 1000 reports to change. Several changes are the standard, so i had created several tools that i use to make that change in all reports.
    However i can't find a way to change Overridden Qualified Table Name and remove the Catalog and Owner information, so it seems that the only way is using CR editor and make these changes one by one... not a good idea!
    Does anyone managed to do this???
    Thanks,
    Carlos Crespo

    Hi,
    <P>Thanks for your input.</P>
    <P>I use CR in two ways:<BR>
    a) to develop reports to use in our projects - In this case we don't have major issues with this, and we chance the location of the database in code at runtime;<BR>
    b) to develop reports to use in ERP softwares from third parties - and here we are having some issues - not always but some times.<BR>
    We know that they change the location of the DB in code also (no specific info however).<BR>
    <P>An example:<P>
    We change a report on my development PC, against a DB called TEST;<BR>
    We send the report to the customer, who runs it on its system, trying to read data from a db XYZ;<BR>
    If the customer also has a TEST db, in some reports the system reads some tables from XYZ, but others he gets the info from TEST db. In one example our customer has an invoice where all data was from the production DB, except the COUNTRY table that was read from a copy of the TEST db. After TEST was removed, the data was read from the production DB....<BR><BR>
    And to get you an idea: we're talking about hundreds of customers - some of them have 600 SQL DBs in the same server (small Dbs, around 70/500 MB in size) - so we can only hope that the user doesn't create a DB with the same name we used to develop the report...<BR><BR>
    And what i don't understand is WHY we can define Overridden Qualified Table Name  in same tables, and not in others.<BR><BR>
    Example:<BR><BR>
    One of the reports has 6 sub-reports. <BR>
    I can define Overridden Qualified Table Name  in the main report (except for a View), and in 2 of the subreports - but not in the other 4...<BR>
    The zero in front of the table name shows  a table where Overridden Qualified Table Name has been defined, and the original Catalog and Owner was removed - the 2 shows a table where Overridden Qualified Table Name has been defined, but the original catalog (PRITESTEDOC75) and owner (dbo) remains.<BR><BR>
    I even tried to export the sub-reports, change this info in the sub-report, and then import it again (a suggestion from Business Object support), but it doesn't work...<BR><BR>
    Main Report:<BR>
    Artigo     0     <BR>     
    CabecDoc     0     <BR>     
    LinhasDoc     0     <BR>     
    ModosExp     0          <BR>
    Clientes     0          <BR>
    CondPag     0          <BR>
    DocumentosVenda     0     <BR>     
    Moedas     0          <BR>
    MoradasAlternativasClientes     0     <BR>     
    OutrosTerceiros     0<BR>          
    ArtigoIdioma     0          <BR>
    Paises     0          <BR>
    ArtigoLote     0     <BR>     
    TDU_CC_INFODOCVND     0     <BR>     
    Clientes_Fac     0     <BR>     
    Paises_Fac     0          <BR>
    V_Entidades     2     PRITESTEDOC75     dbo        (V_Entidades is a View, not a Table)<BR><BR>
    Sub-Report 1:<BR>
    GCP_VND_CalculaTotaisDocumento     2     PRITESTEDOC75     dbo (GCP_VND_CalculaTotaisDocumento is a SP)<BR><BR>
    Sub-Report 2:<BR>
    CnfTabLigCBL     2     PRITESTEDOC75     dbo<BR><BR>
    Sub-Report 3:<BR>
    LinhasNumSerie     2     PRITESTEDOC75     dbo<BR><BR>
    Sub-Report 4:<BR>
    ResumoRetencao     0          <BR>
    Historico     0          <BR>
    OutrosTerceiros     0          <BR>
    EntidadesPublicas     0          <BR>
    Clientes     0          <BR><BR>
    Sub-Report 5:<BR>
    1 ResumoRetencao     0     <BR>     
    2 Historico     0          <BR>
    3 OutrosTerceiros     0          <BR>
    4 EntidadesPublicas     0     <BR>     
    5 Clientes     0     <BR><BR>
    Sub-Report 6:     <BR>
    1 ResumoIva     2     PRITESTEDOC75     dbo<BR>
    2 CabecDoc     2     PRITESTEDOC75     dbo<BR>
    3 Iva     2     PRITESTEDOC75     dbo<BR><BR>
    Best Regards,<BR><BR>
    Carlos Crespo<BR>

  • How to pass parameter for table name in  form6i.

    Hi ,
    I am facing the problem to pass parameter for table name in form6i.
    If any solution please infirm me earliest to my mail id.
    ([email protected])
    example:
    begin
    select ename into :ename
    from :tab_name
    where empno =7788;
    end;
    It gives error as bad bind variable 'tab_name'
    *** where :ename and :tab_name are form fields
    Thanking you,
    Balasaheb

    object name not taken as table --> what do u mean by
    this?
    Please be more clear..
    Regards
    PriyaI have two block. First block I am displaying all the table using user_objects table. Another block I want display, user which table selected, corresponding table all the records.

  • SQL Server Service is not reflecting to the new name.

    Hi,
    I just rename the computer and use the command below to rename the SQL Server but the SQL Server Service is not reflecting to the new name.
    Is there a way to change the SQL Server Service and agent to reflect the new name or do I have to re-install sql server.
    I am using SQL 2008 R2.
    Thank you in advance.

    If running "SELECT
    @@servername" yields the old server name, it means the instance has not been renamed.
    you must run statement to drop the old name of the instance and recreate it with the new name as the default (local) one..
    EXEC master.dbo.sp_dropserver 'MACHINENAME\OLDINSTANCENAME'
    go
    EXEC master.dbo.sp_addserver 'MACHINENAME\newINSTANCENAME', 'local'
    go
    I took the code here: 
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/c07ab906-dabf-4303-9737-d430d82c4f42/how-to-rename-instance-of-sql-server-2008-r2?forum=sqltools
    Once you did this, look at your maintenance plans.  I sometime end up having one or two still following the old name.  Especially if you create this new server from a copy of another virtualized one.

  • Is it possible to view/get the table data from a dump file

    I have dmp files generated using expdp on oracle 11g..
    expdp_schemas_18MAY2013_1.dmp
    expdp_schemas_18MAY2013_2.dmp
    expdp_schemas_18MAY2013_3.dmp
    Can I use a parameter file given below to get the table data in to the sql file or impdp the only option to load the table data in to database.
    vi test1.par
    USERID="/ as sysdba"
    DIRECTORY=DATA
    dumpfile=expdp_schemas_18MAY2013%S.dmp
    SCHEMAS=USER1,USER2
    LOGFILE=user_dump_data.log
    SQLFILE=user_dump_data.sql
    and impdp parfile=test1.par.

    Hi,
    To explain more about my situation.
    Target database has the dump files, where as the source database (cloud) doesn't have access to the target database.
    However, I can request the target DB DBA team to run the par files and provide me the output like a SQL file which I can take and run it in my source database.
    I got the metadata the same way, but is there any way I could get the data from the dump files on the target DB without actually accessing it? My question might sound weird, but please let me know.
    <
    1. export from the source into a dumpfile. You can do this on the source database and then copy the file over to your local database or you can do this from a local database if you have a database link defined on the local database that points to the source database.  In the second case, your dumpfile will be created on your local database.
    >
    How can i access the dump using the database link?

  • Need To Create a table in Sql Server and do some culculation into the table from Oracle and Sql

    Hello All,
    I'm moving a data from Oracle to Sql Server with ETL (80 tables with data) and i want to track the number of records that i moving on the daily basis , so i need to create a table in SQL Server, wilth 4 columns , Table name, OracleRowsCount, SqlRowCount,
    and Diff(OracleRowsCount - SqlRowCount) that will tell me the each table how many rows i have in Oracle, how many rows i have in SQL after ETL load, and different between them, something like that:
    Table Name  OracleRowsCount   SqlRowCount  Diff
    Customer                150                 150            
    0
    Sales                      2000                1998          
    2
    Devisions                 5                       5             
    0
    (I can add alot of SQL Tasks and variables per each table but it not seems logicly to do that, i tryid to find a way to deal with that in vb but i didn't find)
    What the simplest way to do it ?
    Thank you
    Best Regards
    Daniel

    Hi Daniel,
    According to your description, what you want is an indicator to show whether all the rows are inserted to the destination table. To achieve your goal, you can add a Row Count Transformation following the OLE DB Destination, and redirect bad rows to the Row
    Count Transformation. This way, we can get the count of the bad rows without redirecting these rows. Since the row count value is stored in a variable, we can create another string type variable to retrieve the row count value from the variable used by the
    Row Count Transformation, and then use a Send Mail Task to send the row count value in an email message body. You can also insert the row count value to the SQL Server table through Execute SQL Task. Then, you can check whether bad rows were generated in the
    package by querying this table.  
    Regards,
    Mike Yin
    TechNet Community Support

  • IDM with SQL server Error: Cannot find columns for the table...

    Hi all,
    I am Configuring IDM with SQL Server repository and ran into this error.
    'Cannot find columns for the table 'object'
    .....jdbc...[SQL Server]Invalid object name 'object'
    Can anybody please help me!!
    G

    Yes, permissions are very important. I ran into a similar problem because I didn't have the correct permissions. Make sure the user has the following permissions:
    CREATE ANY TABLE
    ALTER ANY TABLE
    DROP ANY TABLE
    CREATE ANY PROCEDURE
    EXECUTE ANY PROCEDURE
    DROP ANY PROCEDURE
    Also, make sure there is enough space in the default tablespace of that user.
    HTH
    ~Suvesh

  • Question on how to Hide the User Name, Password, and Domain fields in the MDT Wizard

    MDT 2012 U1
    Deploying Windows 7 via Offline Media (ISO) to MS Virtual PC's
    I am looking on how to Hide the User Name, Password, and Domain fields which are prepopulated in the MDT wizard via the CS.ini (Not so concerned about the Domain field as I am User Name and Password)
    We do need the Computer Name and OU fields to be seen, so skipping the wizard is not a option
    The client just does not want these fields to be seen by the end users, they dont want them to even know the account name used for adding the machine to the domain, of course the password is not displayed but it must not be displayed either.
    But since we use the fields they must still  be fuctional just not seen.
    Thanks.....
    If this post is helpful please click "Mark for answer", thanks! Kind regards

    You shouldn't have to edit DeployWiz_Definition_ENU.xml. You should only need to add "SkipAdminPassword=YES" to the CS.ini file and your authentication information.
    Example:
    [Settings]
    Priority=Default
    Properties=MyCustomProperty
    [Default]
    OSInstall=Y
    SkipCapture=NO
    SkipAdminPassword=YES
    UserID=<MyUserID>
    UserPassword=<MyPassword>
    UserDomain=<MyDomain.com>
    SkipProductKey=NO
    SkipComputerBackup=YES
    SkipBitLocker=NO
    -Nick O.
    Nick,
    SkipAdminPassword=YES is for:
    You can skip the Administrator Password wizard page by using this property in the
    customsettings.ini.
    I am hidding the Username/Password/and domain field in the computer name Wizard pane which is read from the cs.iniDomainAdmin=xxxxx
    DomainAdminPassword=xxxxx
    DomainAdminDomain=xxxxxx
    JoinDomain=xxxxxx
    If this post is helpful please click "Mark for answer", thanks! Kind regards

  • Is it possible to programmatically get the label name(s) of a VI's connector pane IPs and OPs?

    I can get the number of IPs & OPs using the metrics VI but not the variable names, any help much appreciated.
    Certified LabVIEW Architect

    You can get names of all controls and of all indicators. Use Get All Controls method of VI server.
    This is not exactly that you want but may be will help you.

  • Is it possible to pass a variable in FROM clause in SQL?

    Hi Experts,
    <i><b>loop at it_db_table.
    select field1 from it_db_table-table_name into my_it.
    endloop.</b></i>
    I mean, Is it pass a variable value to FROM clause in SQL?
    I got the info from SAP as,
    <i><b>Works like variants 1-3, provided the source_text varialb contains the table name or a join expression as ABAP source text.
    Examples
    Output of a list of all customers:
    DATA  tabname(10).
    DATA: BEGIN OF wa,
            id   TYPE scustom-id,
            name TYPE scustom-name,
          END OF wa.
    tabname = 'SCUSTOM'.
    SELECT id name INTO CORRESPONDING FIELDS OF wa FROM (tabname).
      WRITE: / wa-id, wa-name.
    ENDSELECT.</b></i>
    thanq.

    Here is a short sample of a dynamic select statement.
    Enter your table name in the parameter on selection screen. Enter you where clause in the select-option on selection screen.
    I used.....
    MARA
    MTART = 'HALB'
    report zrich_0004 .
    data: xwhere(30) type c.
    data: iwhere(30) type c occurs 0.
    data:itab(1000) type c occurs 0 with header line.
    parameters: p_table(30) type c.
    select-options: s_where for xwhere.
    loop at s_where.
      clear iwhere.
      xwhere = s_where-low.
      append xwhere to iwhere.
    endloop.
    select * up to 100 rows into table itab
              from (p_table)
                    where (iwhere).
    loop at itab.
      write:/ itab.
    endloop.
    Regards
    vasu

  • Dynamic pl sql cursor

    Hi.
    I've written a package with the intent of updating a number of fairly large tables.
    I'm using Oracle : 10.2.0
    the package has a main function called to update a set of tables.
    It loops through a table containing table names and column names (one on each row).
    It calls a second function for each (tablename,columnname) to ask it to update all the values in that table.column.
    This, in turn, calls my third 'calculate' function to recalculate the input table.column.
    It is running really slowly, as I wrote it in a 'find out how to do it' mode.
    The tables I am updating can have hundreds of thousands of rows.
    I reviewed some examples which recommended using bulk collect and forall to efficiently update a table.
    My question - it isn't clear if I can do this if the update of a field is accomplished by calling my third pl/sql function which
    resides in the package I am working in.
    summary:
    have a table with 3 columns: tablename, columnname and an 'in use' column (not previously mentioned).
    I loop through this table, and with each tablename/columname, I feed the data into a second function.
    this second function updates the table via a cursor, invoking a third function that calculates the new value.
    it is so slow.
    Is bulk collection/forall a workable approach to repopulating such a set of tables. If so I'll go pursue the details.
    If not, what is a recommended approach.
    I can post some code but it is just gross.
    Thanks
    Jeff

    Thanks for the suggestions.
    This is a one time system modification, part of a larger reorganization. Because the rest of the reorganization is
    going to take alot of time, I need to minimize the time this update process takes.
    My requirement is that I update a number of columns in a number of tables - which tables / columns are due
    to be updated are determined via a complex analysis.
    I already have finished the analysis and code that figures out what tables and columns need updating.
    This code populates a table that contains a column for tablename and a column for columname.
    Each row in this table represent a table and column that need recalculating.
    So now at runtime, I need to iterate through this table, and get the target table/column which required updating.
    For each iteration I need to 'open' the table, read all the rows and update the target column.
    The update is a fairly complex piece of parsing and analysis, so it is encapsulated in a function in my package.
    Therefore, my quest was to figure out if bulk collect was a reasonable/possible way to update the tables at runtime.
    I saw this code on the internet at
    {noformat}
    http://www.dba-oracle.com/plsql/t_plsql_dynamic.htm
    {noformat}
    as an example, and noticed that I seem to need to know the target table in a 'static' manner,
    i.e. the bulk collect into 'parameter' which is of a type declared for a given table
    so I can have a rowtype variable to stuff the data into from the bulk collect.
    DECLARE
      TYPE t_object_id_tab IS TABLE OF bulk_collect_test.object_id%TYPE;
      l_tab   t_object_id_tab;
    BEGIN
      -- Populate collection use in forall.
      SELECT object_id
      BULK COLLECT INTO l_tab
      FROM   bulk_collect_test
      WHERE  rownum < 101;
      FORALL i IN l_tab.first .. l_tab.last
        EXECUTE IMMEDIATE
          'UPDATE bulk_collect_test
           SET    object_id = object_id
           WHERE  object_id = :1'
           USING l_tab(i);
    END;
    /jeff

Maybe you are looking for

  • Copy and Paste from Excel

    I am trying to copy and paste a two column table in Excel into a two column table in Dreamweaver. The data seems to paste into the table with different kinds of problems depending on how I try to paste... text without formatting, etc. Never pastes co

  • 64-bit WLS 11G for Solaris?

    I can not locate the 64-bit version of WLS 11G for Solaris. When I go to the download page all I see are 32-bit versions (at least they look like 32-bit version as denoted by the filenames such as wls1031_solaris32.bin). I have attempted to go throug

  • Cover Flow has disappeared!

    hi everyone. ok, So i couldn't run Sharepod with my ipod, so i deleted the 'ArtworkDB' file from my ipod directory (big mistake not backing that file up like usually would) NOW ALL THE ARTWORK ON MY IPOD HAS VANISHED! over 400 hundred albums GONE!!!!

  • About 64 & 32 bit

    hey there, how do I know that my Intel-based iMac is using 32 or 64 OSX?

  • Option to save a control in PC 10.0

    Dear Experts, When I try to save a control (Local Control) the Option is not highlighted and an option submit is appearing. Could anyone explain what could be configuration to get the save option directly instead of submitting it. (Even when I try to