Dynamic SQL substituting dynamic table name with slct statement having date

Hello,
I just wanted some help with the following PL block. My problem is whenever I try to run this block it ask for invoking values for 2 substitute variables, though no substitute variables present in the code. Please find the code below:
Declare
cursor C_1 is
select unique table_name from gsi_daily_count;
table_names varchar2(240);
Begin
Open C_1;
Loop
Fetch C_1 into table_names;
EXIT WHEN C_1%NOTFOUND;
EXECUTE IMMEDIATE' select last_extract_date,
to_char(min(greatest(nvl(last_update_date,'||01-Jan-10||'),nvl(program_update_date,'||01-Jan-10||'))),'||DD-MON-YY HH24:MI:SS||') mi,
to_char(max(greatest(nvl(last_update_date,'||01-Jan-10||'),nvl(program_update_date,'||01-Jan-10||'))),'||DD-MON-YY HH24:MI:SS||') ma
from' || table_names ||'
group by last_extract_date
order by last_extract_date desc';
End Loop;
Close C_1;
COMMIT;
End;
Please help.
Thanks in advance.

You cannot specify your dates the way you have since they are being intepreted as bind variables:
Try this:
Declare
  cursor C_1 is
    select unique table_name
    from gsi_daily_count;
    table_names varchar2(240);
Begin
  Open C_1;
  Loop
    Fetch C_1 into table_names;
    EXIT WHEN C_1%NOTFOUND;
    EXECUTE IMMEDIATE' select last_extract_date,
                              to_char(
                                      min(
                                            greatest(
                                                      nvl(last_update_date,to_date('''|| '01-Jan-10' ||''',''dd-Mon-yy''))
                                                     ,nvl(program_update_date,to_date('''|| '01-Jan-10' ||''',''dd-Mon-yy''))
                                         ),''DD-MON-YY HH24:MI:SS''
                                     ) mi
                              to_char(
                                      max(
                                            greatest(
                                                      nvl(last_update_date,to_date('''|| '01-Jan-10' ||''',''dd-Mon-yy''))
                                                     ,nvl(program_update_date,to_date('''|| '01-Jan-10' ||''',''dd-Mon-yy''))
                                         ),''DD-MON-YY HH24:MI:SS''
                                     ) ma
                      from ' || table_names ||'
                      group by last_extract_date
                      order by last_extract_date desc';
  End Loop;
  Close C_1;
  COMMIT;
End;
/ There is not way for me to test this, so you may have to play around with all the quotes!

Similar Messages

  • How to find the column name and table name with a value

    Hi All
    How to find the column name and table name with "Value".
    For Example i have value named "Srikkanth" This value will be stored in one table and in one column i we dont know the table how to find the table name and column name
    Any help is highly appricatable
    Thanks & Regards
    Srikkanth.M

    2 solutions by Michaels (the latter is 11g upwards only)...
    michaels>  var val varchar2(5)
    michaels>  exec :val := 'as'
    PL/SQL procedure successfully completed.
    michaels>  select distinct substr (:val, 1, 11) "Searchword",
                    substr (table_name, 1, 14) "Table",
                    substr (t.column_value.getstringval (), 1, 50) "Column/Value"
               from cols,
                    table
                       (xmlsequence
                           (dbms_xmlgen.getxmltype ('select ' || column_name
                                                    || ' from ' || table_name
                                                    || ' where upper('
                                                    || column_name
                                                    || ') like upper(''%' || :val
                                                    || '%'')'
                                                   ).extract ('ROWSET/ROW/*')
                       ) t
    --        where table_name in ('EMPLOYEES', 'JOB_HISTORY', 'DEPARTMENTS')
           order by "Table"or
    SQL> select table_name,
           column_name,
           :search_string search_string,
           result
      from cols,
           xmltable(('ora:view("'||table_name||'")/ROW/'||column_name||'[ora:contains(text(),"%'|| :search_string || '%") > 0]')
           columns result varchar2(10) path '.'
    where table_name in ('EMP', 'DEPT')
    TABLE_NAME           COLUMN_NAME          SEARCH_STRING        RESULT   
    DEPT                 DNAME                ES                   RESEARCH 
    DEPT                 DNAME                ES                   SALES    
    EMP                  ENAME                ES                   JONES    
    EMP                  ENAME                ES                   JAMES    
    EMP                  JOB                  ES                   SALESMAN 
    EMP                  JOB                  ES                   SALESMAN 
    EMP                  JOB                  ES                   SALESMAN 
    EMP                  JOB                  ES                   PRESIDENT
    EMP                  JOB                  ES                   SALESMAN 
    9 rows selected.

  • How to use bind variable value for table name in select statement.

    Hi everyone,
    I am having tough time to use value of bind variable for table name in select statement. I tried &p37_table_name. ,
    :p37_table_name or v('p37_table_name) but none worked.
    Following is the sql for interactive report:
    select * from v('p37_table_name') where key_loc = :P37_KEY_LOC and
    to_char(inspection_dte,'mm/dd/yyyy') = :P37_INSP_DT AND :p37_column_name is not null ;
    I am setting value of p37_table_name in previous page which is atm_state_day_insp.
    Following is error msg:
    "Query cannot be parsed, please check the syntax of your query. (ORA-00933: SQL command not properly ended) "
    Any help would be higly appreciated.
    Raj

    Interestingly enough I always had the same impression that you had to use a function to do this but found out from someone else that all you need to do is change the radio button from Use Query-Specific Column Names and Validate Query to Use Generic Column Names (parse query at runtime only). Apex will substitute your bind variable for you at run-time (something you can't normally do in pl/sql without using dynamic sql)

  • Problem while displaying all the table names from a MS Access Data Source.

    I started preparing a small Database application. I want to display all the Table Names which are in the 'MS Access' Data Source.
    I started to executing by "Select * from Tab" as if in SQL.
    But i got an error saying that "Not able to resolve Symbol 'Tab' in the query".
    Please let me know how can i display all the table Names in the MS Access Dats Source.

    Here i am developing the application in Swing using JDBC for accessing the database.
    I want to display all the Table names from the data source in a ListBox for easy selection of tables to view their details.

  • Query for retreiving table names that have the same data

    Hi,
    Does anybody know how to retreive all the table names that have the same data in their respective tables but i dont know the table names or its fields. Is there any possible query to perform this action???
    Thanks in Advance,
    Balaji.

    What about...
    WITH manager_list AS
    SELECT name,
            LTRIM(MAX(SYS_CONNECT_BY_PATH(id,','))
            KEEP (DENSE_RANK LAST ORDER BY curr),',') AS employees
    FROM   (SELECT m.name,
                    e.id,
                    ROW_NUMBER() OVER (PARTITION BY m.name ORDER BY e.id) AS curr,
                    ROW_NUMBER() OVER (PARTITION BY m.name ORDER BY e.id) -1 AS prev
             FROM   manager m,
                    join_table jt,
                    employee e
      WHERE m.id           = jt.manager_id
      AND   jt.employee_id = e.id
      AND   m.name = :P_MANAGER)
      GROUP BY name
      CONNECT BY prev = PRIOR curr AND name = PRIOR name
      START WITH curr = 1
    ), all_list AS
    SELECT name,
            LTRIM(MAX(SYS_CONNECT_BY_PATH(id,','))
            KEEP (DENSE_RANK LAST ORDER BY curr),',') AS employees
    FROM   (SELECT m.name,
                    e.id,
                    ROW_NUMBER() OVER (PARTITION BY m.name ORDER BY e.id) AS curr,
                    ROW_NUMBER() OVER (PARTITION BY m.name ORDER BY e.id) -1 AS prev
             FROM   manager m,
                    join_table jt,
                    employee e
      WHERE m.id           = jt.manager_id
      AND   jt.employee_id = e.id)
      GROUP BY name
      CONNECT BY prev = PRIOR curr AND name = PRIOR name
      START WITH curr = 1
    SELECT a.*
    FROM   manager_list m,
           all_list a
    WHERE  m.employees = a.employeesWould be easier in 11g, but I don't have an installation here so this is based on 10g.
    Cheers
    Ben

  • SQL-error "-955-Duplicate name" in DDL statement

    Hi!
    During upgrade preparations (PREPARE) i got follwing problem activating a table TAREF in SOLMAN32/MaxDB 7.5
    estos100:smpadm 79> more MVNTTOOL.ELG
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    MVNTABS errors and RETURN CODE in P060227.SMP
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    2EETP345 22:16:03: Retcode 1024: SQL-error "-955-Duplicate name" in DDL statement for "TAREF
    2EETP345                   "
    2EETP334 22:16:03: error in DDL, nametab for "TAREF" not activated
    1 ETP111 exit code           : "8"
    estos100:smpadm 80>
    When looking from the ABAP perspective (se14 -> table "TAREF" -> Indexes) I see that the table has two indexes:  
    "0   X   Primary index"
    "1   X   Index on Object Type".
    When looking at details for "index 1" it says "does not exist in database". 
    How do I solve this ABAP dictionary inconsistancy?
    Regards,
    Fredrik
    Message was edited by: Fredrik  Rosengren

    Hi Fredrik,
    please open an OSS message for your issue.
    Kind regards,
    Roland

  • Whats the fieldname and table name for purchase order delivery date

    hi all,
        whats the fieldname and table name for purchase order delivery date
      thanks and regrads

    EKET-EINDT is the delivery date according to the schedule lines.
    for example the line item has 100 qty.
    it is sent in three schedules (40, 40, 20).
    Then EKET will have 3 records for one PO Line item.
    The final delievry data is the EKET-EINDT for the 3rd schedule line item.
    Regards,
    Ravi

  • Table name in which return item data is stored of a PO

    Can some please specify the table name in which return item data is stored of a PO?
    Thanks in advance;

    Hi,
    Let me explain what exactly I need. In a PO there is a checkbox "Retun Item". If we check that checkbox for an item that item becomes a retun item.
    I need to fetch all the data of this return Item. The commitment data goes to table COOI but this return item records doesn't get stored in COOI table. I need all the data of this entry including the Network Activity, Project, WBS element etc.
    Please let me know if you could help me.
    Thanks.

  • Strange results with Insert statement having select query

    Hi all,
    I am facing a strange issue with Insert statement based on a select query having multiple joins.
    DB- Oracle 10g
    Following is the layout of my query -
    Insert into Table X
    Select distinct Col1, Col2, Col3, Col4, Function(Col 5) from Table A, B
    where trunc(updated_date) > = trunc(sysdate-3)
    and join conditions for A, B
    Union
    Select Col1, Col2, Col3, Col4, Function(Col 5) from Table C, D
    trunc(updated_date) > = trunc(sysdate-3)
    and join conditions for C, D
    Union
    .... till 4 unions. all tables are residing in the local Database and not having records more than 50,000.
    If I execute above insert in a DBMS job, it results into suppose 50 records where as if I execute the select query it gives 56 records.
    We observed following things-
    a) no issue with size of tablespace
    b) no error while inserting
    c) since query takes lot of time so we have not used Cursor and PLSQL block for inserting.
    d) this discrepancy in number of records happens frequently but not everytime.
    e) examined the records left out from the insert, there we couldn't find any specific pattern.
    f) there is no constraint on the table X in which we are trying to insert. Also tables A, B, C....
    I went through this thread -SQL insert with select statement having strange results but mainly users are having either DB Links or comparison of literal dates, in my case there is none.
    Can somebody explain why is the discrepancy and what is the solution for it.
    Or atleast some pointers how to proceed with the analysis.
    Edited by: Pramod Verma on Mar 5, 2013 4:59 AM
    Updated query and added more details

    >
    Since I am using Trunc() in the where clause so timing should not matter much. Also I manually ruled out records which were updated after the job run.
    >
    The first rule of troubleshooting is to not let your personal opinion get in the way of finding out what is wrong.
    Actually this code, and the process it represents, is the most likely CAUSE of the problem.
    >
    where trunc(updated_date) > = trunc(sysdate-3)
    >
    You CANNOT reliably use columns like UPDATED_DATE to select records for processing. Your process is flawed.
    The value of that column is NOT the date/time that the data was actually committed; it is the date/time that the row was populated.
    If you insert a row into a table right now, using SYSDATE (8am on 3/5/2013) and don't commit that row until April your process will NEVER see that 3/5/2013 date until April.
    Here is the more typical scenario that I see all the time.
    1. Data is inserted/updated all day long on 3/4/2013.
    2. A column, for example UPDATED_DATE is given a value of SYSDATE (3/4/2013) in a query or by a trigger on the table.
    3. The insert/update query takes place at 11:55 PM - so the SYSDATE values are for THE DAY THE QUERY BEGAN
    4. The data pull begins at 12:05 am (on 3/5/2013 - just after midnight)
    5. The transaction is COMMITTED at 12:10 AM (on 3/5/2013); 5 minutes after the data pull began.
    That data extract in step 4 will NEVER see those records! They DO NOT EXIST when the data pull query is executed since they haven't been committed.
    Even worse, the next nights data pull will not see them either! That is because the next pull will pull data for 3/5/2013 but those records have a date of 3/4/2013. They will never get processed.
    >
    Job timing is 4am and 10pm EST
    >
    Another wrinkle is when data is inserted/updated from different timezones and the UPDATED_DATE value is from the CLIENT pc or server. Then you can get even more data missed since the client dates may be hours different than the server date used for the data pull process.
    DO NOT try to use UPDATED_DATE type columns to do delta extraction or you can have this issue.

  • Dynamic SQL Joining between tables and Primary keys being configured within master tables

    Team , Thanks for your help in advance !
    I'm looking out to code a dynamic SQL which should refer Master tables for table names and Primary keys and then Join for insertion into target tables .
    EG:
    INSERT INTO HUB.dbo.lp_order
    SELECT *
    FROM del.dbo.lp_order t1
    where not exists ( select *
    from hub.dbo.lp_order tw
    where t1.order_id = t2.order_id )
    SET @rows = @@ROWCOUNT
    PRINT 'Table: lp_order; Inserted Records: '+ Cast(@rows AS VARCHAR)
    -- Please note Databse names are going to remain the same but table names and join conditions on keys
    -- should vary for each table(s) being configured in master tables
    Sample of Master configuration tables with table info and PK Info :
    Table Info         
    Table_info_ID    Table_Name    
    1        lp_order    
    7        lp__transition_record    
    Table_PK_Info        
    Table_PK_Info_ID    Table_info_ID    PK_Column_Name
    2                1    order_id
    8                7    transition_record_id
    There can be more than one join condition for each table
    Thanks you !
    Rajkumar Yelugu

    Hi Rajkumar,
    It is glad to hear that you figured the question out by yourself.
    There's a flaw with your while loop in your sample code, just in case you hadn't noticed that, please see below.
    --In this case, it goes to infinite loop
    DECLARE @T TABLE(ID INT)
    INSERT INTO @T VALUES(1),(3),(2)
    DECLARE @ID INT
    SELECT @ID = MIN(ID) FROM @T
    WHILE @ID IS NOT NULL
    PRINT @ID
    SELECT @ID =ID FROM @T WHERE ID > @ID
    So a cursor would be the appropriate option in your case, please reference below.
    DECLARE @Table_Info TABLE
    Table_info_ID INT,
    Table_Name VARCHAR(99)
    INSERT INTO @Table_Info VALUES(1,'lp_order'),(7,'lp__transition_record');
    DECLARE @Table_PK_Info TABLE
    Table_PK_Info_ID INT,
    Table_info_ID INT,
    PK_Column_Name VARCHAR(99)
    INSERT INTO @Table_PK_Info VALUES(2,1,'order_id'),(8,7,'transition_record_id'),(3,1,'order_id2')
    DECLARE @SQL NVarchar(MAX),
    @ID INT,
    @Table_Name VARCHAR(20),
    @whereCondition VARCHAR(99)
    DECLARE cur_Tabel_Info CURSOR
    FOR SELECT Table_info_ID,Table_Name FROM @Table_Info
    OPEN cur_Tabel_Info
    FETCH NEXT FROM cur_Tabel_Info
    INTO @ID, @Table_Name
    WHILE @@FETCH_STATUS = 0
    BEGIN
    SELECT @whereCondition =ISNULL(@whereCondition+' AND ','') +'t1.'+PK_Column_Name+'='+'t2.'+PK_Column_Name FROM @Table_PK_Info WHERE Table_info_ID=@ID
    SET @SQL = 'INSERT INTO hub.dbo.'+@Table_Name+'
    SELECT * FROM del.dbo.'+@Table_Name+' AS T1
    WHERE NOT EXISTS (
    SELECT *
    FROM hub.dbo.'+@Table_Name+' AS T2
    WHERE '+@whereCondition+')'
    SELECT @SQL
    --EXEC(@SQL)
    SET @whereCondition = NULL
    FETCH NEXT FROM cur_Tabel_Info
    INTO @ID, @Table_Name
    END
    Supposing you had noticed and fixed the flaw, your answer sharing is always welcome.
    If you have any question, feel free to let me know.
    Eric Zhang
    TechNet Community Support

  • BRIDGE statement in a loop : dynamic destination and source table names ...

    Hello,
    I can't find the right syntax to do what I need, if it's possible :
    Context :
    I work actualy on a migration from MS Access applications to Oracle (datas only). So I copied all MS Access Tables into Oracle and created manualy all the relationnal constraints like primary and foreign keys ('cause constraints are not included in 'Copy to Oracle').
    I Have often to refresh my datas, because the MS access applications are still in use. Therefore I wrote PL/SQL scripts. They do the folowing, using dynamic SQL with 'Execute Immediate' statement :
    Script 1
    - disable all user's constraints
    - disable all user's triggers
    - truncate all user's tables
    (Here, I have to do a manual copy of all MS Access tables to Oracle, checking the Append check-box, because the BRIDGE statement doesn't support 'Execute Immediate', and wait...)
    Script 2
    - enable all user's constraints
    - enable all user's triggers
    Could someone let me know how Il could do the same as :
    For t in (select table_name from user_tables) loop
    -- Copy the datas from an Access table into the same Oracle table
    execute immediate ('BRIDGE ' || t.table_name || ' AS MyAccessConnName(select * from ' || t.table_name || ') APPEND') ;
    -- News flash ...
    dbms_output.put_line('Table ' || t.table_name || ' filled') ;
    end loop;
    -------------------------------------------------------------------------------------------------------------------------- ==> 00900. 00000 - "invalid SQL statement"
    If a dynamic table name substitution is applicable in the Bridge statement from a query, I take it with joice!
    Thank you for helping me...
    Daniel

    Hi Daniel,
    The BRIDGE statement is just an extra command I implemented in the SQL Developer worksheet script runner.
    It gets interpreted by SQL Developer and it dynamically creates (CREATE TABLE , INSERT INTO , SELECT ... ) statements and runs them against the connections specified.
    It was developed to improve certain migration features of SQL Developer. We haven't really spent any time developing it into a customer friendly statement to be used in custom scripts.
    Hence the lack of doc. But it is there and if you can make it work for yourself all the better.
    When I say "One way of doing what you want". I mean I haven't thought about your particular problem exhaustively and I wouldn't want you to take my solution as gospel :)
    If you are happy running a script in SQL Developer, but would rather not run 2 scripts , or cut and paste results around, you could SPOOL the results and execute them.
    --call your other scripts to disable constraints during the data move
    set echo off;
    set feedback off;
    set linesize 1000;
    set pagesize 0;
    set headsep off;
    set termout off;
    set verify off;
    set heading off;
    SET PAGES 0;
    SET HEAD OFF;
    spool c:\mydynamicscript.sql
    select 'BRIDGE ' || table_name || ' AS MyAccessConnName(select * from ' || table_name||');' from user_tables ;
    spool off
    @c:\mydynamicscript.sql
    --call another script to enable your constraints again
    Regards,
    Dermot.
    SQL Developer Team.

  • Avoid Hard Parsing for executing dynamic SQL using DUAL table Oracle

    I want to know if dynamic sql statements involving DUAL table can be modified to remove HARD PARSING.
    We have several SQL statements are stored in configuration table, here is sample example
    -- query 1 before replacing index values as stored in config table ---
    select count(*) from dual where  'REPLACE_VALUE_OF_INDEX_3' IN ('K')
    AND (('REPLACE_VALUE_OF_INDEX_13' IN ('1053','1095','1199') ) OR ('REPLACE_VALUE_OF_INDEX_13' IN ('1200') ))
    AND 'REPLACE_VALUE_OF_INDEX_2' IN ('6')
    AND 'REPLACE_VALUE_OF_INDEX_15' IN ('870001305')
    -- query 1 after replacing index values--
    select count(*) from dual where  'REPLACE_VALUE_OF_INDEX_10' IN ('K')
    AND (('1030' IN ('1053','1095','1199') ) OR ('1030' IN ('1200') ))
    AND '2' IN ('6')
    AND 'X' IN ('870001305')
    -- query 2 before replacing index values as stored in config table --
    select count(*) from dual where  'REPLACE_VALUE_OF_INDEX_5' IN ('361A','362A')
    AND 'REPLACE_VALUE_OF_INDEX_22' BETWEEN '200707' AND '200806'
    -- query 2 after replacing index values--
    select count(*) from dual where  '3MAA' IN ('361A','362A') AND '201304' BETWEEN '200707' AND '200806'

    If I got it right you have some (maybe lots of) conditions stored in a table (be patient - it's my interpretation)
    create table eb_conditions as
    select 1 rid,q'{:5 IN ('361A','362A') AND :3 BETWEEN '200707' AND '200806'}' cndtn from dual union all
    select 2,q'{:2 IN ('361A','362A') AND :3 BETWEEN '200707' AND '200806'}' from dual union all
    select 3,q'{:1 IN ('K') AND ((:2 IN ('1053','1095','1199') ) OR (:4 IN ('1200') )) AND :3 IN ('6') AND :5 IN ('870001305')}' from dual
    RID
    CNDTN
    1
    :5 IN ('361A','362A') AND :3 BETWEEN '200707' AND '200806'
    2
    :2 IN ('361A','362A') AND :3 BETWEEN '200707' AND '200806'
    3
    :1 IN ('K') AND ((:2 IN ('1053','1095','1199') ) OR (:4 IN ('1200') )) AND :3 IN ('6') AND :5 IN ('870001305')
    and you have to check the conditions using values stored in an array
    I used a table instead: the vl at rid = 1 representing the value of bind variable :1 in eb_conditions table and so on ...
    create table eb_array as
    select 1 rid,'K' vl from dual union all
    select 2,'1199' from dual union all
    select 3,'200803' from dual union all
    select 4,'1000' from dual union all
    select 5,'870001305' from dual
    RID
    VL
    1
    K
    2
    1199
    3
    200803
    4
    1000
    5
    870001305
    You want to check the conditions using select count(*) from dual where <condition with binds substituted fron the array>
    Judging from the title Hard Parsing represents the major problem and you cannot avoid it since every condition to be verified is different from every other condition.
    I think your best bet is not to evaluate conditions row by row - context shift cannot be avoided and there might be more than one for each iteration.
    So try to do it in a single step:
    declare
    w_cndtn varchar2(4000);
    w_clob  clob;
    w_cursor sys_refcursor;
    one number;
    two number;
    begin
      dbms_lob.createtemporary(w_clob,false);
      for rw in (select rid,
                        max(cndtn) cndtn,
                        listagg(val,',') within group (order by rn)||',' usng
                   from (select c.rid,c.cndtn,c.rn,c.bind,
                                replace(rtrim(c.bind),':'||to_char(v.rid),''''||v.vl||'''') val
                           from (select rid,
                                        cndtn,
                                        regexp_substr(cndtn,':\d+ ',1,level) bind,
                                        level rn
                                   from eb_conditions
                                 connect by level <= regexp_count(cndtn,':')
                                        and prior rid = rid
                                        and prior sys_guid() is not null
                                ) c,
                                eb_array v
                          where instr(c.bind,':'||v.rid||' ') > 0
                  group by rid
      loop
        w_cndtn := rw.cndtn;
        while instr(w_cndtn,':') > 0
        loop
          w_cndtn := replace(w_cndtn,trim(regexp_substr(w_cndtn,':\d+ ',1,1)),substr(rw.usng,1,instr(rw.usng,',') - 1));
          rw.usng := substr(rw.usng,instr(rw.usng,',') + 1);
        end loop;
        w_cndtn := 'select '||to_char(rw.rid)||' cndtn_id,count(*) from dual where '||w_cndtn||' union all ';
        w_clob := w_clob ||' '||w_cndtn;
      end loop;
      w_clob := substr(w_clob,1,instr(w_clob,'union all',-1,1) - 1);
      open w_cursor for w_clob;
      loop
        fetch w_cursor into one,two;
        exit when w_cursor%notfound;
        dbms_output.put_line(to_char(one)||':'||to_char(two));
      end loop;
      dbms_lob.freetemporary(w_clob);
    end;
    1:0
    2:0
    3:0
    Statement processed.
    Regards
    Etbin

  • Using Table name in Read statement dynamically

    Hi Experts,
    I have the following requirement.
    Based on a country code say "A" , "B", "C" and based on this i have to read different internal tables lt_tabA, lt_tabB and lt_tabC.
    The table key can be given dynamically, but how can i use the internal table name dynamically without using if statements.
    Please help.
    Thanks!
    Best Regards,
    Gayathri

    Hi Gayathri,
    something like
    DATA:
        lt_t100 TYPE TABLE OF t100,
        lt_t000 TYPE TABLE OF t000.
      FIELD-SYMBOLS:
        <table> TYPE table,
        <rec>   TYPE ANY,
        <field> TYPE ANY.
      SELECT:
        * INTO CORRESPONDING FIELDS OF TABLE lt_t100 FROM t100 UP TO 10 ROWS,
        * INTO CORRESPONDING FIELDS OF TABLE lt_t000 FROM t000 UP TO 10 ROWS.
      CASE abap_true.
        WHEN space.
          ASSIGN  lt_t100 TO <table>.
        WHEN OTHERS.
          ASSIGN  lt_t000 TO <table>.
      ENDCASE.
      READ TABLE <table> with key ('MANDT') = sy-mandt ASSIGNING <rec>.
    Regards,
    Clemens

  • Dynamic DB table name in insert statement

    In the following command i was able to build <dyn_table> dynamically but how do we do that for <dyn_wa>. table name should be populated dynamically here.
    for ex: pa0001, pa0002, .... and I have these names in an IT table
    INSERT  <dyn_wa> FROM TABLE <dyn_table>
                              ACCEPTING DUPLICATE KEYS.
    Pls help...Thanks

    Take it as charater type.
    This code works for me.
    TABLES : ztest123.
    DATA : tab_name(10) TYPE c.
    tab_name = 'ZTEST123'.
    DATA : wa LIKE ztest123.
    wa-name = 'Mahesh'.
    INSERT (tab_name) FROM wa.
    Thanks
    Mahesh

  • Dynamically assigning table name in select statement

    how can i assign the table name dynamically in Select statement?
    i tried following code
    create or replace procedure proc1
    as
    x varchar2(100);
    y varchar2(10);
    begin
    x='UNIT_MASTER';
    execute immediate 'select unit_code into y from x where
    rownum=1';
    dbms_output.put_line(y);
    end;
    the procedure is created but when i execute the procedure the
    error is shown in the execute immediate statement

    Do the following :
    Create or replace procedure pro1 as
    x varchar2(100);
    y varchar2(10);
    begin
    x := 'UNIT_MASTER';
    EXECUTE IMMEDIATE 'select unit_code from '||x||' where rownum
    = 1' INTO y;
    dbms_output.put_line(y);

Maybe you are looking for

  • Western Digital external hard drive not working properly

    I have this external hard drive from western digital, 2 TB space, in wich i stored data from a windows machine. Now i moved to an arch machine (the one i have at home) and it doesn't mount the hard drive. I tried as normal user and as root, i tried j

  • Oracle Database Mobile Server 11 sync

    Hi, I have two simple tables in the back-end oracle database in order to create a meeting-room android application with and embebbed SQLite database on the client devices. I have written all the functionality to register, authenticate, create a new a

  • Excise duty  in Purchase Order

    Dear Guru's Please find my query mentioned below....... QUERY: We are using Taxinn as a procedure Scenario: Same vendor same material same plant I want to create 2  Seperate PO  1) With Zero Excise duty 2) With 16 % Excise Duty How to Solve this Quer

  • 'Touch does not have proper permission to run.'

    I downloaded the app 'touch' but it will not open. I have tried uninstalling it and reinstalling it but when I click on it, it still will not open. Whenever I restart my phone the first message that pops up is 'Touch does not have proper permission t

  • Documentation SAP Modules

    Hi, I am looking for the SAP Modules documentation for SAP R/3 4.7 similar to the one found on this site http://www.sapbrainsonline.com/TUTORIALS/FUNCTIONAL/ This documentation dates back to the year 2001. I am looking for more recent documentation.