Querying the schema for table name with column value!

In my schema i have 500+ tables and other objects.
i have a column with the name BO_PRODUCT_CODE.
I wants to know in what tables the value of BO_PRODUCT_CODE='FX03'.
i have query the user_tab_columns which gives me the result with 90 tables having the column BO_PRODUCT_CODE.
What is query which will give me the exact number/name of the table whose column value is FX03. ie, BO_PRODUCT_CODE='FX03'.

Hi you can use this approach:
BEGIN
v_str VARCHAR2(250);
v_count NUMBER :=0;
DECLARE
FOR loop_tbl IN ( SELECT DISTINCT table_name FROM USER_TAB_COLUMNS
WHERE column_name ='BO_PRODUCT_CODE' )
LOOP
v_str := 'SELECT COUNT(*) FROM ' || loop_tbl.table_name || ' WHERE BO_PRODUCT_CODE=||'''' ||'FX03' || '''' '
EXECUTE IMMEDIATE v_str INTO v_count ;
IF v_count > 0 THEN
DBMS_OUTPUT.PUT_LINE ('Table Name :'|| loop_tbl.table_name || ' Count :'||v_count);
END IF;
v_count :=0;
END LOOP;
EXCEPTION
WHEN others THEN
DBMS_OUTPUT.PUT_LINE(SQLERRM);
END;
Please remove if any syntax error.
Regards

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.

  • Using a Variable for Table Name  with a cursor

    Hello All
    Is it possible to use a Parameter passed to a procedure as the table name
    in a cursor selection statment. I thought the below would work but I get
    a error. Does anyone have any ideas?? The Error is listed below to.
    Here's the code I just complied
    CREATE OR REPLACE PROCEDURE Dup_Add(NEWQATABLE IN VARCHAR2) IS
    CURSOR c1 IS SELECT MUNI,PROV FROM NEWQATABLE GROUP BY MUNI, PROV;
    c1rec c1%ROWTYPE;
    BEGIN
    OPEN c1;
    LOOP
    FETCH c1 INTO c1rec;
    EXIT WHEN c1%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE(c1rec.MUNI);
    END LOOP;
    CLOSE c1;
    END;
    Here is the errors
    LINE/COL ERROR
    3/8 PLS-00341: declaration of cursor 'C1' is incomplete or malformed
    3/15 PL/SQL: SQL Statement ignored
    3/38 PLS-00201: identifier 'NEWQATABLE' must be declared
    5/7 PL/SQL: Item ignored
    10/3 PL/SQL: SQL Statement ignored
    10/17 PLS-00320: the declaration of the type of this expression is
    incomplete or malformed
    12/3 PL/SQL: Statement ignored
    12/24 PLS-00320: the declaration of the type of this expression is
    incomplete or malformed
    LINE/COL ERROR
    Thanks
    Peter

    If you are going to have a table name or a column name as a parameter, then you have to open the cursor dynamically. The following example uses Native Dynamic SQL (NDS) to open a ref cursor dynamically. I also eliminated the group by clause, since it is intended for use with aggregate functions and you weren't using an aggregate function. Also notice that there are some other differences in terms of defining variables and fetching and so forth.
    SQL> CREATE TABLE test_table
      2  AS
      3  SELECT deptno AS muni,
      4         dname  AS prov
      5  FROM   dept
      6  /
    Table created.
    SQL> CREATE OR REPLACE PROCEDURE Dup_Add
      2    (newqatable IN VARCHAR2)
      3  IS
      4    TYPE cursor_type IS REF CURSOR;
      5    c1 cursor_type;
      6    c1muni NUMBER;
      7    c1prov VARCHAR2 (20);
      8  BEGIN
      9    OPEN c1 FOR 'SELECT muni, prov FROM ' || newqatable;
    10    LOOP
    11      FETCH c1 INTO c1muni, c1prov;
    12      EXIT WHEN c1%NOTFOUND;
    13      DBMS_OUTPUT.PUT_LINE (c1muni || ' ' || c1prov);
    14    END LOOP;
    15    CLOSE c1;
    16  END;
    17  /
    Procedure created.
    SQL> SHOW ERRORS
    No errors.
    SQL> SET SERVEROUTPUT ON
    SQL> EXECUTE dup_add ('test_table')
    10 ACCOUNTING
    20 RESEARCH
    30 SALES
    40 OPERATIONS
    PL/SQL procedure successfully completed.

  • JDBC Schema and Table Names Reversed

    Hi,
    We're currently evaluating CR4E but are unable to successfully run/preview any reports.
    We have successfully created a JDBC  connection using the generic JDBC driver. We are connecting to an Ingres database. The connection is successful and we can browse databases/schemas/tables with no problem. The problem is with the SQL that the reporting engine is generating.
    A simple example:
    SELECT "currency"."description" FROM   "currency"."john" "currency"
    In this statement, "currency" is actually the table and "john" is the schema name.
    The query should read:
    SELECT "currency"."description" FROM   "john"."currency" "currency"
    Help would be appreciated as we're completely stuck.
    Many thanks,
    Darran Smith

    Hi Tej,
    Thanks for clarifying the issue on the JRC.
    Executing:
    SELECT "price_type"."currency", "price_type"."description" FROM   "price_type"."john" "price_type"
    against the DB results in "Table 'john' does not exist or is not owned by you" as expected.
    Executing
    SELECT "price_type"."currency", "price_type"."description" FROM   "john"."price_type" "price_type"
    against the DB works just fine.
    I amended my code to simply call:
    CRJavaHelper.changeDataSource(reportClientDocument, userName, password, connectString, driverName, JNDIName);
    and changed the CRJavaHelper.java file around line 145 that originally reads:
    newTable.setQualifiedName (origTable.getAlias ());
    I tried setting the qualified name to various different things:
    "price_type"
    "john.price_type"
    "otherSchema.price_type"
    None of these worked, but they did produce different things in the JDBC trace log. I've uploaded the JDBC log file to showing what happens with either "price_type" or "john.price_type":
    [http://www.romofabrics.com/iijdbc.txt|http://www.romofabrics.com/iijdbc.txt]
    As you can see, everything looks OK (including the schema and table name) until the very final select statement is created.
    When you say that generic JDBC is supported, is that what I'm effectively using?
    Cheers,
    Darran

  • Query to find out the table name and column name..

    Hi Experts,
    I have an Oracle DB in which has more than 50 tables and 100,000 records. I want to get the record which contains *"ITxtVarValue references a non existing text"* the text.
    Is there any query there to find out the table name and column name of this particular record where it reside?
    Please help. Any help will be rewarded.
    Thanks,
    G

    Using this forum's search function, I found a thread that should give you an idea: How to find out a tablename
    C.

  • How to query / list table name with certain data type?

    Hi all spatials,
    Sorry for the dumb question. I need to make a query that list all table name that contain certain data type, eg. SDO_georaster. How to do this ?
    Many thanks in advance
    damon

    Skip it. I figured it : using USER_TAB_COLUMNS will definitely help.
    Cheers
    damon

  • 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

  • I need the sap bw table names for ROLE's

    I need the sap bw table names for ROLE's .
    thanks

    Hi,
    AGR_1251 - Authorization data for the activity group
    AGR_USERS - Assignment of roles to users
    AGR_TCODES - Assignment of roles to Tcodes
    You can also try putting AGR* in ur search.
    -Vikram

  • How to query the "Schema" in the Reporting Schema?

    I need to be able to report on a specific set of tables with my model.
    I have elected to group them under one Schema.
    I was thinking I could write a custom report via the Reporting Schema and select the tables based on the schema they are associated with.
    However, I dont see the table within the SQLDeveoper Model Reporting Schema that containes the mapping of tables to a schema.
    Is this missing from the export?
    If yes, what would be a better way of doing this type of grouping?
    Thanks
    Mark

    Hi Mark,
    Schema is not exported to reporting repository.
    You can use Classifications types to group tables, entities etc. And you can create your own classification types. There is field classification_type_ovid in dmrs_tables table which can be used as filter.
    Another way of grouping is using Sub Views. In that case these are the queries:
    --This returns all main views + sub views, exported to DB, filter in Where clause for specific design could be applied
    SELECT CASE
    WHEN d.diagram_type = 'MainView' THEN d.model_name
    ELSE ''
    END as "Model Name",
    d.model_ovid as "Model OVID",
    CASE
    WHEN d.diagram_type = 'Subview' THEN d.diagram_name
    ELSE ''
    END as "Sub View",
    d.ovid as "OVID"
    FROM dmrs_vdiagrams d,
    dmrs_models m
    WHERE d.model_ovid = m.model_ovid
    --AND    d.design_ovid = column design_ovid from DMRS_DESIGNS table
    --AND    m.model_type = 'Relational' (or 'Logical')
    ORDER BY d.model_name,d.diagram_type, d.diagram_name
    - This return all all tables withing specific sub view
    SELECT t.table_name as "Table Name",
    t.ovid as "OVID"
    FROM dmrs_tables t,
    dmrs_diagram_elements de,
    dmrs_vdiagrams d
    WHERE de.ovid = t.ovid
    AND de.diagram_ovid = d.ovid
    AND d.ovid = -> this is subview ovid from above query
    Regards

  • 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.

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

  • Passing table name and columns name as parameters to procedure

    i need a procedure that take table name and column names as parameters .
    it should display all values in those columns
    like
    if i execute procedure p ( t1,c1,c2)
    it should display c1,c2 values in t1 table
    if i execute procedure p ( t1, c1,c2,c3)
    it should display c1,c2,c3 values in t1 tables
    no of column parameters changes

    See if this helps...
    First, read the manual on collections.
    Second, define your expected results. You want to output the results to the screen? You cannot perform a 'select' in PL/SQL. You will have to select your output into another collection, then loop through that.
    Finally, I am curious why this is necessary versus performing a regular query.
    Take a look at this incomplete code.
    create or replace
    package dave_pac
    IS
    TYPE col_name_list IS VARRAY(20) OF VARCHAR2(30);
    PROCEDURE SFA_TAB_COL1
    (p_tname  IN    VARCHAR2
    ,p_cnames IN    col_name_list);
    END;
    create or replace
    package  body dave_pac
    IS
    PROCEDURE SFA_TAB_COL1
    (P_tname  IN varchar2
    ,p_cnames in col_name_list)
    IS
    l_stmt long;
    l_rc number;
    begin
    l_stmt :='select '||p_cnames(1);
    for i in 2..p_cnames.count
    loop
    l_stmt :=l_stmt||' , '||p_cnames(i);
    end loop;
    l_stmt:= l_stmt||' from '|| p_tname ;
    execute immediate l_stmt;
    end ;
    END dave_pac;

  • 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.

  • Can substitution strings be used for table name references?

    Hi,
    I was wondering if it's possible to use substituion strings for table names in SQL queries. This would allow for me to edit all references to a table at one location. For instance, if a table name or dblink changed, I could edit the substitution string or application item to ensure all the queries reference the new table.
    For example:
    select * from &table1.
    table1 would be the substitution string for the actual table name
    I know this is possible if I used a pl/sql function returning a query, but I would much rather use a substition string in a SQL query.
    Thanks in advance.
    Brian

    i think not
    because how create the fields of * in this case
    in the other because all is dynamic, i think that you obtain only an error

  • Impossible to change the Fontsize for a Radiogroup(with Submit).

    Impossible to change the Fontsize for a Radiogroup(with Submit).
    I have a Menue displayed from a Query like (select menue_title, id from lov_tabel)
    and displayed in a Report Region as a Radio group with Submit.
    The problem is, i've not been able to change the font size.
    What i' have tried.
    - Change the color works if i change "+Page Item"-> Element -> HTML Table Celle Attributes+ to
    style="font-size:1.2em; color:#CC00CC" I see the new color but NO change in font-size.
    - If change in Application-> Shared Components-> Templates
    copy the Template "Reports Region" to "MenueReport",
    then change on "MenueReport"->Template
    value to      <table class="t6ReportsRegion" id="#REGION_STATIC_ID#" #REGION_ATTRIBUTES# summary=""
         *style="font-size:1.2em; color:#CC00CC; font-family:Verdana"*>
         <tr><td class="t6Header">#TITLE#</td></tr>
         <tr><td class="t6ButtonHolder">#CLOSE#   #PREVIOUS##NEXT##DELETE##EDIT##CHANGE##CREATE##CREATE2##EXPAND##COPY##HELP#</td></tr>
         <tr><td class="t6Body">#BODY#</td></tr>
         </table>     option style="font-size:1.2em; color:#CC00CC; font-family:Verdana" inserted
         and then change in the template for the report region the Option
         Edit Region->User Interface -> Template to "MenueReport".
         I see a new color but NO font-size will be changed!
    - I have changed the query to     SELECT  ' <font size="4">' || rt_name as x, rt_nr  FROM report_types order by rt_nr     But there is NO change of font size, and the Tag <font size= .. is deprecated.
    Used Version is Apex apex_030200 with Firefox 3.5.5 Windows.
    After all this failed attempts, i have no idea how to change the font for page to a larger size.
    Can anyone help me and explain how to change the font size in Apex for a Radiogroupe?
    Thanks in advanced
    Dieter

    Assign a [static region ID|http://download.oracle.com/docs/cd/E14373_01/appdev.32/e11838/ui.htm#sthref1438] to the region containing the radiogroup.
    Place the following code in the HTML Header page property, replacing static-region-id with the ID given to the region:
    <style type="text/css">
    #static-region-id label {
      font-size:1.2em;
    </style>after that how do we need to call this css
    and does it need to be called within the Region HTML table cell attributes of a region or in the HTML Form Element Attributes of the radio group items
    >
    CSS isn't "called". Learn how [themes, templates|http://download.oracle.com/docs/cd/E14373_01/appdev.32/e11838/themes.htm#CJABAEIE] and CSS are used to control the appearance of APEX applications.

Maybe you are looking for

  • IMessage contact address problems

    I am a little perplexed about how to set up iMessage correctly.  I have iMessage activated.  My settings are that "I can be reached by iMessage" at my phone number and email.  I "Start new conversations from" my email. The first problem I have is whe

  • DISP+WORK PROCESS

    Hi all, I appreciate the help. I am trying to run the disp+work process. It runs for about a minute then stops. Please see below trace file. I can see its getting a login error for \SAPServiceBWP, but am not even trying to run the instance using that

  • Document level scripting

    I have read about document level scripting - This is a nice feature - since it allows a certain level of generalization rather that writing a scriptlet for each objects events. I am using Live cycle designer 8.2 How can I create a document level java

  • Changing the TCP port on async ports in Cisco router

    Hello, My goal is to replace old terminal servers from a factory environment. These terminal servers act as a aggregation point of terminal equipment (printers and factory automation). Software used in this factory writes to these devices using ip-ad

  • FLOAT TO TIME STAMP CONVERSION

    Hi Folks, I am getting some pain while i am converting from float values into timestamp... I have a T1 table and one columns data type as float ...i want convert that float values into time stamp.. Exp: field1(float datatype) 48045.4352222 45065.4452