How to pass dynamically table name in my cursor declaration

Hi:
I am new. could you please let me know how to pass a table name dynamically in my cursor declaration? for instance I am declaring the following cursor in my pl/sql procedure:
CURSOR crs_validate IS
select * FROM <ACT_JUN_2006_LOB>;
this ACT_JUN_2006_LOB table name, I should able to pass it when I open the cursor ... any help appreciated. thanks.
srini

Thanks all for the response. REFCURSOR does work: here is an example ... which I found on-line
procedure emp_test(
month varchar2,
year varchar2)
is
type cur_typ is ref cursor;
c cur_typ;
query_str varchar2(200);
emp_number number := 7900;
salary number;
name varchar2(30);
Begin
query_str := 'Select empno, ename, sal from emp_' || month ||'_'||year
|| ' where empno = :id';
open c for query_str using emp_number;
loop
fetch c into emp_number, name, salary;
exit when c%notfound;
dbms_output.put_line(emp_number);
end loop;
close c;
end;

Similar Messages

  • Passing dynamic table name in ADO. net destination

    I am new to SSIS and I have a requirement where i need to pass dynamic table name in ADO .net destination .
    My package contains an "Execute Sql task" in the control flow which computes the destination table name to be provided at run time and stores it in a variable expression
    "@[User::Table_name]"(which has a scope of full package). 
    Now, the problem I'm facing right now is that , I am unable to use this variable expression in the ADO .Net Destination .
    I need to pass this variable expression as the table name in ado .net destination.
    But, whenever I use this variable in place as the table name I keep on getting this error and my package fails:- 
    [ADO NET Destination [403]] Error: The Table or View name is not expected. \n\t If you are quoting the table name, please use the prefix " and the suffix " of your selected data provider for quotation. \n\t If you are using multipart name,
    please use at most three parts for the table name. 
    Although ,I am able to run my package when i am providing the existing(static) table name.So there is nothing wrong with the  package.
    Tried a lot of things still not working..Please help...

    I am having the result stored in the variable expression . I just need a way to be able to use it as the Destination table in ADO .net Destination.
    I am not sure if this will work for you, but I am able to store the table name in variable and use it dynamically (via data flow task expression property ) as shown.
    Thanks, hsbal
    Hi Adeep,
    Based on my further research, just as hsbal said, we can set a variable as ADO.NET Destination table via Expressions property in Data Flow Task.
    If there are any other questions, please feel free to ask.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • How to pass Dynamic Table(s) to FM

    Hello All i hv an requirement in which i need to process a block of code recursively. right now i am trying to do the same with Subroutine but its hard i know. I have an option to use FM instead but i am not sure if we can pass dynamic tables to FM, so is there anybody who had solution for the same. otherwise i can use it using TOP include to declare dynamic table in comon arae as im calling it from another FM(RFC) but i  dont want to use that as it will consume more memory.
    So i have 2 question
    1. should i use FM instead of subroutine for recursive operation if yes how can know if i reached the maximum alloted size of memory for a program. is there any FM which can tell me about the memory used or somethign like that so that i can avoid any ABAP dump.
    2.how can i pass dynamic tables as input to parameters.
    Note : i allready seen https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/f50dcd4e-0501-0010-3596-b686a7b51492

    Hello Mani
    Perhaps the sample report ZUS_SDN_TABLE_READ_VIA_RFC_XML in thread
    How to return back a structure of dynamic tables in a Function Module
    might be a useful approach for you.
    Regards
      Uwe

  • How to set dynamic table name in sql query?

    I want set dynamic table name by parameter in sql query,just like:
    select * from :tbname
    but run report is error,BI P report table name is invalidation.
    What can i do? Thanks!

    Hi,
    that's only possible inside a data template with a lexical parameter.
    Regards
    Rainer

  • 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);

  • How to pass the Dynamically table name and RELID in IMPORT  x TO y FROM DATABASE dbtab(ar) ID Key

    Hello Expert,
    I wanted to know is there any way through which we can dynamically pass the table name in IMPORT condition.
    For e.g.
    DATA : PCLT TYPE DD03L-TABNAME.
    DATA: SET_RELID TYPE T52RELID-RELID.
    DATA: key TYPE PCLKEY.
    DATA: text_version TYPE PVRSN.
    DATA: BEGIN OF ptext OCCURS 132.
    DATA: line(132).
    DATA: END OF ptext.
    SET_RELID = 'TX'.
    PCLT = 'PCL1'.
    KEY = '00001000004005     9999123119960101000'.
    TEXT_VERSION = '01'.
    IMPORT TEXT_VERSION PTEXT FROM DATABASE <PCLT>(<SET_RELID>) ID KEY.
    If i use this then it gives me error message "The Dictionary structure or table "<PCLT>" is either not active or does not exist."
    Kindly help me in this matter.
    Thanks
    Srikanth

    Hi Srikanth
    I dont know if there is another solution, but this is what i did using a dynamic subroutine, please check it
    just add this lines to your code
    DATA: prog  TYPE c LENGTH 8,
           mess TYPE string,
           sid  TYPE string,
           wrd  TYPE string,
           dir  TYPE trdir,
           OFF(3).
    DATA: lt_code TYPE TABLE OF rssource-line.
    DATA: ls_code TYPE rssource-line.
    perform call_import using pclt set_relid key.
    form call_import USING p_pclt p_set_relid p_key.
       ls_code = 'PROGRAM SUBPOOL.'.
       append ls_code to lt_code.
       ls_code = 'form get_text tables ptext using p_key changing text_version.'.
       append ls_code to lt_code.
       ls_code = 'IMPORT text_version ptext from database'.
       append ls_code to lt_code.
       concatenate p_pclt '(' p_set_relid ')' into ls_code.
       append ls_code to lt_code.
       ls_code = 'id p_key.'.
       append ls_code to lt_code.
       ls_code = 'endform.'.
       append ls_code to lt_code.
       generate subroutine pool lt_code
                           name prog
                           message mess
                           SHORTDUMP-ID sid
                           WORD WRD
                           OFFSET OFF.
       IF SY-SUBRC EQ 0.
         perform GET_TEXT IN PROGRAM (prog) tables ptext
                                              USING p_key
                                              CHANGING text_version .
       ENDIF.
    endform.
    Hope this help
    Regards
    MC

  • Dynamic table name in native sql query

    Can i pass a dynamic table name in this query ---
                EXEC SQL PERFORMING APPEND_MTO.
                  SELECT          
                               LTOG_QUANTITY_TYPE,
                               FCONO,
                              WBSELEMENT,
                             PROJECT
                  INTO   :IMTO
                  FROM  RWORKS.MTO_ISO_V2
                  WHERE LTOD_DATE > TO_DATE(:MAXD,'YYYYMMDDHH24MISS')
                ENDEXEC.
    How can i pass this table name RWORKS.MTO_ISO_V2  dynamically in the query
    Edited by: Madhukar Shetty on Nov 26, 2009 2:40 PM

    Can i pass a dynamic table name in this query ---
                EXEC SQL PERFORMING APPEND_MTO.
                  SELECT          
                               LTOG_QUANTITY_TYPE,
                               FCONO,
                              WBSELEMENT,
                             PROJECT
                  INTO   :IMTO
                  FROM  RWORKS.MTO_ISO_V2
                  WHERE LTOD_DATE > TO_DATE(:MAXD,'YYYYMMDDHH24MISS')
                ENDEXEC.
    How can i pass this table name RWORKS.MTO_ISO_V2  dynamically in the query
    Edited by: Madhukar Shetty on Nov 26, 2009 2:40 PM

  • How to get the table name in the trigger definition without hard coding.

    CREATE  TRIGGER db.mytablename
    AFTER UPDATE,INSERT
    AS
        INSERT INTO table1(col1)
        SELECT InsRec.col1   
        FROM
        INSERTED Ins
       --Below i am calling one sp for which i have to pass the table name
       EXEC myspname 'tablename'
      In the above trigger,presently i am hard coding the tablename
      but is it possible to get the table name dynamically on which the trigger is defined in order to avoid hard coding the table name

    I really liked your audit table concept.  You inspired me to modify it so that, the entire recordset gets captured and added a couple of other fields.  Wanted to share my end result.
    USE [YourDB]
    GO
    /****** Object: Trigger [dbo].[iudt_AutoAuditChanges] Script Date: 10/18/2013 12:49:55 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER TRIGGER [dbo].[iudt_AutoAuditChanges]
    ON [dbo].[YourTable]
    AFTER INSERT,DELETE,UPDATE
    AS
    BEGIN
    SET NOCOUNT ON;
    Declare @v_AuditID bigint
    IF OBJECT_ID('dbo.AutoAudit','U') IS NULL BEGIN
    CREATE TABLE [dbo].[AutoAudit]
    ( [AuditID] bigint identity,
    [AuditDate] DateTime,
    [AuditUserName] varchar(128),
    [TableName] varchar(128) NULL,
    [OldContent] XML NULL,
    [NewContent] XML NULL
    ALTER TABLE dbo.AutoAudit ADD CONSTRAINT
    PK_AutoAudit PRIMARY KEY CLUSTERED
    [AuditID]
    ) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    CREATE NONCLUSTERED INDEX [idx_AutoAudit_TableName_AuditDate] ON [dbo].[AutoAudit]
    ( [TableName] ASC,
    [AuditDate] ASC
    )WITH (STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    END
    Select * Into #AuditDeleted from deleted
    Select * Into #AuditInserted from inserted
    While (Select COUNT(*) from #AuditDeleted) > 0 OR (Select COUNT(*) from #AuditInserted) > 0
    Begin
    INSERT INTO [dbo].[AutoAudit]
    ( [AuditDate], [AuditUserName], [TableName], [OldContent], [NewContent])
    SELECT
    GETDATE(),
    SUSER_NAME(),
    [TableName]=object_name([parent_obj]),
    [OldContent]=CAST((SELECT TOP 1 * FROM #AuditDeleted D FOR XML RAW) AS XML),
    [NewContent]=CAST((SELECT TOP 1 * FROM #AuditInserted I FOR XML RAW) AS XML)
    FROM sysobjects
    WHERE
    [xtype] = 'tr'
    and [name] = OBJECT_NAME(@@PROCID)
    Set @v_AuditID = SCOPE_IDENTITY()
    Delete from AutoAudit
    Where AuditID = @v_AuditID
    AND Convert(varchar(max),oldContent) = Convert(varchar(max),NewContent)
    Delete top(1) from #AuditDeleted
    Delete top(1) from #AuditInserted
    End
    END

  • How to pass dynamic filename to Receiver JMS channel

    Hi experts,
    I want to pass the dynamic filename to receiver JMS message Properties.
    for example
    I am passing directory name via adapter module AF_Modules/DynamicConfigurationBean with key and value combination like below. How to pass dynamic filename value to a dynamic property ( say DCJMSMessageProperty1)
    eg.
    key.0 - >insert http://sap.com/xi/XI/System/JMS DCJMSMessageProperty0
    value.0 - >  testdirectory ( which is static value)
    Note: Im have not created any ESR object . i just have to bypass the file to a jms queue. I have used AAE integrated configuration scenario ( file to jms )
    Regards,
    Balaji
    Edited by: Balaji Pichaimuthu on Jan 27, 2011 4:45 PM
    Edited by: Balaji Pichaimuthu on Jan 27, 2011 4:46 PM

    Already given link for the dynamic configuration code snippet in the earlier reply... Below is the code snippet
    Note: Use Adapter Specific Message Attributes for the target Communication Channel(CC).Check the indicator for filename in the advanced tab of CC
    //UDF code
    String filename="";
    String NameSpace = "http:/"+"/sap.com/xi/XI/System/JMS";
    try{
          DynamicConfiguration conf = (DynamicConfiguration) param.get(
            StreamTransformationConstants.DYNAMIC_CONFIGURATION);
          DynamicConfigurationKey key  =  DynamicConfigurationKey.create( "http://sap.com/xi/XI/System/File",   "FileName");
           // read filename value
           filename = conf.get(key);     
          // So far we extracted filename value .. now do your logic  something like this...
          DynamicConfigurationKey key2 = DynamicConfigurationKey.create(NameSpace,"yourjmsvalue goes here");
           conf.put(key2,filename);
         } catch(Exception e){

  • Dynamic table name in native SQL

    Hi,
    How can i use dynamic table name in native SQL?
    My req is to select data from a external database table , but the table name will be only poulated during runtime.
    How can i acheive this?
    Regards,
    Arun.

    It should work OK - see demo below.
    Jonathan
    report zsdn_jc_adbc_test.
    start-of-selection.
      perform demo_lookup.
    form demo_lookup.
      data:
        l_error_msg          type string,
        ls_t001              type t001, "Company
        ls_t003              type t003. "Doc types
      perform dynamic_lookup
        using
          'T001'
        changing
          ls_t001
          l_error_msg.
      write: / l_error_msg.
      perform dynamic_lookup
        using
          'T003'
        changing
          ls_t003
          l_error_msg.
      write: / l_error_msg.
    endform.
    form dynamic_lookup
      using
        i_tabname            type tabname
      changing
        os_data              type any
        o_error_msg          type string.
    * Use ADBC to select data
      data:
        l_mandt_ref          type ref to data,
        l_result_ref         type ref to data,
        l_mandt              type symandt,
        l_tabname            type tabname,
        l_sql_statement      type string,
        lo_cx_root           type ref to cx_root,
        lo_cx_sql            type ref to cx_sql_exception,
        lo_connection        type ref to cl_sql_connection,
        lo_statement         type ref to cl_sql_statement,
        lo_result_set        type ref to cl_sql_result_set.
      clear: os_data, o_error_msg.
      get reference of l_mandt into l_mandt_ref.
      get reference of os_data into l_result_ref.
      l_mandt   = '222'.   "i.e. select from client 222
      l_tabname = i_tabname.
      try.
          lo_connection = cl_sql_connection=>get_connection( ).
          lo_statement  = lo_connection->create_statement( ).
    * Set criteria for select:
          lo_statement->set_param( l_mandt_ref ).
          concatenate
            'select * from' l_tabname
            'where mandt = ?'
            into l_sql_statement separated by space.
    * Execute
          call method lo_statement->execute_query
            exporting
              statement   = l_sql_statement
              hold_cursor = space
            receiving
              result_set  = lo_result_set.
    * Get the data from the resultset.
          lo_result_set->set_param_struct( l_result_ref ).
          while lo_result_set->next( ) > 0.
            write: / os_data.
          endwhile.
    * Tidy up:
          lo_result_set->close( ).
          lo_connection->close( ).
        catch cx_sql_exception into lo_cx_sql.
          o_error_msg = lo_cx_sql->get_text( ).
        catch cx_root into lo_cx_root.
          o_error_msg = lo_cx_root->get_text( ).
      endtry.
    endform.

  • Dynamic table name - error

    After run (or test) of procedure
    create or replace procedure tmp_select_dymanic
    ( AInTable IN VARCHAR2,
    ACount OUT NUMBER
    ) as
    begin
    EXECUTE IMMEDIATE 'BEGIN SELECT count(*) INTO :Count FROM :InTable END;'
    USING ACount, AInTable;
    end tmp_select_dymanic;
    error message: invalid table name.
    I know the table exists and contains data. I can make SELECT in SQL (not dynamic).
    What a reason for error? May be privileges in database? But i make SELECT on my own table?
    How can i set dynamic table name in other way?
    My Oracle Version 10g.

    What you are asking can be done by REF_CURSOR;
    look this example and try your self the rest:
    CREATE OR REPLACE PROCEDURE insert_to_table_dinamic (
       table1   IN   VARCHAR2,
       table2   IN   VARCHAR2
    AS
       rc         sys_refcursor;
       v_sql      VARCHAR2 (2000);
       v_deptno   NUMBER;
    BEGIN
       v_sql :=
             'SELECT DEPTNO FROM '
          || table1
          || ' WHERE ROWNUM = 1 AND DEPTNO IS NOT NULL';
       OPEN rc FOR v_sql;
       LOOP
          FETCH rc
           INTO v_deptno;
          EXIT WHEN rc%NOTFOUND;
          v_sql :=
                'UPDATE '
             || table2
             || ' SET DEPTNO = '
             || v_deptno
             || ' WHERE DEPTNO IS NULL';
          EXECUTE IMMEDIATE v_sql;
       END LOOP;
    EXCEPTION
       WHEN OTHERS
       THEN
          DBMS_OUTPUT.put_line (SQLCODE || SQLERRM);
    END insert_to_table_dinamic;when i give DEPT , EMP as my 2 parameters above code will set the deptno in EMP table where deptno is null;
    --Just a test proc.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Dynamic table name from Arguments in cfquery /

    I'm trying to use dynamic table names in a cfc but seem to
    have hit upon a wall as my calling methods from flash keep hitting
    my _error methods - Code attached to show what I'm trying to
    achieve; if anyone can give me some pointers it would be a great
    help. I've seen numerous by using the Form with the arguments but
    this is coming into a gateway used by a flash component and doesn't
    work no matter how much I fiddle the code.
    Thanks in advance

    There was a time when I needed a dynamic query such as this.
    BUT, it is very dangerous, which is why I took a few steps to make
    it more secure.
    1. Always use cfqueryparam and strict datatyping
    2. Use listFindNoCase for known table names in the database
    e.g
    <cfset variables.tableNames =
    "items,products,categories,blog" />
    <cfif
    listContainsNoCase(variables.tableNames,lCase(trim(arguments.tableName)),",")>
    query here
    <cfelse>
    Error: Unknown table requested
    </cfif>
    Mikey

  • How to pass a table as parameter on a stored procedure

    Hello all,
    I want to pass the name of a table as parameter into a stored procedure, that will be used for cursors etc.
    But when i pass the parameter and i compile the S.P. it give me error (error: table not existing...)
    Any Help?
    Thanks in advance, Marco

    Marco wrote:
    As i've written above, i'm using stored procedures like 'batch' programs which will be executed with oracle scheduler (passing to s.p. the name of the 'input' tables)
    These input tables are 'external' tables which have got the same structure; for example i've got TABLEX_001, TABLEX_002, XXTAB etc. with the same structure.
    This is the the reason... what do you think?An external table definition can reference multiple files via the LOCATION definition or you can user "ALTER TABLE" to alter the location and change the file that the external table points to.
    Thus you only need one static External Table and use an alter table (via execute immediate) to change the file location it points to, or if you want all the data together, just specify all the files in the location.
    That would be clean design, using one fixed table, without the need to pass any table names, just dynamically altering the file names if necessary at run time.

  • How to create Dynamic Table Control

    Hi
    How to create Dynamic Table control , The field names and values to be displayed in table control are to be fetched from Add-on Tables.
    Regards
    Prasath

    Hi Jonathan,
    Actually the columns to be displayed are not constant . It will be increased based on the database values, Anyhow it will not exceed 100.
    Please confirm my understanding.
    1. In this case I have to create 100 custom columns and make it visible / invisible based on my requirement and I can set the title at runtime.
    2. How can i assosicate / reassociate the datadictionary reference for the columns that i use. Because I need to show the search help values for the
    dynamic columns.
    Your opinion on this will be helpful.
    Regards
    Prasath

  • How to get source table name

    Hi,
    I need to know how get a source table name. I need to get a source table name and do some transformation. I am adding the step in IKM to do this and therefore need source table name in there.
    <%=odiRef.getSrcTablesList("","[RES_NAME]","","")%> gives work table name (C$_0XXXXX) whereas actual source table name is expected.
    Could someone please help?
    Thanks.

    Hi,
    May i add a point?
    In IKM level, if u use this API it will always return u C$ table name only since for IKM C$ is the source. You need to capture and use this API in LKM level.
    In LKM add a step in Command on target and technology as Jython and try the below code.
    mySourceTable= '<%=odiRef.getSrcTablesList("", "[RES_NAME]", ", ", "")%>'
    And later in IKM use this variable for ur transformation.
    Thanks,
    Guru

Maybe you are looking for

  • Error after deploying BPM Process due to VC-TaskUI

    Hello, i'm trying to run a successfully deployed BPM Process with one Task created in Visual Composer. The task is consuming a Webservice from the ESWorplace. The task appears in the UWL, when I click it, this error message comes: (The error only app

  • Photoshop Elments 3 Organizer vs. Photoshop Album 2

    Hi Leute, ich wollte mal fragen, ob mir jemand Infos geben kann, was an dem Organizer in Photoshop Elements 3 anders/besser ist als Photoshop Album 2. Danke Im Vorraus

  • IE and the back-button

    Hi all... I've used JHeadstart 10.1.2 to build a fairly simple UIX based web application. This application is completely a read-only view of some data, layed out as master-detail-detail over a few screens. As such, I followed the directions in the JH

  • Save for Web crashing Photoshop Elements 11!

    I am trying to get some images ready for my work who is developing an app. I am trying to save the images and pages for web 'Save for Web', however whenever I click save it crashing the entire programme. Has anyone else had this or does anyone know h

  • Forum sign in on iphone

    I suddenly can't sign onto any forums with my iphone. The page refresshes without logging me in. It recognises that the username and password are correct, as i've tried incorrect ones and i get the message that they are wrong.