data in multiple tables and columns

Hello

How to find if multiple tables are containing the same data?
Text of the 'Apple' is in three different tables and under three different column names.
Expected result
 
fruits_one
fruits_two 
fruits_three
Select name, quantity from fruits_one;
Apple   1
Orange  1
Pear    1


select flavour, desc from fruits_two;
Red,   Apple 
Blue, Berry

select order,date,details  from fruits_three;
101  11/11/2011    Grapes
102  12/01/2010    Apple
Thank you
Sandy
SQL> create table fruits_one (name varchar2(100), quantity number);

Table created.

SQL> insert into fruits_one
  2  select 'Apple'  name, 1 quantity from dual union all
  3  select 'orange'  name, 1 quantity from dual; 

2 rows created.

SQL> commit;

Commit complete.

SQL> create table fruits_two (flavour varchar2(100), des varchar2(100));

Table created.

SQL> insert into fruits_two
  2  select 'Red' flavour,   'Apple' des  from dual union all
  3  select 'blue' , 'berry'  from dual ;

2 rows created.

SQL> commit;

Commit complete.

SQL> set serveroutput on
SQL> declare
  2  l_search varchar2(10) := 'APPLE';
  3  l_cnt number := 0;
  4  begin
  5
  6  for x in (select column_name, data_type, table_name from user_tab_cols where data_type in ('VAR
CHAR2'))
  7  loop
  8
  9    execute immediate  'select count(*) from "' || x.table_name ||'" where upper("' || x.column_n
ame || '") like ''%' || l_search || '%''' into l_cnt;
 10
 11    if l_cnt > 0  then
 12    dbms_output.put_line('table = "' || x.table_name ||'", column = "' || x.column_name ||'"');
 13    end if;
 14
 15  end loop;
 16
 17  end;
 18  /
table = "FRUITS_ONE", column = "NAME"
table = "FRUITS_TWO", column = "DES"

PL/SQL procedure successfully completed.

SQL> 

Tags: Database

Similar Questions

  • The most effective way to insert form data into multiple tables and w/autonum

    Hi all, this is my first post here. I am new to APEX and PL/SQL. I have ColdFusion and SQL, and I'm used to perform CRUD operations in my CF Tags application files. From what I've read so far, so if this is accurate, it seems that it is more efficient to perform most of the CRUD operations on the database side, I hope that for advice on the best way to accomplish what I ask - even if I'm trying to do is better off in my new APEX application I am open to this information as well.

    I have a form whose data must reside in two tables. Table A is a one-to-one relationship table and stores General information for each request. Table B is a table of one-to-many observations and should store unique records for each type of comment entered on the form, of which there are 3 comment fields on the form, I'd end up with 3 disks in table B for 1 in table A. I am generating an AutoNumber for table A with a sequence and relaxation. I want to do is take the AutoNumber I just created and use it for insertion in the Table B each insertion I have to do. This is where I am stuck.

    I would like to comment on 1) where I should put all these operations and 2) how best to go about what I want to do coding. In ColdFusion, it is as simple as inserting the record in Table A, immediately asking to table A more recent recording and storing (auto) ID in a variable and then using this var for any other table insertions, I had to do. I know it must be at least a little easier in the Oracle world, I just need a nudge in the right direction. Thank you!

    OraclePledge,

    You're pretty close to not having worked with oracle a lot.

    This section is backwards:

    insert into sch.tbl_main(cust_lname,cust_fname,acct_num)
    values(:P3_CUST_LNAME,:P3_CUST_FNAME,:P3_ACCT_NUM);
    
    select "SCH"."TBL_MAIN_SEQ".currval
          into
          v_ID
          from dual;
    

    Even if it will work if you only have a single user, it's a potential bug with two or more users. First select the key (if it's first use nextval rather than currval) can use it in the insert statement.

    See you soon,.
    Janet Tyson

    Published by: Tyson Janet on June 23, 2011 10:48

  • Comment of tables and columns are included in the Data Modeler

    Hi all
    I used Oracle SQL Developer Data Modeler (Version 3.0.0.665) and created a data model for my project. I sent an email a PDF version of the data model to our systems analyst. She asked if I could re - create the data model and include table and column comments. Is this possible and if so how this work is it?

    Thank you for your comments,

    Seyed

    Seyed salvation,

    I used the Data Modeler and create a report. The report included 36 .csv files

    What is the purpose of this 'report' task, because 36 files csv does not sound like report to me. Watch "files > reports" feature - you can generate reports for your model. -for any model, single table or tables belonging to specific subview. The report of the complete table contains additional details, so if you need these comments, then only you can create a template and select column comments appear only. So some general information table will be also included.

    Philippe

  • Select the data in a table and update in another table

    Dear experts,

    create the table TB_ENCRYPT

    (

    Identification number,

    Varchar2 (200) KEY

    );

    INSERT INTO TB_ENCRYPT VALUES(1,'HJUVHDUIFBSDGVU');

    SELECT * FROM TB_ENCRYPT;

    1 HJUVHDUIFBSDGVU

    create TABLE users)

    username, NUMBER of

    password VARCHAR2 (200)

    );

    Insert users

    values (1, 123 # "")

    Insert users

    values (2, 456 #')

    Select * from users;

    1 123 #.

    # 2 456

    I want to select the data KEY for table TB_ENCRYPT column and update in the column of tables for the respective key user password

    TB_ENCRYPT table contains only a single key value. Comparing this key, I want to update the old value of the key to the new value.

    For encryption and decryption I followed the java class method.no is worried about that.

    create or replace

    PACKAGE PCK_ENC AUTHID CURRENT_USER AS

    FUNCTION DECRYPT (VARCHAR arg0, arg1 VARCHAR) AS VARCHAR BACK LANGUAGE JAVA NAME 'Encrclass.decrypt (java.lang.String, java.lang.String) return java.lang.String ';

    FUNCTION ENCRYPT (VARCHAR arg0, arg1 VARCHAR) AS VARCHAR BACK LANGUAGE JAVA NAME 'Encrclass.encrypt (java.lang.String, java.lang.String) return java.lang.String ';

    END;

    SELECT PCK_ENC. ENCRYPT('1234','HJUVHDUIFBSDGVU') FROM DUAL;

    HERE,

    1234 - is the password of the users table column data

    HJUVHDUIFBSDGVU - represents the key of table TB_ENCRYPT column data.

    Comparing this key, I want to update the old value of the key to the new value.

    I tried with this method

    declare

    cursor c1 is

    Select the key

    of TB_ENCRYPT

    where id = 1

    update the id;

    Start

    for c1_rec looping c1

    update users

    password is PCK_ENC. Encrypt (Password, Key)

    the location being c1;

    commit;

    end loop;

    end;

    /

    Help, please

    You can use the MERGE statement.

    merge into users
    using tb_encrypt
       on (id = userid)
      when matched then
          update set password = PCK_ENC.ENCRYPT(password,key);
    

    And why you encrypt your password. This isn't a good idea. Just password hash.

  • Size of the data in a table and the size of the table

    I am trying to determine the size of the data in a table and also the overall table size. I use the following query:

    SELECT BOTTOM (a.owner) as owner,
    LOWER (a.table_name) AS table_name,
    a.tablespace_name,
    a.Num_Rows,
    ROUND ((a.blocks * 8 / 1024)) AS size_mb,
    a.Blocks,
    a.Blocks * 8 Blocks_Kilo_Byte.
    a.PCT_FREE,
    a.compression,
    a.Logging,
    b.bytes / 1024 / 1024
    From all_tables a, dba_segments b
    WHERE the a.owner AS SUPERIOR ("USER_TEST")
    AND a.table_name = "X_TEST_TABLE."
    AND b.segment_name = a.table_name
    AND b.owner = a.owner
    ORDER BY 1, 2;

    Is this the right way to go about finding the size of the data in a table? If this isn't the case, please give your suggestions.

    BTW, this in a 10g version.

    You probably want to use the DBMS_SPACE package. In particular, the procedures SPACE_USAGE and UNUSED_SPACE to get an accurate account of the use of space in a table. Your application may give you a relatively accurate estimate if the optimizer on your table's statistics are reasonably accurate estimates. But there is no guarantee that the optimizer statistics are accurate.

    If you want just an approximate answer and you're comfortable that your statistics are accurate, this query may be close enough. If you want a specific response, however, use the DBMS_SPACE package.

    Justin

  • Find the key referenced foreign Table and column

    Can someone please refresh my memory?

    How can I determine which table and column refers to a foreign key?

    For example, with select * from ALL_constraints WHERE TABLE_NAME = 'my_table '; I can see forced CONSTRAINTA_FK and CONSTRAINTB_FK I guess reference another table and column because CONSTRAINT_TYPE = "R", but it isn't that I get. "

    I would get all the way to the referenced table and the column I just don't remember how.

    Thank you

    Lou

    Hello

    Example:

    Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
    Connected as hr
    
    SQL>
    SQL> SELECT UC.TABLE_NAME,
      2         UC.R_CONSTRAINT_NAME,
      3         UCC.TABLE_NAME,
      4         UCC.COLUMN_NAME
      5    FROM USER_CONSTRAINTS  UC,
      6         USER_CONS_COLUMNS UCC
      7   WHERE UC.R_CONSTRAINT_NAME = UCC.CONSTRAINT_NAME
      8     AND uc.constraint_type = 'R'
      9   ORDER BY UC.TABLE_NAME,
     10            UC.R_CONSTRAINT_NAME,
     11            UCC.TABLE_NAME,
     12            UCC.COLUMN_NAME;
    
    TABLE_NAME                     R_CONSTRAINT_NAME              TABLE_NAME                     COLUMN_NAME
    ------------------------------ ------------------------------ ------------------------------ --------------------------------------------------------------------------------
    COUNTRIES                      REG_ID_PK                      REGIONS                        REGION_ID
    DEPARTMENTS                    EMP_EMP_ID_PK                  EMPLOYEES                      EMPLOYEE_ID
    DEPARTMENTS                    LOC_ID_PK                      LOCATIONS                      LOCATION_ID
    EMPLOYEES                      DEPT_ID_PK                     DEPARTMENTS                    DEPARTMENT_ID
    EMPLOYEES                      EMP_EMP_ID_PK                  EMPLOYEES                      EMPLOYEE_ID
    EMPLOYEES                      JOB_ID_PK                      JOBS                           JOB_ID
    JOB_HISTORY                    DEPT_ID_PK                     DEPARTMENTS                    DEPARTMENT_ID
    JOB_HISTORY                    EMP_EMP_ID_PK                  EMPLOYEES                      EMPLOYEE_ID
    JOB_HISTORY                    JOB_ID_PK                      JOBS                           JOB_ID
    LOCATIONS                      COUNTRY_C_ID_PK                COUNTRIES                      COUNTRY_ID
    TEMP_LEAVE                     PK_CLIENT                      CLIENT                         CLIEND_ID
    VISITORS                       SYS_C004169                    GROUPS                         GROUPID
    VLANGS                         SYS_C004170                    VISITORS                       VISITORID
    
    13 rows selected
    
    SQL> 
    

    In the output:

    TABLE_NAME                     R_CONSTRAINT_NAME              TABLE_NAME                     COLUMN_NAME
    ------------------------------ ------------------------------ ------------------------------ --------------------------------------------------------------------------------
    COUNTRIES                      REG_ID_PK                      REGIONS                        REGION_ID
    

    means that a COUNTRY table has a foreing key called REG_ID_PK that points to an array of AREAS. REGION_ID
    Kind regards

    Published by: Walter Fernández on March 4, 2009 23:26 - adding explanation...

  • Write multiple rows and columns of the worksheet

    Is it possible to write several rows and columns of the spreadsheet, with the ability to add data to the file and create a new file if it does not exist?
    I tried to write to table vi, but I couldn't make it work.
    It won't let me write several lines in the same column.
    Can someone please give me an example?
    Thanks in advance.

    If you want to use the tab character (\t) as the delimiter, then check the txt file.  Then Excel will open as you wish.

    If you want to keep the csv extension, then use comma (,) as a separator.

  • Rename tables and columns in sql running that accessing these columns in the table.

    Hello

    Using oracle 11.2.0.3

    We want to rename columns, tables and work just a sql scripts for this.

    If sqls who have access to those running long tables/columns for example reports what is happening

    Existing sql running, will work perfectly in that picked up sql before table/colum rename or will they crash if tables/columns renamed during them.

    scripts wil take a few seconds to run maximum

    Thank you

    The only other activity that would go on select is against these tables/columns. No etl isnert/update/delete etc wil, which happened during the name change.

    Only possible activities are report instructions srunning select.

    Tried to run a long selection and rename that select while that was going on and got no error on the test system.

    This is because certain statements does not place locks on tables or lines, so even if a session is reading data, another session can make some ddl (or dml) manipulation.

    In this situation (with only selects, no other dml queries), renaming can be done, but the question remains, what the application code?

    If it refers to old column names after name change operation, is no good.

  • Create the form for selecting data in multiple tables

    Hello

    I'm getting APEX for the first time and I just read 2 days dev Application Express guide

    I tried to play and I can't create a report with the form that select data from several tables

    What I want to achieve is a report we'll say 'USERS' makes MANAGER_ID ID, NAME, with a form that allows me to create, delete, change users

    The problem is that, once the report with the form created, if I click on create (to create a user) it will ask me for id, name, and manager_id

    I need a water drop down which allows me to select managers in the table manager instead of manually insert Director id

    How do I do that?

    Thank you!

    HI Chris,

    LOV will use this magic.

    Search:

    Kind regards

    BEnjamin

  • Protect a document while allowing the insertion of data in a table and the points on a graph.

    I created a Word document that contains a table and a chart.  Can I protect document but allow data entry in the table and allow points appear in the table using Adobe?

    Hi brianh89327665,

    While you can apply a permissions password to a PDF file to prevent things such as printing and editing the document, you can not apply it selectively to parts of the PDF file.

    Best,

    Sara

  • Select Max (date) between multiple tables

    I need to retrieve a record from a Table in a set of similar tables with a common "date field". You can select the record where this "date field" value is greater between multiple tables.

    Here, any help is appreciated.  Thank you in advance.

    FOR EXAMPLE

    No. EMP is the primary key.

    Again, each table can have multiple records for EMP n ° 1

    TABLE1:

    FIRST NAME

    FAMILY NAME
    THE EMP NO.

    BASE SALARY

    DATE_FROM

    TABLE 2

    FIRST NAME

    FAMILY NAME
    THE EMP NO.

    SALARY GRADE

    DATE_FROM

    TABLE 3

    FIRST NAME

    FAMILY NAME
    THE EMP NO.

    COMPENSATION

    DATE_FROM

    Hello

    Said Knani, if you use the current design of the table, then here is a way to do what you want:

    WITH union_data AS

    (

    SELECT MAX (base_salary) AS sal FROM table1 UNION ALL

    SELECT MAX (grade_salary) table2 UNION ALL

    SELECT MAX (compensation) FROM table3

    )

    SELECT MAX (sal) AS max_sal

    Of union_data

    ;

  • Alias table and column aliases

    I'm new to the discoverer. I have some confusion.


    1. If it is possible use different aliases for the same table during the creation of spreadsheet?

    Need to produce different joins.

    for example:

    SELECT C1. Name, C2. Remarks

    CLIENTS C1,.

    C2 customers,

    Ticket T,

    Sale S

    WHERE C1. Client_Id = T.Client_Id AND C2. Client_Id = S.Client_Id

    2. How can I use the Alias column to show as a custom in the worksheet column heading?

    for example:

    SELECT Client_Default_Name AS name OF customers


    Thanks in advance.

    Hello

    first question:

    the sql worksheet is always structured according to the EUL (the end user layer). If you have used two customer tables and created a join of tables then the sql is generated according to your requirement. There is no way we can have discoverer create a sql like this. If you are interested with the sql. You can create a custom in the business district folder and paste the sql code and create a report on the top of the custom folder.

    second question:

    You can always change the topic in the discoverer more filing cabinets according to your requriement

    hope this helps

    -N.S.

  • to ensure the integrity of data in multiple tables materialized

    Hello



    I have a problem and I am not able to solve. Partly, it's because of my poor knowledge of SQL. I have three tables and I use a sequence to enter data into them.

    I am attached to is to create a materialized view (full or quick, depending on) with discount to the validate option to verify that each table contains unique data to each other.



    I write code so you can get there:


    CREATE TABLE table_1 (
    ID NUMBER PRIMARY KEY
    
    );
    
    
    
    CREATE TABLE table_2 (
    ID NUMBER PRIMARY KEY
    
    );
    
    
    
    CREATE TABLE table_3 (
    ID NUMBER PRIMARY KEY
    
    );
    
    
    
    INSERT INTO table_1 VALUES (1);
    
    INSERT INTO table_1 VALUES (2);
    
    INSERT INTO table_2 VALUES (3);
    
    INSERT INTO table_2 VALUES (4);
    
    INSERT INTO table_3 VALUES (5);
    
    INSERT INTO table_3 VALUES (6);
    I want to write create a materialized view that will give me the output only in the case that it has same values in two different tables. I had to date.


     
    
    
    CREATE MATERIALIZED view mv_test 
    REFRESH COMPLETE ON COMMIT
    AS
    SELECT count(1) ROW_COUNT
    FROM dual 
    WHERE EXISTS (
         SELECT a.id 
         FROM table_1 a
         WHERE a.id IN(
             SELECT b.id 
             FROM table_2 b)) 
    OR EXISTS (
        SELECT a.id 
         FROM table_1 a
         WHERE a.id IN
                 (SELECT c.id 
                 FROM table_3 c))
    OR EXISTS (
        SELECT b.id 
             FROM table_2 b
        WHERE b.id IN
                 (SELECT c.id 
                 FROM table_3 c)); 
                 
        ALTER MATERIALIZED VIEW mv_test
        ADD CONSTRAINT cs_mv_test
        CHECK (row_count = 0) DEFERRABLE;
    This sql statement itself returns no line if my logic is correct. And in case there was a few lines in two different tables, it would return 1 and constraint would throw an error.



    However, I can't create this with ON COMMIT option. When I try to compile I get:


     
    
    
    
    ORA-12054: cannot set the ON COMMIT refresh attribute for the materialized view
    I went through the documentation, I tried mat_view creation logs etc.

    I know that one of the mistakes is that I am referencing the double table and I don't know if I can use EXISTS.



    Unfortunately, my SQL wisdom ends here. I need help to rewrite the sql code, so it would be a materialized view with Refresh on the validate option. Help, please!



    I know that since I'm on a sequence there is little chance that same value will enter into two different tables, but I would like to make somekind of audit.





    Thank you in advance.

    >

    I know that since I'm on a sequence there is little chance that same value will enter into two different tables, but I would like to make somekind of audit.

    If you are certain that you control all the entries in the table and you are probably using a sequence to be inserted in the three tables then there is physically no possible in all tables, you will get duplicate values.

    Write something to check if it is the case would be nearly identical to writing something to verify that 1 + 1 is really equal to 2 in 100% of cases.

    If you need to, however. consider something similar to what can be better that follows:

    select *
      from table_1 t1
      full outer join table_2 t2 on (t1.id = t2.id)
      full outer join table_3 t3 on (t1.id = t2.id
                                     or
                                     t2.id = t3.id)
     where t1.id+t2.id+t3.id not in (t1.id,t2.id,t3.id);
    
  • Flexible, set up including the tables and columns of text?

    I need to set up tables (annual report) and some text between the two notes.

    I would like to have frames as little as possible on every page - for InCopy workflow later.

    If I paste the text of the regular column in the frames containing the tables anchored that I must apply the shift of different basis for each block of anchor text, text which is not a nice workflow.

    Can you recommend a skillful means and flexible to set this place that will make the tables and text boxes flows if more lines or more text are added?

    Best regards

    Nina storm

    For this test I did it manually, but I have no reason to think that it would behave differently as part of a style. As far as I know, ID will attempt to balance the two columns automatically. If there is not enough text to divide into two columns it will not appear to divide but always see you any extra spacing and add just enough text to be wider than the column width of Courland and your line will have a gap in it for the gutter of the column.

    OK, I've just defined a style with the attribute of split, and Yes, it works in the same way. If you have a single paragraph, the paragraph is divided. If you have more than one, the block is divided, reading down by the first paragraph to the second (assuming that the linecounts work that way) in the first column before splitting into the second column. Paragraphs distributed individually. ID is to balance my columns automatically and will adjust the break if I edit, and if the number of rows is not divisible by 2 short column is on the right.

  • DBMS_FGA.add_policy... How to handle multiple tables and multiple users

    Dear all,

    My database is 11 GR 1 material and Linux is the platform.

    I have over 50 very important tables and about 15 users database.

    I want to implement an audit fine-grained on these important tables.

    This is how I will implement:

    SQL > START
    () DBMS_FGA.add_policy
    object_schema = > 'Scott ',.
    object_name = > "SAL."
    POLICY_NAME = > "SALARY_CHK_AUDIT"
    audit_condition = > NULL,
    handler_schema = > 'imran.
    statement_types = > 'SELECT, INSERT, UPDATE, DELETE.
    audit_column = > NULL);
    END;
    /

    What is I have several tables of several users and object_schema in handler_schema.

    I hope I'm able to clear my question, doubts please let me know.

    Best regards, Imran

    Hello

    object_schema - the schema of the object to be audited. (If the value is NULL, the schema of the current user is supposed).
    in case if you want to audit for multiple users - then make a test taking a value null and test access important tables - where relevant audit records are generated according to your requirement or not. I have not tested... try it

    -Pavan Kumar N

Maybe you are looking for

  • iPhone 5 value stopped silent vibrate with incoming text

    Noticed that with iPhone5 set to silent, vibration-free wanted me text messages alerts. tried the reset and still nothing tried next series/top of another iPhone 5 which worked well... But still not vibrating while on silence, for text messages... ve

  • Firefox crashes on startup after update

    After the latest Automatic update, Firefox crashes whenever I start it. Uninstalled it, downloaded the fresh installation files, installed these - even of the accidents.

  • no idea how to tell firefox that .qfx files should start quicken 2007?

    Firefox 3.6.3 (Mac) knows only .ofx Quicken files. I don't find any obvious way to add. QFX to the list and the dialog box ('open with this application', always "do it in the future) hasno effect. huh? This has happened Each time Firefox opened Is th

  • I lost my recycle bin

    I don't know where he was going.  I tried to do a search for trash on my computer.  He came in white.  I tried to Auto sort by the desktop icons by right-clicking on the desktop.  It still does not appear on my desktop.  Is someone can you please tel

  • Satellite P300D - wireless connection problems

    Good evening. Sorry for my bad English. Here's my problem: whenever I try to install my wireless modem, my computer shuts down, the blue screen before connecting off the coast with many words that I did not have time to read. The modem is certainly n