Query to find columns (in relation FK) which gives bad child result...

I need to find all the columns in a Parent child table. I wrote the below query to do this.

CREATE TABLE test_parent
(      supplier_id      number(10)      not null,
     supplier_name      varchar2(50)      not null,
     contact_name      varchar2(50),      
     CONSTRAINT supplier_pk PRIMARY KEY (supplier_id)
);




CREATE TABLE test_child
(      product_id      number(10)      not null,
     child_supplier_id      number(10)      not null, ---*its child_supplier_id not supplier_id*
     CONSTRAINT fk_supplier
       FOREIGN KEY (child_supplier_id)
      REFERENCES test_parent(supplier_id)
      ON DELETE CASCADE
);


insert into test_parent values (3,'ABC','John');
insert into test_child values (993983,3);


COL TABLE_NAME FORMAT A25
COL CONSTRAINT_TYPE FORMAT A25
COL CHILD_COLUMN FORMAT A25

select     a.table_name, 
     b.column_name child_column
from user_constraints a,
     user_cons_columns b
     where a.r_constraint_name=b.constraint_name
and R_CONSTRAINT_NAME =  (select constraint_name from 
                 user_constraints where table_name = 'TEST_PARENT' -- I enter the parent table name here
                and constraint_type = 'P'
               )
and constraint_type = 'R';


TABLE_NAME                CHILD_COLUMN
------------------------- ------------------------
TEST_CHILD                SUPPLIER_ID
It should be
*child_supplier_id*
Let's not my request. I'm doing something really stupid here.

Try this one

select fk_cons.table_name, fk_cons.constraint_name, fk_cols.column_name
from user_constraints PK_cons
join user_constraints fk_cons on fk_cons.r_constraint_name = pk_cons.constraint_name
join user_cons_columns fk_cols on fk_cols.constraint_name = fk_cons.constraint_name
where fk_cons.constraint_type = 'R'
and PK_cons.table_name = 'TEST_PARENT';

Tags: Database

Similar Questions

  • Text index CONTEXT Oracle which gives bad results!

    Expert Oracle Text,

    I'm on Oracle 11.2.0.2 on Solaris 10 and have implemented the Oracle text features using the CONTEXT index type, and I'm getting a few problems in. I have a need for research with joker as % and giving the wrong exit. Here's the scenario where I get incorrect results:
     
    
    --creating preferences etc 
    exec   ctxsys.ctx_ddl.create_preference ('cust_lexer', 'BASIC_LEXER'); 
    exec   ctxsys.ctx_ddl.set_attribute ('cust_lexer', 'base_letter', 'YES'); -- removes diacritics 
    exec   ctxsys.ctx_ddl.create_preference ('cust_wl', 'BASIC_WORDLIST') 
    exec   ctxsys.ctx_ddl.set_attribute ;    ('cust_wl', 'SUBSTRING_INDEX', 'true'); 
    
    --table set up 
    CREATE TABLE TEST_USER 
    ( 
      FULL_NAME  VARCHAR2(64 CHAR)                  NOT NULL, 
      LAST_NAME  VARCHAR2(64 CHAR)                  NOT NULL 
    ); 
    
    
    CREATE INDEX TEST_USER_IDX5 ON TEST_USER 
    (FULL_NAME) 
    INDEXTYPE IS CTXSYS.CONTEXT 
    PARAMETERS('LEXER cust_lexer WORDLIST cust_wl SYNC (ON COMMIT)'); 
    
    --data set up 
    Insert into TEST_USER 
       (FULL_NAME, LAST_NAME) 
    Values 
       ('Supervisor upervisor', 'upervisor'); 
    Insert into TEST_USER 
       (FULL_NAME, LAST_NAME) 
    Values 
       ('JOSEPH WILSON', 'WILSON'); 
    Insert into TEST_USER 
       (FULL_NAME, LAST_NAME) 
    Values 
       ('CHRISTOPHER Phil', 'TAYLOR'); 
    Insert into TEST_USER 
       (FULL_NAME, LAST_NAME) 
    Values 
       ('PAUL HERNANDEZ', 'HERNANDEZ'); 
    Insert into TEST_USER 
       (FULL_NAME, LAST_NAME) 
    Values 
       ('Betty Jipes', 'Jones'); 
    Insert into TEST_USER 
       (FULL_NAME, LAST_NAME) 
    Values 
       ('One Anna', 'Anna'); 
    Insert into TEST_USER 
       (FULL_NAME, LAST_NAME) 
    Values 
       ('Three Anna', 'Anna'); 
    Insert into TEST_USER 
       (FULL_NAME, LAST_NAME) 
    Values 
       ('Two Anna', 'Anna'); 
    Insert into TEST_USER 
       (FULL_NAME, LAST_NAME) 
    Values 
       ('Four Anna', 'Anna'); 
    Insert into TEST_USER 
       (FULL_NAME, LAST_NAME) 
    Values 
       ('Gary Barrow', 'Barrow'); 
    COMMIT; 
    
    --query using CONTAINS which gives WRONG output - because out intention is to return only those strings that START WITH the letter P but it returns another string that has P not at the starting!! 
    
    SQL> select full_name from test_user where contains(full_name,'P%')>0; 
    
    FULL_NAME 
    ---------------------------------------------------------------- 
    PAUL HERNANDEZ 
    CHRISTOPHER Phil 
    
    -- I need output as follows in which the second value is not returned...meaning 'CHRISTOPHER Phil' should NOT be returned by the CONTAINS clause just as the LIKE operator below doesn't return it. 
    SQL> select full_name from test_user where full_name like 'P%'; 
    
    FULL_NAME 
    ---------------------------------------------------------------- 
    PAUL HERNANDEZ 
    Please can anyone suggest what to do about it?

    Thank you
    OrauserN

    No, you can skip all those, if you use SUBSTRING_INDEX.

  • CS5.5 cannot find the XML connector component - which gives

    I'm working on an actionscript file in flash CS5.5 2 and can't find the XML connector component any place. What happened to him?  How are you suppose to get a ride there. Y at - it somewhere I can download the .swc file and install it? convert it to action script 3 is not an option in this case.

    Thank you

    Joel

    with as2, use the xml class.

  • view inline values, which gives bad result...

    I saw a123 table with data below...


    GRANTAMOUNTDRCR
    112341000D
    212345000C
    3123452000C
    4123457000D



    Now I want below o/p of the table of the a123


    GRANTBALANCE
    1234-4000
    12345-5000

    To do this, I wrote below the query but its appropriate result not give...

    Select grant, credit-debit balance of)

    Select grant, sum (debit) Debit, sum (credit) credit of)

    Select grant,

    Drcr case when 'C' THEN amount *-1 Else NULL END in the form of credit.

    Drcr case when had ' then amount end otherwise null flow

    from a123)

    Grant group);

    top query results are below...

    GRANTBALANCE
    112346000
    2123459000

    Please help me on this thanks...

    Pretty obvious what is wrong:

    you convert credit figures in negative numbers with the case statement

    If you have

    1 1234 1000 D
    2 1234 -5000 C
    3 12345 -2000 C
    4 12345 7000 D

    and after that you are subtracting these figures of your throughput numbers.

    Therefore, do not convert negative credits before subtracting the or if you want to make negativ, then you must add them.

    1000 + 5000 =-4000

    1000-5000 = 6000

    HTH

  • LEFTOUTER join querry which gives bad result

    Hello

    I have tables like below.when I perform a left outer join issue IDs and startdate he gives invalid results.when I write in request

    It does not correct result because there is no data for 16 jan. It should give no results. But it shows all records. How do I solve this problem

    SQL:

    Select a.id, a.date, b.val, a.tot, b.net, b.cre

    FROM table1 a

    join table2 b left

    "on a.id = b.id and a.date = b. and a.date ='02-Feb-2014."

    In the tables below contains no data for the month of February but still im getting the incorrect data. He must not returnany files right?

    Table1:

    IDDateValtot
    1January 1, 1319
    22 January 1338
    33 January 1347
    4January 4, 1356
    55 January 1365

    Table2:

    IDDateNETCRE
    1January 1, 1319
    213 January 1338
    33 January 1347
    4January 4, 1356
    55 January 1365

    "It should not returnany files right?

    Wrong, there is no where clause so it should return all the records in a padded with NULL values for b.

  • Query to find the sales order

    Hi all
    I need a query to find sales order number against which a serial number is processed.

    Can ny helps an onthis.

    Thank you

    Hello
    Try the following question

    Select wdd.source_document_number
    Of wsn wsh_serial_NUMBERS,.
    wsh_delivery_details JMD
    Where wsn.delivery_detail_id = wdd.delivery_detail_id
    And & wsn.fm_serial_number series
    and nvl (wsn.ti_serial_number, wsn.fm_serial_number)

    Thank you
    Claire

  • Simple query to find the difference between 2 numbers in one column to another column

    Hello

    I would like to know the difference between 2 numbers in same column corresponding to a condition of another column. How do that?

    For example: say I have a table with 3 columns A, B and C.

    A > Varchar2

    B > Varchar2

    C > number

    A B C
    AD1
    BC2
    CB3
    DA4

    I want something like 'column value corresponding C min min (col B) result = (col A) - value of the corresponding C column (number)' without having to write 2 select statements. How do I do that?

    Thanks in advance

    aBBy007



    Notes on the system:

    2-node 11.2.0.3.4 GI/RDBMS running on RHEL5.

    Hello

    It is not very similar to your original question.  It would be better if you asked what you really want in your first post, rather than making people to time writing solutions you want not and can not use waste.  Once you see an answer to this question, will you change the question again?

    Here's a way to do what you asked:

    WITH got_lasts AS

    (

    SELECT val.thread #.

    , MAX (val.sequence #) AS last_standby_seq_received

    MAX (CASE

    WHEN val.applied = "YES".

    THEN val.sequence #.

    END

    ) AS last_standby_seq_applied

    V $ archived_log val

    Join v$ database vdb WE val.resetlogs_change #.

    = vdb.resetlogs_change #.

    GROUP BY thread #.

    )

    SELECT thread #.

    last_standby_seq_received

    last_standby_seq_applied

    last_standby_seq_received

    -last_standby_seq_applied AS total_lag

    OF got_lasts

    ORDER BY thread #.

    ;

  • Query to find and update

    Hello

    Can someone please provide me with a request to find the names with ',' comma as served, which in fact, I have a service name column in a table where I need to find the names by commas ',' and delete per update.

    I enjoyed, if someone provide me with query to find these services with commas between the two and one update statement separated to remove


    Thanks in advance for your cooperation

    Kind regards
    Ahon

    Hello

    use the REPLACE & INSTR sql command

    example:

    Query:
    Select service name
    from YOURTABLE
    where instr (service_name, ',') > 0 - it return those with tank «,»

    Update:

    Update YOURTABLE
    Set service_name = replace(service_name,',','') - to replace the tank ',' null values
    where instr (service_name, ',') > 0

    But before to do that back up your table or do it in a copy of this...

    Syntax
    -------------------------------------------------------------------------------

    REPLACE (string_expression, string_pattern, string_replacement)

    Arguments
    -------------------------------------------------------------------------------

    String_Expression
    Is the string expression to search for. string_expression can be of character or binary type.
    string_pattern
    Is the substring to find. string_pattern can be of character or binary type. string_pattern cannot be an empty string ("") and must not exceed the maximum number of bytes that fits on a page.
    string_replacement
    Is the replacement string. string_replacement can be of character or binary type.

    Charles.

    If it find useful or appropriate then mark it accordingly

  • Query to find records with more than 2 decimal places.

    I have written the below query to find records with more than 2 decimal places, but it is returning records with decimal places 1 & 2. 
    The datatype of the AMT column is NUMBER (without any precision).
    
    SELECT amt  FROM amount_table
     WHERE substr(amt, instr(amt, '.')) LIKE '.%'
           AND length(substr(amt, instr(amt, '.') + 1)) > 2
    Output:-

    AMT

    * 41591.1*
    * 275684.82*
    * 64491.59*
    * 3320.01*
    * 6273.68*
    * 27814.18*
    * 30326.79*
    131.8413635
    162.5352898
    208.5203816
    8863.314632
    22551.27856
    74.716992
    890.0158441
    2622.299682
    831.6683841
    * 1743.14*
    2328.195877
    3132.453438
    5159.827334
    3.236234727
    37.784
    Thanks

    Hello

    user1585440 wrote:

    when i inserted fee_amt as 41591.0999999999  it is displayed as 41591.1 in the output i.e,
    
    insert into amount_table (line_number,fee_amt) values (100,41591.0999999999);
    
    select fee_amt from amount_table  where line_number = 100. this query shows the output as below
    
    fee_amt
    
    41591.1
    
    The fee_amt column has number as datatype (without precision)
    
    Why it is automatically shown rounded off as 41591.1? 
    

    Published by: user1585440 on December 28, 2010 04:50

    You use SQL * more your front end?

    SQL * Plus has a fixed width to display all columns. The default for numbers is 10 characters. If necessary, SQL * Plus will be round a number or the use of scientific notation, to represent the number of the expected number of characters.
    You can use the SQL * more "SET NUMLARGEUR" to change the default view for all the numbers of orders, or "COLUMN" to set a sepcific format in an individual column.
    If you explicitly convert your channel numbers in a query, SQL * Plus adjusts the column width to whatever is needed. For example

    SELECT  TO_CHAR (fee_amt, 'TM')     AS fee_amt_d
    

    "TM" is the default format; You can call TO_CHAR with a single argument, if you prefer.

  • Adding column which gives the serial number for each line in the Bulletin Board

    I use the update version 2 Jdev 11 g.
    I'm the filling of all employees from the emp table ADF table.
    My requirement is to add a column more as the first column and header line which displays the serial number for each serial number of row.the is not available in the table emp in database .i want to generate it dynamically when the data are filled in to ADF table.i don't want not to use the method to get the SQL query rownum. I want to get custom code (in the Managed Bean) or set all of the properties in the subject entity or any other object.

    Published by: sj0609 on September 8, 2009 09:43

    Hello

    Give an id to the table (say 'currRow') varStatus property. Add a column to the table (for example with a text output), then set it to the value of the output text #{currRow.index}.

    Arun-

  • Finder column resizing handle missing

    The Finder column resizing handle is missing when I open the Finder. I trashed the file com.apple.finder.plist. Restarted. Made no difference.

    In preferences, I have 5 files com.apple.finder.plist. One is .lockfile.  We're just. Finder.plist. the other 3 have strings of characters after them, for example, com.apple.finder.plist.ahWZKxi

    There should be 5 finder plist files?

    Suggestions for the restoration of the column resizing handle?

    Thank you very much.

    It is not all handles. Just put the cursor between columns, and then drag.

    If you have scroll bars always value, they will always show.

  • I can't find the tab of Firefox which takes me to edit and print et al, except that I have a little bitty screen.

    I just got a new computer and have changed for windows 8, and the guy put in place with internet explore when I was accustomed to using firefox. My son put on firefox, but I can't find the tab firefox with access to edit, print, print preview, etc., except when I got the box of firefox on three-quarters of the screen, which is too small. How to fill the screen and still give me the small box so I can print? Please do not reply to an avalanche of gibberish, because the understanding of my computer is negligible.

    Hi Senyax, how are enlarge you Firefox when you want more? They will give you different results:

    (1) maximize the window (the middle between _ and X button)

    You should still be able to see the top bar of the window with the orange Firefox button. If you don't see this, one of your Firefox settings files could be damaged.

    (2) full screen (F11 key or the Firefox button orange > fullscreen)

    By default, nothing else that the site displays full-screen mode. Although you can have the tab bar and toolbar display (drag your mouse to the top of the screen and right click on an empty area of the tab bar, then uncheck "Hide toolbar"), you cannot use the orange Firefox menu button in this mode.

  • Hotmail has emoticons, but I can't find them in Outlook, to which I was transferred automatically. Are they in Outlook, and how to get them?

    Hotmail has emoticons, but I can't find them in Outlook, to which I was transferred automatically.  Are they in Outlook, and how to get them?

    Hello njz,

    When you create a new email you should see a toolbar at the top of the text by e-mail window. This toolbar will include "BOLD", italic, underlining, and other formatting tools. At the end of the toolbar, you'll see a smiling face. Click to display the available emoticons.

    This forum post is my own opinion and does not necessarily reflect the opinion or the opinion of Microsoft, its employees or other MVPS.

    John Barnett MVP: Windows XP Expert associated with: Windows Expert - consumer: www.winuser.co.uk |  vistasupport.mvps.org | xphelpandsupport.mvps.org | www.silversurfer-Guide.com

  • Where can I find THE "SEND TO" folder (which has things like < Office create a shortcut >), so I can add add my own send to options that is send to my documents - my pictures.

    Where can I find THE "SEND TO" folder (which has things like < desktop="" create="" shortcut=""> ), so I can add add my own send to options that is send to my documents - my pictures.

    This isn't how it's done.  There is such a file, but customizing the send option in the context menu is a little more complicated that just add entries to this file.  Here is the procedure:http://www.vistax64.com/tutorials/67599-send-context-menu.html.  In fact, if you are interested in adding move to a folder or a copy of a folder specifically, the following article may be also useful: http://www.vistax64.com/tutorials/89196-context-menu-add-copy-folder-move-folder.html (even if it would be any folder and you need browse and select which one you want may not be exactly what you're looking for (although know it may be something you also want to add) but the first article will include the ability to add a folder of) specciic to send it to the menu as well as other programs and just about anything you want).

    Also another clue.  The contextual menu has more options you see when you right click on an element to access.  Try to hold the SHIFT key when right-clicking on an item and you will see an expanded list of options that can include something that willl help you.  It does not the question asked you (the first link above did that), but it is linked and I thought that I have it add in case you weren't aware, and where it is very convenient at a given time.

    I hope this helps (I'm sure it will).  A suggestion - be careful how you add to the context menu.  Not that it has a limit or something like that, but add the more you more it will be difficult to find whatever it is you are really looking for.  It is easy to get carried away and end up with a menu that is so crowded it defeats the purpose to save time with shortcuts.  Try only to add the options that you use often enough that the feature will really help you.

    Good luck!

    Lorien - MCSA/MCSE/network + / has + - if this post solves your problem, please click the 'Mark as answer' or 'Useful' button at the top of this message. Marking a post as answer, or relatively useful, you help others find the answer more quickly.

  • SQL query to find the total number of source based nonsource passangersbetween source and destination station and passenger station on the same chekindate

    Hello

    SQL query to find the total number of source based nonsource passangersbetween source and destination station and passenger station on the same chekindate.

    Please help on this script and let me know if you need more details.

    ---

    You use a SELECT statement.  Let me know if you need more details.

Maybe you are looking for

  • Can HP Designjet 100 - you HELP me please?

    I am a novice / amateur.I just bought an old Designjet 100.I was told it worked 'perfectly '... NOT TRUE.(It may have been 'sitting' since it worked perfectly).& nbsp;But before I trash, I hope that someone knows enough to advise me based on some fac

  • Calculation of the frequency of real output of a PXI-5402

    I have a card PXI-5402, sitting in a high chassis. I'm only interested in the sine wave output at frequencies up to about 10 kHz. I know that it is possible to request an output frequency and then interrogate the acutal output frequency but I prefer

  • access to the user account without password via Remote Desktop Conncetion

    Hello, I have a question for remote desktop connection. I have two computer, let's call them computer (XP pro) and computer B.  And A computer user account has no password created. If I activate the remote desktop on A computer (computer a user accou

  • Help on Windows 98 USB driver

    I need to save files off old my teacher computer, but the computer won't recognize any of my disks to jump when I put them in there. He continues to say that he cannot locate a driver for it. I can't use a CD to save the info because the CD drive doe

  • More problems with Code signing

    Well, I tried for a week to get my application to sign with no luck. I finally got a new certificate of RIM at the expense from the command line this time, rather than half a Flash Builder, something half line of command, I had tried before. Whenever