Help needed in making table name and column name dynamic

please check the below query? in the below message
Message was edited by:
460425
Message was edited by:
460425

thanks Dmytro,
below is the script i was looking for it got it..any way thanks.
just need to replace dbms_output.put_line with utl_file.put_line
to put the code on server directory.
and execute as and when required.
Reg.
AAK
CREATE OR REPLACE PROCEDURE p_ad_log
IS
     CURSOR tbl_cursor IS
          SELECT table_name FROM user_tables WHERE table_name IN('EMP','EMP1') ;
     CURSOR col_cursor( cp_table_name varchar2) IS
          SELECT column_name FROM user_tab_columns WHERE table_name=cp_table_name;
     --v_file_handle      utl_file.file_type;
     --v_file_dir          varchar2(30)      :=     'DIRECTORY PATH'     ';
     --v_file_name     varchar2(30)       :=       'AD_TRIGGER_TEXT.TXT';
     tbl_cursor_value     tbl_cursor%ROWTYPE;
     col_cursor_value     col_cursor%ROWTYPE;
     v_string          varchar2(4000);
     v_string_val     varchar2(4000);
BEGIN
     DELETE audit_triggers_status;
     COMMIT;
     --v_file_handle := utl_file.fopen(v_file_dir,v_file_name,'W',32000);
     OPEN tbl_cursor;
     LOOP
          FETCH tbl_cursor into tbl_cursor_value;
          EXIT WHEN tbl_cursor%NOTFOUND;
          OPEN col_cursor(tbl_cursor_value.table_name);
          DBMS_OUTPUT.PUT_LINE( 'CREATE OR REPLACE TRIGGER' ||' ad_'||tbl_cursor_value.table_name); -- short name for audit trigger coz table name will be appended to it and result should not exceed 30 char
          DBMS_OUTPUT.PUT_LINE( 'BEFORE INSERT OR UPDATE OR DELETE ON '||tbl_cursor_value.table_name);
          DBMS_OUTPUT.PUT_LINE( 'FOR EACH ROW');
          DBMS_OUTPUT.PUT_LINE( 'BEGIN');
          v_string:='INSERT INTO'||' ad_'||tbl_cursor_value.table_name||'(';
          v_string_val:='values(';
          INSERT INTO audit_triggers_status( table_name,trigger_name,audit_flag) VALUES (tbl_cursor_value.table_name,' ad_'||tbl_cursor_value.table_name,'Y');
               LOOP
                    FETCH col_cursor into col_cursor_value;
                    EXIT WHEN col_cursor%NOTFOUND;
                    v_string:=v_string||col_cursor_value.column_name||',';
                    v_string_val:=v_string_val||':new.'||col_cursor_value.column_name||',';
               END LOOP;
               CLOSE COL_CURSOR;
          v_string:=substr(v_string,1,length(v_string)-1);
          v_string_val:=substr(v_string_val,1,length(v_string_val)-1);
          v_string:=v_string||') ';
          v_string_val:=v_string_val||');';
          --DBMS_OUTPUT.PUT_LINE(v_string||v_string_val);
          DBMS_OUTPUT.PUT_LINE('IF INSERTING THEN');
          DBMS_OUTPUT.PUT_LINE('     '||v_string||v_string_val);
          DBMS_OUTPUT.PUT_LINE('END IF;');
          DBMS_OUTPUT.PUT_LINE('IF UPDATING THEN');
          DBMS_OUTPUT.PUT_LINE('     '||v_string||v_string_val);
          DBMS_OUTPUT.PUT_LINE('END IF;');
          DBMS_OUTPUT.PUT_LINE('IF DELETING THEN');
          --DBMS_OUTPUT.PUT_LINE('     '||v_string||REPLACE(v_string_val,':new.',':old.');
          V_STRING_VAL:=REPLACE(v_string_val,':new.',':old.');
          DBMS_OUTPUT.PUT_LINE('     '||v_string||v_string_val);
          DBMS_OUTPUT.PUT_LINE('END IF;');
          DBMS_OUTPUT.PUT_LINE('END '||' ad_'||tbl_cursor_value.table_name||';');
          DBMS_OUTPUT.PUT_LINE(' ');
     END LOOP;
     CLOSE TBL_CURSOR;
     COMMIT;
END;

Similar Messages

  • Troubleshoting help needed:  My iMac keeps crashing and restarting with a report detail: "spinlock application timed out"  What can I do to fix this?timed out"

    Troubleshooting help needed:  My iMac keeps crashing and restarting with a notice: "Spinlock application timed out"  What can I do?

    Launch the Console application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Console in the page that opens.
    Select the most recent panic log under System Diagnostic Reports. Post the contents — the text, please, not a screenshot. In the interest of privacy, I suggest you edit out the “Anonymous UUID,” a long string of letters, numbers, and dashes in the header and body of the report, if it’s present (it may not be.) Please don't post shutdownStall, spin, or hang reports.

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

  • Problem in using table name dynamically in PL/SQL

    I tried to create a procedure to use table name dynamically and got the following error. Anything wrong with my procedure?
    NFADV>declare
      2   cnt number;
      3   cursor cur is select table_name from user_tables where table_name in ('EMP','DEPT');
      4  begin
      5   for c1 in cur
      6   loop
      7    execute immediate select count(*) into cnt from c1.table_name;
      8      dbms_output.put_line('Count is : '||cnt);
      9   end loop;
    10  end;
    11  /
    declare
    ERROR at line 1:
    ORA-06550: line 7, column 21:
    PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
    ( - + case mod new not null <an identifier>
    <a double-quoted delimited-identifier> <a bind variable> avg
    count current exists max min prior sql stddev sum variance
    execute forall merge time timestamp interval date
    <a string literal with character set specification>
    <a number> <a single-quoted SQL string> pipe
    <an alternatively-quoted string literal with character set specification>
    <an alternatively-quo
    ORA-06550: line 8, column 5:
    PLS-00103: Encountered the symbol "DBMS_OUTPUT"
    ORA-06550: line 8, column 45:
    PLS-00103: Encountered the symbol ";" when expecting one of the following:
    . ( , * % & - + / at mod remainder rem <an identifier>
    <a double-quoted delimited-identifier> <an exponent (**)> as
    from into || multiset bulkThanks and Regards
    Kaustubh

    Hi,
    The wrong part is in execute immediate, it should be as follows:
    execute immediate ('select count(*) from '|| c1.table_name)
    into cnt
    (not tested)
    Regards
    AK

  • How to use table name dynamically in report  procedure

    Hello every body
    I want to use table name dynamically means at runtime i want to pass table name.
    I can do this by lexical parameter in main query.
    But my problem is that i want to crate new format trigger or new function that use 1 cursor in which that lexical parameter : table name is used.
    so how to do that?
    i can not use that lexical parameter it is giving error.
    please help me how to do that.

    Call a database function which you pass the lexical parameter. Then in the database function you use dynamic sql or the execute immediate option to build the SQL string.
    Return the information from this function to build your business logic on in your format trigger.
    Marcos

  • Help Needed Tagging Complex Tables

    I am often asked to create accessible versions of PDFs for clients that contain complex tables -- e.g., merged and/or blank cells, multiple levels of subcategory headings. Are there any online resources that might help me understand (a) IF it is possible to create accessible versions of these tables and, if so, (b) HOW to tag them. In the ideal world, we would go back to the original document and revise the table, but that's not always possible.
    For example, a document I am working on currently includes a table that looks something like this:
    Category
    Period 1
    Period 2
    FTE
    $
    FTE
    $
    A. First Heading
        1. First Subhead
            a. Topic A
    34
    45
            b. Topic B
    54
    63
    Subtotal
    108
       2. Second Subhead
           a. Topic A
    etc.
    I understand how to tag the "Period 1" and "Period 2" headings as column headings that span 2 columns, but I'm not clear on how to handle the blank cells and/or the subheadings. Sorry for such an open-ended questions, but I'm not sure where to look - all the documentation I've seen seems to address fairly simple tables. I am using Acrobat XI for Mac.
    Any guidance would be greatly appreciated. Thank you!

    Yes, it is possible to create accessible versions of the these tables. There are several possible solutions.  In the example above, you are correct that Period 1 and Period 2 need to be tagged as <TH> with Span = 2 Column. Scope also needs to be set to Column.  FTE and $ also need to be tagged as TH with Scope = Column. All the cells in Column 1 (A. First Heading, 1. First Subhead, etc.) are <TH> with Scope = Row. 
    Because this is a complex table you need to Associate the table content with these headings using <ID> tags. 
    This is unfortunately where things can get a little time consuming.  The process can be done within Acrobat using the Touch Up Reading Order (TOR) tool (Accessibility Tool Panel). To briefly summarize -- Select the TOR, select the Table, and click the Table Button on the TOR Menu to open up the Table Editor.  The TOR Menu will disappear, and the table will be visible. You can click on individual cells, right click and select Cell Properties. 
    Select one of the header cells, right click and then select Table Cell Properties. There you will see the ID, which is usually something memorable like TD_08934_121.  Changes this to something meaningful like PERIOD_1 and P1_FTE. The name must be unique within the file. 
    Click OK to save and exit the Table Cell Properties window.
    Using the TOR select all of the content cells beneath that header and right click to open the Cell Properties.  Acrobat will let you select more than one cell by using the Shift Key, if there are no conflicting values in Cell Properties. Note: At times you may need to work one cell at a time.
    Once the Table Cell Properties is open, click the plus next to Associate Header Cell IDs and select the appropriate Heading ID that you defined above.
    Repeat until all the content cells are associated with their appropriate column headings, subheadings and row headings.
    That's method 1. 
    Method 2 would be to use the CommonLook plug-in.  Adding Table Cell IDs is CommonLook's strong point, but the price is high and there is a learning curve. And I've experienced some troublesome issues involving borders and shading in some files.  Still if you have Commonlook available it can be a REAL timesaver for tagging complex tables.
    Lastly, there are some tricks and workarounds that would make the structure of this table simple and therefore accessible without all of this.  If you are experienced  working in the Tags Panel in Acrobat. In the example above you could convert the first row of content  Headings Period 1 and Period 2 to Artifacts and then entirely delete that row from the table within the tags panel,  Then add alternative text to the second row of headings so FTE will always read as "Period 1 FTE" or Period 2 FTE" and so forth. Some purists may object to this method, but it would work.
    NOTE: Any of these methods require further checking with a screen reader to ensure the tables are recognized by tables and no mistakes were made in assigning the headings to the cells and I would also check to make sure any blank cells read as "Blank" as they may be mistagged in the tags panel by the authoring application (e.g., MS Word). 

  • Need to include table name,schema name in select output

    I need to output the table name and schema name of the current user into a table.. I have tried including
    within a select statement..
    table_name,
    from user_tables
    where table_name='mnme';
    no rows returned

    Hi,
    Its in upper case 'MNME'
    Best.
    EA

  • Need a that Table Name in Select command which being used in from statement

    My Question Is:
    If my SQL command is like this "
    Select Code, Name from Customer (Table Name)
    Can I get this output in this Way .. ?
    Select Code, Name,Customer(Table Name)  from Customer (Table Name)
    in dynamic way ..

    NO. You missing many fundamental concepts of RDBMS. A table is a set of entities, so it's name is plural or collective(unless you really do have only one customer as you said). There is no such thing as a generic "name", or "code" in RDBMS. Those affixes
    are called attribute properties, and they have to be part of an attribute data element name -- customer_name, postal_code, etc. 
    Since a table is a set, its columns are fixed and known in the schema. They do not change by magic! This kind of non-RDBMS thinking is called "Automobiles, Squids and Lady GaGa" coding. Please read any intro book on RDBMS. Your whole mindset is wrong. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Procedure needed to input table name

    i want a procedure where i would enter the table name and an attribute as input parameters.
    The procedure will find whether the entered attribute is primary key or not
    Please help me

    Hi,
    Try this :
    SQL> create table test (col1 number primary key, col2 number);
    Table created.
    SQL> create or replace function is_pk (tb_name varchar2, col_name varchar2)
    return varchar2 is
    var_is_pk varchar2(5);
    begin
    begin
    select 'PK'
    into    var_is_pk
    from   user_cons_columns a, user_constraints b
    where  a.OWNER=b.OWNER
    and   a.CONSTRAINT_NAME=b.CONSTRAINT_NAME
    and   a.TABLE_NAME=b.TABLE_NAME
    and   a.TABLE_NAME=upper(tb_name)
    and   a.COLUMN_NAME=upper(col_name)
    and   b.constraint_type='P';
    exception when others then var_is_pk:='NO_PK';
    end;
    return var_is_pk;
    end;
    Function created.
    SQL> select is_pk('test','col1'), is_pk('test','col2') from dual;
    IS_PK('TEST','COL1')  IS_PK('TEST','COL2')
    PK                             NO_PKHTH,
    Nicolas.
    I'm sorry Maarten, my network is catastrophic this morning... so I didn't see your post before post mine.
    Message was edited by:
    N. Gasparotto

  • Can we pass IT table name dynamically to READ and SORT stmt

    Hello All,
      i have a requirement in which i am passing table name using a variable and want to read the same table: so my question is can we execute read and sort stmt with dynamic IT name. please see below for explaination.
    v_itname = <it_2>.
    now read using variable
    READ table ( v_itname ) with key <field>.
    and
    SORT ( v_itname ) by (otab).
    thanks
    Mani

    Hi ,
    This can be done. Please refer to the  codes below. Please note that the code will work if the itabs are of type standard table else it may dump.
    You just need to replace the variables form the values from your internal table.
    DATA: v_table1(10) TYPE c VALUE 'I_MARA',
          v_field(10)  TYPE c VALUE 'MATNR',
          i_mara TYPE STANDARD TABLE OF mara.
    FIELD-SYMBOLS : <fs_tab>   TYPE STANDARD TABLE,
                    <fs_field> TYPE ANY.
    DATA: otab TYPE abap_sortorder_tab,
    oline TYPE abap_sortorder.
    SELECT * UP TO 10 ROWS
      FROM  mara
      INTO TABLE i_mara.
    IF sy-subrc = 0.
      ASSIGN (v_table1) TO <fs_tab>.
      IF sy-subrc = 0.
        oline-name = v_field.
        APPEND oline TO otab.
        SORT <fs_tab> BY (otab).
        READ TABLE <fs_tab>
        WITH KEY (v_field) = '000000000020000989' "
        BINARY SEARCH
        TRANSPORTING NO FIELDS.
        IF sy-subrc = 0.
        ENDIF.
      ENDIF.
    ENDIF.
    Regards,
    Dev.

  • Help needed for SAP Tables Relationships

    Hi All,
    I am new to ERP and need help regarding standard SAP Tables.
    Please share the document that contains the details of SAP Tables and Standard SAP FM that are provided by SAP.
    All helpful answers will be rewarded.
    Regards,
    Udaya.

    Hi,
    Please go to the following link.
    http://www.erpgenie.com/abap/tables.htm
    http://www.erpgenie.com/abap/tables_sd.htm
    http://www.erpgenie.com/abap/tables_mm.htm
    http://www.erpgenie.com/abap/tables_fi.htm
    Regards
    Jean

  • Help need with Update statement -Two date columns

    I have two tables rate_change and load ,i want to update the next_rate_change_date and next_rate_change_date columns ,load table has rate_change_effe_term column has value (12) that represents months for each loan,
    i want to take that rate_change_effe_term from load table and add it to min values of rate_chng_effective_date and then update the next_rate_change_date and then continue to do for all the rows of that loan_numer.
    Please see the below sample data.
    Current_data:::
    Loan_number rate_chng_effective_date next_rate_change_date
    111111 02/01/2012 02/01/2014
    111111 03/01/2012 02/01/2014
    111111 06/01/2012 02/01/2014
    111111 07/01/2012 02/01/2014
    111111 08/01/2012 02/01/2014
    Requrired format
    Loan_number rate_chng_effective_date next_rate_change_date
    111111 02/01/2012 02/01/2014
    111111 02/01/2014 02/01/2016
    111111 02/01/2016 02/01/2018
    111111 02/01/2018 02/01/2020
    111111 02/01/2020 02/01/2022
    /* Formatted on 10/24/2012 9:34:23 PM (QP5 v5.227.12220.39724) */
    CREATE TABLE rate_change
       loan_number                NUMBER (10),
       rate_chng_effective_date   VARCHAR2 (20),
       next_rate_change_date      VARCHAR2 (20)
    INSERT INTO rate_change
         VALUES (111111, '02/01/2012', '02/01/2014');
    INSERT INTO rate_change
         VALUES (111111, '03/01/2012', '02/01/2014');
    INSERT INTO rate_change
         VALUES (111111, '06/01/2012', '02/01/2014');
    INSERT INTO rate_change
         VALUES (111111, '07/01/2012', '02/01/2014');
    INSERT INTO rate_change
         VALUES (111111, '08/01/2012', '02/01/2014');
    COMMIT;
    CREATE TABLE Load
       loan_number             NUMBER (10),
       Correct_day             VARCHAR2 (20),
       rate_change_effe_term   VARCHAR2 (20)
    INSERT INTO Load
         VALUES (111111, '02/20/2012', '24');
    INSERT INTO Load
         VALUES (222222, '02/15/2010', '96');
    COMMIT;
    Current_data:::
    Loan_number   rate_chng_effective_date        next_rate_change_date
    111111            02/01/2012                             02/01/2014
    111111            03/01/2012                              02/01/2014
    111111            06/01/2012                             02/01/2014
    111111            07/01/2012                            02/01/2014
    111111            08/01/2012                            02/01/2014
    Requrired format
    Loan_number   rate_chng_effective_date        next_rate_change_date
    111111            02/01/2012                             02/01/2014
    111111            02/01/2014                            02/01/2016
    111111            02/01/2016                             02/01/2018
    111111            02/01/2018                            02/01/2020
    111111            02/01/2020                            02/01/2022
    Any ideas ,suggestion greatly helps . Thank you  very much.

    try with below query.
    update rate_change
    SET rate_chng_effective_date   = To_CHAR(ADD_MONTHS((select MIN(TO_DATE(rate_chng_effective_date,'MM/DD/YYYY'))
                                                          FROM rate_change
                                                          WHERE loan_number = 111111)
                                                          (rownum -1)*(select rate_change_effe_term 
                                                          FROM Load
                                                          WHERE loan_number  =111111) ),'MM/DD/YYYY'  )          
         ,next_rate_change_date      = To_CHAR(ADD_MONTHS((select MIN(TO_DATE(next_rate_change_date,'MM/DD/YYYY'))
                                                          FROM rate_change
                                                          WHERE loan_number = 111111)
                                                          (rownum -1)*(select rate_change_effe_term 
                                                          FROM Load
                                                          WHERE loan_number  =111111) ),'MM/DD/YYYY'  )
    WHERE  loan_number = 111111 ;Thanks,ram

  • Help Needed in Creating Java Class and Java Stored Procedures

    Hi,
    Can anyone tell how can i create Java Class, Java Source and Java Resource in Oracle Database.
    I have seen the Documents. But i couldn't able to understand it correctly.
    I will be helpful when i get some Examples for creating a Java Class, Java Source and Stored Procedures with Java with details.
    Is that possible to Create a Java class in the oracle Database itself ?.
    Where are the files located for the existing Java Class ?..
    Help Needed Please.
    Thanks,
    Murali.v

    Hi Murali,
    Heres a thread which discussed uploading java source file instead of runnable code on to the database, which might be helpful :
    Configure deployment to a database to upload the java file instead of class
    The files for the java class you created in JDev project is located in the myworks folder in jdev, eg, <jdev_home>\jdev\mywork\Application1\Project1\src\project1
    Hope this helps,
    Sunil..

  • Urgent please help: what is the table name for cash management reports?

    I am wondering what the table name for cash management reports is. I am trying to figure out then if I have any missing.
    Please help.

    I checked MSEG table. But, I didn't find any field for date.
    Can you tell me field name.
    Regards
    Siva

  • Table headings and column/row sizes

    I have mapped my FM table format to a table style defined in my CSS. However, I have the following issues with the resulting RoboHelp tables:
    I have a header row in the FrameMaker table, but the header doesn't come over into RH. All of the table rows are <td> instead of <th>. Therefore, the shading defined in my CSS for the table header row does not appear.
    A bunch of inline formatting that I don't want is coming over, defining the table width and the row width and height. Here's an example:
    <table class="formatA" cellspacing="0" width="600">
        <tr style="height: 18.00pt;">
            <td style="vertical-align: top; padding-left: 6.00pt; padding-top: 3.00pt;
                 padding-right: 6.00pt; padding-bottom: 3.00pt;" width="198"><p>Report/Visualization</p></td>
            <td style="vertical-align: top; padding-left: 6.00pt; padding-top: 3.00pt;
                 padding-right: 6.00pt; padding-bottom: 3.00pt;" width="402"><p>Description</p></td>
        </tr>
    Is there any way to get RH to recognize table header rows?
    Also, is there any way to prevent the size information from coming over? What I'd like is for the table width to be 100% and the cell widths and heights to be determined by their content (which would happen automatically if the inline formatting weren't added).
    If there isn't a way to accomplish this, then I'd probably be better off not trying to map the table styles and just going with "Source". The sizes would still be fixed, but at least the shading would appear.

    Forget FM for a moment. I think that if you create a table in RoboHelp using TH you will find  RoboHelp simply does not understand TH.
    The more people who report a bug or request a feature, the more likely it is to be actioned. Please follow this link.
    http://www.Adobe.com/cfusion/mmform/index.cfm?name=wishform&product=38
    See www.grainge.org for RoboHelp and Authoring tips
    @petergrainge

Maybe you are looking for

  • Sun.awt.X11.XToolkit processException

    In my application, I'm embedding a Java AWT Frame into a Qt widget and for that I'm using "sun.awt.X11.XEmbeddedFrame.java" class. I pass the "Window Id" of the QWidget to XEmbeddedFrame which then displays itself into the QWidget. The embedding work

  • Using TV for display!

    What type of cable will connect my macbbok pro to an HDMI port on my TV? Where can i get one? I would like to watch Netflix on my TV!

  • How can i reset my computer password

    my friend hired a company to setup het imac her network password and all passwords for  extreme etc were set by them they have since gone out of business, and she has no way of retreiving the passwords she always relied on them i have tried to look t

  • Is there any difference in upgrade for position based security model

    Hello Gurus, I am working on a Upgrade project from 4.6c to ECC6.0 , In 4.6C R/3 system position based security concept is used. Are there any extra precautions need to be taken while upgrading in a position based security model ? Or Is it the same p

  • Software monitoring and latency

    I've heard people mention that they turn off software monitoring to minimize latency, but I don't see how to do that. I realize it has to do with the equipment and maybe my device does not allow for non-software monitoring. I'm using items none of yo