Query to find relevant Table name

Hi i need a SQL query which should return me relevant table names. i.e. if there is table 'EMP' , then query should give table names with below result:
EMP
EMP_1
EMP_2
EMP_3
EMP_4
i.e. All tables which is starting with EMP (No Hardcoding of table, It should be dynamic way).I know we can achieve through SELECT * FROM USER_OBJECTS WHERE OBJECT_NAME LIKE 'EMP%'.
But here object_name i will passing dynamically.
Actually my main purpose is to create backup tables i.e. EMP is main table and EMP_1,EMP_2,EMP_3 .. EMP_100 is backup table.Now whenever i am making the any changes in EMP table, then i should take the backup of exiting EMP table and backup data should go to EMP_101 (as last table with sequence is EMP_100).
Any idea in SQL , PL/SQL i would appreciate .
Thanks

here is a way:
set serveroutput on
declare
tab_name varchar2(30) := 'EMP';
new_tab_name varchar2(30);
begin
  for i in (
        select * from (
            select t.*,
                    row_number() over(order by t.table_name desc) as row_nr ,
                    min(table_name) over () as originiall_table
                    from all_tables t
            where table_name like tab_name||'%'
        ) where row_nr = 1
  ) loop
    new_tab_name := substr(i.table_name, 1, instr(i.table_name, '_') - 1 )
                    ||'_'
                    || (TO_NUMBER(substr(i.table_name, instr(i.table_name, '_') + 1 )) + 1 ) ;
    execute immediate 'create table '||new_tab_name||' as select * from '||i.originiall_table;   
  end loop;
end;but why do you want to keep too many copies of tables in db?
anytime you will get problems with tablespaces.

Similar Messages

  • 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

  • Query to find the class name that has the maximum number of students ?

    I need the query to find the [class Name] which has the most number of students. please look below at the tables
    Students Table                                                                     
    StudentId     StudentName  ClassID                                    
    1                  xxx                   1                                           
    2                  yyy                   1                                           
    3                  zzz                   1  
    4                  fff                    2
    5                   ttt                  2
     Classes Table
     ClassID          ClassNane
     1                    CSHARP
     2                    JSHARP
    The result should be : CSHARP
    since there are 3 students in CSHARP and 2 students in JSHARP class
    Appreciate your help
    Thanks

    Try:
    DECLARE @Classes TABLE (
    ClassID INT identity(1, 1) PRIMARY KEY
    ,ClassName VARCHAR(50)
    INSERT INTO @Classes (ClassName)
    VALUES ('CSharp')
    ,('JSharp')
    DECLARE @Students TABLE (
    StudentID INT identity(1, 1) PRIMARY KEY
    ,StudentName VARCHAR(10)
    ,ClassID INT
    INSERT INTO @Students (
    StudentName
    ,ClassID
    VALUES (
    'xxx'
    ,1
    'yyy'
    ,1
    'zzz'
    ,1
    'fff'
    ,2
    'ttt'
    ,2
    SELECT TOP (1)
    WITH TIES C.ClassName
    FROM @Classes C
    INNER JOIN @Students S ON C.ClassID = S.ClassID
    GROUP BY C.ClassID
    ,C.ClassName
    ORDER BY COUNT(S.StudentID) DESC
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • Find the table names in a package body

    How to find the table names in a package body in single query .(SQL).

    Hi,
    you can find dependent objects of a package from below query
    select distinct referenced_name ,REFERENCED_TYPE from ALL_DEPENDENCIES where name = 'PACKAGE' and  referenced_owner not in ('SYS','PUBLIC') and referenced_type = 'TABLE';
    Thanks
    Handle: user12057782
    Status Level: Newbie
    Registered: Oct 13, 2009
    Total Posts: 5
    Total Questions: 4 (4 unresolved)
    mark answered if helpful/correct
    Edited by: CKPT on Nov 22, 2010 1:21 PM

  • Regarding finding the table name for a field in R12 forms

    Hi all,
    I need to know how to find the table name for a field in R12. I am working on extracting the employee information but i need to know how to get the table names for the fields.
    Thank you,
    raj

    Please see these threads.
    How to find table name in ebs
    How to find table name in ebs
    E-Business tables
    E-Business tables
    Thanks,
    Hussein

  • Find Transparent table name for correspoding Dictionary Structure SRM 7.0

    Hi,
    I am not able to find Transparent table name for correspoding Dictionary Structure in Webdynpro Component for a field in  SRM 7.0.
    Please let me know.
    Thanks,
    Monica

    Hi Monica
    please tell the transaction name and the name of field seen in webdynpro
    regards
    andrea

  • Need a query to list all table names

    I have more than 500 tables in my database.
    'insert_date' & 'update_date' columns are found in more than 100 tables with data type as date.
    I need a query to list all table names and 'insert_date' , 'update_date' column's content.
    Please Help
    Lee1212
    Message was edited by:
    LEE1212

    I have more than 500 tables in my database.
    'insert_date' & update_date column is found in more
    than 100 tables with data type as date.
    I need a query to list all table names and
    'insert_date' column's content.What do you mean by "column's content". A table can have many rows. Do you want to display all the distinct value for these columns?
    Below is the query to get the tables which has columns insert_Date and update_date
    select table_name
    from user_tab_columns
    where column_name ='INSERT_DATE'
    or column_name ='UPDATE_DATE'
    /You can write a PL/SQL block to retrive the distinct values of INSERT_DATE for these tables
    declare
    TYPE ref_cur IS REF CURSOR;
    insert_date_cur ref_cur;
    lv_insert_date DATE;
    cursor tables_list IS
    select table_name
    from user_tab_columns
    where column_name ='INSERT_DATE';
    begin
    for cur_tables in tables_list
    loop
      OPEN insert_date_cur for 'SELECT DISTINCT insert_date from '||cur_tables.table_name;
      DBMS_OUTPUT.PUT_LINE(cur_tables.table_name);
      DBMS_OUTPUT.PUT_LINE('--------------------------------');
      LOOP
      FETCH insert_date_cur into lv_insert_date;
      EXIT WHEN insert_date_cur%NOTFOUND;
      DBMS_OUTPUT.PUT_LINE(lv_insert_date);
      END LOOP;
    CLOSE insert_date_cur;
    end loop;
    end;I haven't tested this code. There might be some errors. Just posted something to start with for you.

  • I want to find the table name

    Hi experts,
    I want to find information which is stored in the particular transaction (find the table name)
    tcode is COR3 in that enter process order and enter after that go to adminstrative data in that created user.
    I want find user information will be stored in which table . pls help me in this

    Hi,
    There are both technical and functional ways of knowing the Table Names:
    1. You can ask your functional consultant to give you the basic or the main table name. From there you can use a where used list to get the list of all the tables that are connected to this table by the foreign key relationship.
    2. You can get to know the name of the package from the package hierarchy. You can also use se84 to find the objects from the repository information browser.
    3. You can use the ST05 transaction to run and SQL trace to find all the tables that where accessed during the TCODE execution. But here you need to be precise as it will show you all the names of all the database tables accessed.
    Hope this will help you.
    Thanks,
    Samantak.

  • To find a table name where the field is from??

    Hi Friends...
    I know the field name and now how can I find the table name to which the field belongs....
    Points will be surely awarded...
    Thanks

    Hi,
    To know the master table for the field:
    Go to se11 and give ur field name in the data type selecttion and click on Display.
    Double click on Domain. Goto Value range tab page. In the bottom you can see Value table.
    With rgds,
    Anil Kumar Sharma .P

  • How can one find the table name of the Delta Que and setup table?

    Hi !
    Is there any method to find the table name of the delta que and Extraction que ?

    setup table = <extract structure>_setup
    example: setup table for MC11VA0ITM = MC11VA0ITM_SETUP
    Delta Queue is based on following 3 tables:
    ARFCSDATA
    ARFCSSTATE
    TRFCQOUT
    assign points if useful ***
    Thanks,
    Raj

  • What's the query to find all requests' name of all modules EBS R12.1.3??

    What's the query to find all requests' name of all modules EBS R12.1.3??
    Regards:
    Shahzad M. Saleem

    Dear rioman !!!
    Thanks!!
    Regards:
    Shahzad M. Saleem

  • Need a query to find a table by two of its column names

    I work in software quality assurance. Oftentimes I am trying to figure out from which table data is being pulled, but the database has thousands of tables to look through. Instead of looking through all the tables, I just take a guess at one of the column names and execute a query like this:
    SELECT table_name FROM information_schema.columns WHERE column_name like '%pur%code%'
    That usually works, but occassionally it can return hundreds of table names which doesn't help me much. Instead, I'd like to form a query that could take two column names and return all the tables that have those columns.
    So, in English, I want to say:
    "Give me the names of all the tables that have a column named like %pur%code% and another column named like %client%loc%"
    How do I do this?

    One might have hoped that the QA guy actually had sufficient documentation to tell him which table information was "pulled from".
    (or is he actually checking that the documentation is accurate and complete .... )
    SQL> select phrase from well_known
             where upper ( phrase ) like '%PIG%' and upper ( phrase ) like '%FLY%'

  • Query to find out tables using view

    Hi
    I have a views using three tables.Now i wanted a query to find out number of views using three tables
    I have written a query
    select * from dba_views where text like '%SELECT%;
    It is giving me error as ora error EXPECTED NUMBER GOT LONG.
    Appreciate your help?

    SELECT DECODE(referenced_type, 'NON-EXISTENT', '.....',
    referenced_type) || ' ' || referenced_owner ||
    '.' || referenced_name r_name, ' is referenced by: ' ||
    type || ' ' || owner || '.' || name name,
    ' Referenced Link: ' || DECODE(referenced_link_name,
    NULL, 'none', referenced_link_name) r_link
    FROM dba_dependencies
    -- WHERE owner NOT IN ('SYS', 'SYSTEM')
    -- and rownum < 50
    ORDER BY 1,2;
    add your own where clause to it

  • How To Find Out Table Name At Database Level Trigger

    Table Name
    How do I will come to know the name of table on which currently DML statement is fired ?
    e. g. My current user is SCOTT. So Scott should realize the event of DML Statement fired. Hence my question is how the trigger on User Level is to be written & how to catch the event & table name on which the statement is being executed.
    Suppose my table is as follows
    Table Name : EMP
    EMPNO number
    ENAME varchar2(10)
    JOB varchar2(9)
    MGR number
    HIREDATE date
    SAL number
    COMM number
    DEPTNO number
    Bcd number
    Brcd number
    Rec_id number
    Scn_no number
    Sequences for above table
    1. EMP_REC_ID - minimum value is 1 increment by 1 & max value is unlimited
    2. EMP_SCN_NO - minimum value is 1 increment by 1 & max value is unlimited
    I have written a trigger as follows :
    CREATE OR REPLACE TRIGGER UPD_EMP_REC_SCN BEFORE INSERT OR UPDATE OR DELETE ON EMP REFERENCING NEW AS NEW OLD AS OLD FOR EACH ROW
    DECLARE
    BEGIN
    IF (INSERTING) THEN
    SELECT EMP_REC_ID.NEXTVAL INTO :NEW.REC_ID FROM DUAL;
    ELSIF (UPDATING) THEN
    SELECT EMP_SCN_NO.NEXTVAL INTO :NEW.SCN_NO FROM DUAL;
    ELSIF (DELETING) THEN
    INSERT INTO DELETED_ROWS (TAB_NAME, BCD, BRCD, REC_ID)
    VALUES (‘EMP’, :OLD.BCD, :OLD.BRCD, :OLD.REC_ID);
    END IF;
    END;
    Hence My problem is
    If my database user contains 800 tables then I have to write down 800 triggers (i.e. for each table).
    I want to write only one trigger at database level so that I can dynamically take actions, for this I need table name and the event on which the dml event has taken place.
    Any help in this matter will be greatly appreceiated.
    Regards
    Vikrant

    You cannot write a single trigger that applies to multiple tables. If you need a trigger for every table, you will need to generate 800 triggers.
    Rather than manually generating 800 triggers, you might write a code generator that generates triggers for each of the tables by querying the data dictionary (i.e. DBA_TABLES, DBA_TAB_COLS, etc).
    Justin

  • How to find out table name for the field in the webUI

    Hi.
    I am in CRM2007.
    So i go to the transaction code    BSP_WD_CMPWB
    In that i provide the component name as CRM_UI_FRAME.
    I press the Test button.
    So, it opend the WebUI.
    I want how to find out table of the particular input field?
    I mean from which table the data is retrived how to find out?
    When i enter some thing in the input field how to find out in which table that data is stored?
    By pressing F2 on the input field it opend View and Component Name.
    I want find out table of that particular field. How to find it?
    If anybody know about this explain it with Screen shorts if possible.
    Thank You.
    Krishna. B.

    hi
    goto tx genil_model_browser. Suppose you want to find fields reated to your order header eg sold to name. In component set write all and press F8. Then goto access object and in access object click on node BTAdminH. Click on attribute structure. Here you will find structure and attributes. If you click relationship then you will see all the relationship wrt btadminh. open any r/s that you require. and click on other object and attribute. You will get to know the structure.
    Best regards
    Pankaj kumar

Maybe you are looking for