Distinct rows from two tables linked by a third one

Hi,
I need to write an SQL sentence to bring a group of DISTINCT rows, each row in a form of: A.X, A.Y, C.IDBOLETA. Tables A and C are linked through the table C, as follow:
Table A: INDUSTRIAGEO
NIT VARCHAR2(20) NOT NULL,
CORRELAIGEO NUMERIC(2) NOT NULL,
NOMBREAGENCIA VARCHAR2(255) NOT NULL,
DIRECCION VARCHAR2(255),
X NUMERIC(12,8) NOT NULL,
Y NUMERIC(12,8) NOT NULL,
CONSTRAINT PKGEOINDUST PRIMARY KEY(NIT, CORRELAIGEO),
CONSTRAINT FKGEOINDUST FOREIGN KEY(NIT) REFERENCES INDUSTRIA(NIT)
Table B: ANALISIS
IDANALISIS NUMERIC(12) NOT NULL,
NIT VARCHAR2(20) NOT NULL,
CORRELAIGEO NUMERIC(2) NOT NULL,
FECHA DATE NOT NULL,
IDINSPECTOR NUMERIC(4) NOT NULL,
CONSTRAINT PKANALISIS PRIMARY KEY(IDANALISIS),
CONSTRAINT FKANALGEOI FOREIGN KEY(NIT, CORRELAIGEO) REFERENCES INDUSTRIAGEO(NIT, CORRELAIGEO),
CONSTRAINT FKANALINSP FOREIGN KEY(IDINSPECTOR) REFERENCES INSPECTOR(IDINSPECTOR)
Table C: ANALISISBOLETA
IDANALISIS NUMERIC(12) NOT NULL,
CORRELAANALISIS NUMERIC(2) NOT NULL,
IDBOLETA NUMERIC(12) NOT NULL,
IDCATEGORIAINDUSTRIA NUMERIC(3) NOT NULL,
CONSTRAINT PKANALBOLE PRIMARY KEY (IDANALISIS, CORRELAANALISIS),
CONSTRAINT UKANALBOLE UNIQUE (IDBOLETA),
CONSTRAINT FKANALBOLE FOREIGN KEY(IDANALISIS) REFERENCES COPS.ANALISIS(IDANALISIS),
CONSTRAINT FKANALCATI FOREIGN KEY(IDCATEGORIAINDUSTRIA) REFERENCES COPS.CATEGORIAINDUSTRIA(IDCATEGORIAINDUSTRIA)
Thanks for your help!!!
Mario

Perhaps
select distinct a.x,a.y,c.idboleta
  from industriaego a,
       cops.analisis b,
       analisisboleta c
where a.nit = b.nit
   and a.correlaigeo = b.correlaigeo
   and b.idanalisis = c.idanalisisRegards
Etbin
Edited by: Etbin on 4.5.2010 21:42
the copy/paste elf did it again: b.correlaigeo instead of b.a.correlaigeo (as in the OP's comment below)

Similar Messages

  • Need of SQL query in selecting distinct values from two tables

    hi,
    I need a query for selecting distinct values from two tables with one condition.
    for eg:
    there are two tables a & b.
    in table a there are values like age,sex,name,empno and in table b valuses are such as age,salary,DOJ,empno.
    here what i need is with the help of empno as unique field,i need to select distinct values from two tables (ie) except age.
    can anybody please help me.
    Thanks in advance,
    Ratheesh

    Not sure what you mean either, but perhaps this will start a dialog:
    SELECT DISTINCT a.empno,
                    a.name,
                    a.sex,
                    b.salary,
                    b.doj
    FROM    a,
            b
    WHERE   a.empno = b.empno;Greg

  • How to compare two rows from two table with different data

    how to compare two rows from two table with different data
    e.g.
    Table 1
    ID   DESC
    1     aaa
    2     bbb
    3     ccc
    Table 2
    ID   DESC
    1     aaa
    2     xxx
    3     ccc
    Result
    2

    Create
    table tab1(ID
    int ,DE char(10))
    Create
    table tab2(ID
    int ,DE char(10))
    Insert
    into tab1 Values
    (1,'aaa')
    Insert
    into tab1  Values
    (2,'bbb')
    Insert
    into tab1 Values(3,'ccc')
    Insert
    into tab1 Values(4,'dfe')
    Insert
    into tab2 Values
    (1,'aaa')
    Insert
    into tab2  Values
    (2,'xx')
    Insert
    into tab2 Values(3,'ccc')
    Insert
    into tab2 Values(6,'wdr')
    SELECT 
    tab1.ID,tab2.ID
    As T2 from tab1
    FULL
    join tab2 on tab1.ID
    = tab2.ID  
    WHERE
    BINARY_CHECKSUM(tab1.ID,tab1.DE)
    <> BINARY_CHECKSUM(tab2.ID,tab2.DE)
    OR tab1.ID
    IS NULL
    OR 
    tab2.ID IS
    NULL
    ID column considered as a primary Key
    Apart from different record,Above query populate missing record in both tables.
    Result Set
    ID ID 
    2  2
    4 NULL
    NULL 6
    ganeshk

  • Display distinct rows from Oracle table without using "DISTINCT" keyword.

    How to retrieve distinct rows from oracle table without using 'DISTINCT' keyword in SQL?
    Thanks in advance.
    Mihir

    Welcome to the forum.
    Besides GROUP BY you can use UNIQUE instead of DISTINCT as well, but that's probably not wanted here ;) , and the ROW_NUMBER() analytic:
    SQL> create table t as
      2  select 1 col1 from dual union all
      3  select 1 from dual union all
      4  select 2 from dual union all
      5  select 3 from dual union all
      6  select 4 from dual union all
      7  select 4 from dual;
    Table created
    SQL> select col1 from t;
          COL1
             1
             1
             2
             3
             4
             4
    6 rows selected
    SQL> select distinct col1 from t;
          COL1
             1
             2
             3
             4
    SQL> select unique col1 from t;
          COL1
             1
             2
             3
             4
    SQL> select col1 from t group by col1;
          COL1
             1
             2
             3
             4
    SQL> select col1
      2  from ( select col1
      3         ,      row_number() over (partition by col1 order by col1) rn
      4         from   t
      5       )
      6  where rn=1;
          COL1
             1
             2
             3
             4

  • How NOT to restrict no of rows from two tables

    I have two identical tables Invoice and Payment. The only difference is Invoice_id,Invoice_Amt and Payment_id,Payment_Amt columns that shows different ids and amounts. The bank_ids, names, account_types are same. Invoice table has 3 rows and Payment has 2. Simply meaning that there were 3 invoices generated but the bank received 2 payments. I want to show Invoice_Amt and Payment_Amt using sql query. But its giving me total 6 rows. Whereas, I want 3 from Invoice and 2 rows from Payment table to show side-by-side.
    CREATE TABLE invoice
    ( invoice_id NUMBER
    bank_id NUMBER,
    bank_name VARCHAR2(256),
    invoice_amount NUMBER);
    ----Invoice table has 3 rows showing 3 Invoice Amts
    CREATE TABLE payment
    ( payment_id NUMBER
    bank_id NUMBER,
    bank_name VARCHAR2(256),
    payment_amount NUMBER);
    ----Payment table has 2 rows showing 2 Payments
    After executing this sql statement below, I get 6 rows:
    select inv.invoice_amount,pymt.payment_amount from invoice inv,payment pymt where inv.bank_id=pymt.bank_id;
    How can I show 3 rows for Invoice and 2 for Payment..?
    Thank you.

    Hi,
    So you want
    the 1st invoice to appear side-by-side with the 1st payment,
    the 2nd invoice to appear side-by-side with the 2nd payment,
    the nth invoice to appear side-by-side with the nth payment.
    But, if there are an uneqaul numner of payments and invoices, all the payments and all the invoices must still be shown, alone on a row if necessary.
    That sounds like a job for FULL OUTER JOIN.
    Use the analytic ROW_NUMBER fucntion to determine which is the 1st, 2nd, ..., nth row in each table, for each bank.
    WITH     invoice_plus_r_num     AS
         SELECT     bank_id, bank_name
         ,      invoice_amount
         ,     ROW_NUMBER () OVER ( PARTITION BY  bank_id, bank_name
                                   ORDER BY          invoice_id
                           )         AS r_num
         FROM    invoice
    ,     payment_plus_r_num     AS
         SELECT     bank_id, bank_name
         ,      payment_amount
         ,     ROW_NUMBER () OVER ( PARTITION BY  bank_id, bank_name
                                   ORDER BY          payment_id
                           )         AS r_num
         FROM    payment
    SELECT       NVL (i.bank_id,   p.bank_id)          AS bank_id
    ,       NVL (i.bank_name, p.bank_name)     AS bank_name
    ,       i.invoice_amount
    ,       p.payment_amount
    FROM          invoice_plus_r_num     i
    FULL OUTER JOIN     payment_plus_r_num     p  ON   i.bank_id     = p.bank_id
                                        AND     i.bank_name     = p.bank_name
                                AND     i.r_num          = p.r_num
    ORDER BY  bank_id     -- you can use column aliases here
    ,       bank_name
    ,       NVL (i.r_num, p.r_num)
    ;You mentioned something about accounts, but didn't include that in the CREATE TABLE statements. You'll probably want to add that wherever I used bank_id and bank_name, above.
    Are invoce and payment actually views, rather than tables? If not, you should have a separate bank table, and only include the bank_id in the other tables.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using.
    Edited by: Frank Kulash on Feb 3, 2011 12:32 PM

  • Selecting from two tables but making it just one selection

    Is there a way to select from two tables and just have one selection appear?
    Specifically I have a fact_install_unit, and a fact_install_arch table.
    Sometimes the value exists in fact_install_unit.factory_timestamp, and sometimes when fact_install_unit.factory_timestamp is null I need to pull it from the fact_install_arch.factory_timestamp.
    sort of like:
    (select fact_install_unit.factory_timestamp
    from fact_install_unit, fact_install_arch
    where fact_install_unit.fl_unit_sak = fact_install_arch.fl_unit_sak
    and where fact_install_unit.factory_timestamp is null then display fact_install_arch.factory_timestamp)

    > I was just stating that I do not have sufficient priveleges to create views in this database.
    >
    nm means "no more" than that
    And how are we supposed to know that? You seem to have changed the thread subject to "unfortunately I only have read-only and insufficient priveleges", which is not even a question.
    nm means "New Mexico":
    http://www.myshortpencil.com/schooltalk/messages/85/515.html?971794944

  • Select unique rows from two tables...

    Hi,
    I have two tables, replies1 and replies2.
    SQL> desc replies
    Name Null? Type
    URN VARCHAR2(36)
    ADDRESS VARCHAR2(18)
    FILESIZE NUMBER
    AS_NUM VARCHAR2(6)
    SQL> desc replies2
    Name Null? Type
    URN VARCHAR2(36)
    ADDRESS VARCHAR2(18)
    AS_NUM VARCHAR2(6)
    Both of the tables have no primary keys, but I have indixes on (urn, addrss) combination on both....
    I am trying to select the unique rows with (urn, address) from replies2, and then find the matching size from replies...
    I am using the following query:
    select distinct replies2.urn, replies2.address, replies.filesize from replies2, replies where replies2.AS_NUM like 'XYZ' and replies.urn = replies2.urn;
    I cannot figure out why it won't work. the way I understand it is that, distinct will give all distinct combination of all column names that follow, which is what I want...
    I know it is wrong, because the query:
    select count(*) from replies2 where AS_NUM like 'XYZ' returns less number of rows than the above query.
    Any help would be greatly appreciated.
    Thank you
    Oz.

    Thanks a lot Mohan for your reply.
    urn is not a unique key. Several rows could have the same (urn, address) pair in both tables. What I want is retrieve all (urn, address) rows from one table, and find the size from the other table to make a (urn, address, size). I want all unique combinations of (urn, address) to appear in the output.
    AS_NUM is an empty column in replies... It would've been a lot easier if it wasn't, since then I'll just say: select distinct urn, address, filesize from replies where AS_NUM like 'XYZ';
    I will try your query though and let u know how it goes. It takes quite a while to run since my tables are huge.

  • How to return mismatched rows from two tables?

    I have created two tables in the same database as below which gives the row
    count of tables across all databases before and after an DB restore
    operation.
    create table before_restore(db_name varchar(100),table_name
    varchar(1000),row_count int) insert into before_restore exec sp_msforeachdb 'USE
    [?]; select ''?'' as database_name,o.name,max(i.rowcnt ) From [?].sys.objects o
    inner join [?].sys.sysindexes i on o.object_id=i.id where o.type=''U'' group by
    o.name'
    create table after_restore(db_name varchar(100),table_name
    varchar(1000),row_count int) insert into after_restore exec sp_msforeachdb 'USE
    [?]; select ''?'' as database_name,o.name,max(i.rowcnt ) From [?].sys.objects o
    inner join [?].sys.sysindexes i on o.object_id=i.id where o.type=''U'' group by
    o.name'
    I want to compare these two tables and it should only return me rows that
    have changed after the restore operation is complete.
    Eg:
    Table xyz has rowcount of 100 before restore and the restore was not proper
    and after restore count is 50. So it should return me the result set as
    below;
    Db_name    Table_Name  row_count_before_restore    row_count_after_restore
    abc                   xyz                       100                              
       50
    Thanks!!!

    Something like below perhaps? Btw, I recommend using catalog view and dynamic management views instead of the old system tables (now called compatibility views)...
    SELECT
    COALESCE(a.db_name, b.db_name) AS db_name
    ,COALESCE(a.table_name, b.table_name) AS table_name
    ,a.row_count AS row_count_before_restore
    ,b.row_count AS row_count_after_restore
    FROM before_restore AS b FULL OUTER JOIN after_restore AS a ON b.db_name = a.db_name AND b.table_name = a.table_name
    WHERE b.row_count <> a.row_count OR b.db_name IS NULL OR a.db_name IS NULL
    Tibor Karaszi, SQL Server MVP |
    web | blog

  • Select Distinct rows from 3 tables

    I need to retrive information from 3 different tables by applying a specific condition.
    I have the following query which works fine for retrieving desired data from 2 tables.
    SELECT
    a.userId
    FROM userGeneral
    a inner
    join userSpecific
    b on a.userId
    = b.userId
    WHERE
    a.userActive
    = 1
    userId
    111
    222
    333
    444
    Now I have a third table called userMgr which may contain multiple records for each userId with a corresponding mgrId value. It has a primary key identity column called userRecId and I would like to fetch the
    mgrId value corresponding to the MAX(userRecId) for the matching userId.
    userRecId  |  userId  | mgrId
    1 |    111    | 123
    2 | 111 | 234
    3 | 111 | 345
    4 | 333 | 345
    5 | 333 |  456
    The resultset should be as follows after joining all the 3 tables.
    userId | mgrId
    111 | 345
    222 | NULL
    333 | 456
    444 | NULL
    Can anyone please help with this query.

    I need to retrive information from 3 different tables by applying a specific condition.
    I have the following query which works fine for retrieving desired data from 2 tables.
    SELECT
    a.userId
    FROM userGeneral
    a inner
    join userSpecific
    b on a.userId
    = b.userId
    WHERE
    a.userActive
    = 1
    userId
    111
    222
    333
    444
    Now I have a third table called userMgr which may contain multiple records for each userId with a corresponding mgrId value. It has a primary key identity column called userRecId and I would like to fetch the
    mgrId value corresponding to the MAX(userRecId) for the matching userId.
    userRecId  |  userId  | mgrId
    1 |    111    | 123
    2 | 111 | 234
    3 | 111 | 345
    4 | 333 | 345
    5 | 333 |  456
    The resultset should be as follows after joining all the 3 tables.
    userId | mgrId
    111 | 345
    222 | NULL
    333 | 456
    444 | NULL
    Can anyone please help with this query.
    try this:
    select userId,userRecId,
    from userMgr,
    (SELECT a.userId, max(a.userRecId)
    FROM userGeneral a inner join userSpecific b on a.userId = b.userId
    group by a.userId
    WHERE a.userActive = 1) table1(userId,userRecId)
    where userMgr.userRecId = table1.userRecId

  • Select Distinct rows from multiple tables

    Table 1 is a List of Vendors - VID, PID, VName, VAddress, VPhone
    Table 2 is a list of Products - PID, PName, PPrice, PWeight, PColor
    I need to produce a list of unique PID's showing the following fields - PID, VName, PName, PColor
    So, Here is my failed attempt:
    SELECT P.PID, V.VName, P.PName, P.PColor
    FROM Products P INNER JOIN Vendors V ON P.PID = V.PID
    GROUP BY P.PID

    If you post DDL, sample data and your desired output based on that sample data, someone can probably create a query that does what you want. 
    And I have to tell you that Table 1 is not a list of vendors unless you have a system where a vendor provides one and only one product - something that is unusual. If your system is one where a vendor should provide any number of products (and if a product
    can be provided by any number of vendors), you have some fundamental schema issues to correct.
    Lastly, there are sticky posts at the top of the forum that provide suggestions for posting questions.  Please have a look - help your readers help you by providing sufficient information.  Phrases such as "failed" or "does not work"
    do not provide any useful detail.  And one good rule of thumb - any time you feel you need to use (or say) distinct in a query is an indication that something somewhere is wrong.  It could be a schema issue, a misunderstanding of the schema or the
    goal, an incorrect query, etc.  There are few instances where distinct is needed in a well-defined and implemented system, IMO.

  • How to select x numbered row from two tables

    Hi,
    I have one performance problem...
    Here is sample scenario...
    TableA
    A1 A2 A3
    a1     a12     a13
    a2     a22     a23
    a3     a32     a33
    TableB
    B1     B2     B3
    b1     b12     b13
    b2     b22     b23
    I want result like
    A1     B1     A2     B2
    a1     b1     a12     b12
    a2     b2     a22     b22
    I have written it like
    select
    A1,
    B1,
    A2,
    B2
    from
    (select A1, A2, rownum rnA from TableA) a,
    (select B1, B2, rownum rnB from TableB) b
    where rnA = rnB
    but suppose TableA has 2500000 rows and
    TableB has 500 rows then for 500 rows I have to
    wait for all 2500000 rows scanning.
    Is there any smart solution..?
    I have created indexes for on columns A1, (A1,A2,A3), B1, (B1,B2,B3).
    Curious:)
    Rushang Kansara
    Message was edited by:
    Rushang Kansara

    Here is explain plan
    SELECT STATEMENT, GOAL = FIRST_ROWS               Cost=5     Cardinality=67     Bytes=3618
    HASH JOIN               Cost=5     Cardinality=67     Bytes=3618
    VIEW     Object owner=SFMFG          Cost=2     Cardinality=82     Bytes=2214
    COUNT                         
    TABLE ACCESS FULL     Object owner=SFMFG     Object name=TABLEA     Cost=2     Cardinality=82     Bytes=1148
    VIEW     Object owner=SFMFG          Cost=2     Cardinality=82     Bytes=2214
    COUNT                         
    TABLE ACCESS FULL     Object owner=SFMFG     Object name=TABLEB     Cost=2     Cardinality=82     Bytes=1148
    New to sql tunning Here why cardinality goes to 67 and cost to 5???
    Thank you for your time.. :)

  • Retrieve data from two tables and store it in one itab

    Hi All,
    i have an internal table of structure which has fields ar_object and objecttext.
    I want to retrieve all the ar_object from table toaom for object type BUS2012 and then the corresponding objecttext from toasp where toaom-ar_object = toasp-ar_object and then store both this values in my internal table.
    what is the best method to do it ?  Please let me know if you want to know how i am doing it right now
    thanks,
    Golu

    Hi,
    You can get many ways 
    1. using  For all entries in 
    2. using Inner join
    3. you can get 2 tables data into 2 different internal tables  and   loop first internal table and read second internal using key fields append it another internal table or modify second internaltable.
    In above ways 1st and 2nd are performance issues.   the best way is
    get TOAOM table data into itab1 and get TOASP table data into itab2 you can append data into another itab3 or modify itab2
    regards,
    Ganesh

  • How to insert data into two tables linke with foreign key..

    I have two tables
    1)EMP(emp_ID,username,emp_type_code)
    emp_ID is primary key, emp_type_code is a foreign key references emptype table.
    2)emptype(emp_type_code,emp_type_descripton)
    emp_type_code is primary key
    Could anyone help me ..how to insert data into EMP table. How to insert data into two tables linke with foreign key..

    CREATE TABLE "CATDB"."DWDIMUSER"
    "USER_ID" NUMBER(10,0) NOT NULL ENABLE,
    "SPECIALTY_ID" NUMBER(10,0),
    "FULLNAME" VARCHAR2(20 BYTE),
    "FNAME" VARCHAR2(20 BYTE),
    "LNAME" VARCHAR2(20 BYTE),
    "USER_SUBTYPE" VARCHAR2(20 BYTE),
    CONSTRAINT "DIMUSER_PK" PRIMARY KEY ("USER_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "CATDB" ENABLE,
    CONSTRAINT "DIMUSER_DIMSPECIALTY_FK" FOREIGN KEY ("SPECIALTY_ID") REFERENCES "CATDB"."DWDIMSPECIALTY" ("SPECIALTY_ID") DISABLE
    CREATE TABLE "CATDB"."DIMSPECIALTY"
    "SPECIALTY_ID" NUMBER(10,0) NOT NULL ENABLE,
    "SPECIALTY_NAME" VARCHAR2(100 BYTE),
    CONSTRAINT "DIMSPECIALTY_PK" PRIMARY KEY ("SPECIALTY_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "CATDB" ENABLE
    INSERT INTO DIMUSER (FullName, FNAME, LNAME, USER_TYPE, USER_SUBTYPE)
    SELECT DISTINCT
    Engineer AS FullName,
    regexp_substr(Engineer , '[^,| ]+', 1, 1) as FName,
    regexp_substr(Engineer , '[^,| ]+', 1, 2) as LName ,
    'Engineer'
    FROM EMPLOYEELOOKUP;
    INSERT INTO DIMSPECIALTY (SPECIALTY_NAME)
    SELECT DISTINCT SPECIALITY
    FROM EMPLOYEELOOKUP;
    COMMIT;
    CREATE TABLE employeelookup ...IS A TABLE THAT HAS ALL THE DATA NEDED TO BE FILLED IN BOTHE TABLES...
    CREATE TABLE "CATDB"."EMPLOYEELOOKUP"
    "EMPLOYEELOOKUP_ID" NUMBER(10,0) NOT NULL ENABLE,
    "ENGINEER" VARCHAR2(25 BYTE),
    "SPECIALTY" VARCHAR2(20 BYTE),
    CONSTRAINT "DIMSPECIALTY_PK" PRIMARY KEY ("EMPLOYEELOOKUP_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "CATDB" ENABLE
    DATA IN EMPLOYEELOOKUP
    Engineer, Specialty,
    John, Dow, Electronis,
    Dow, Jons, Technician
    Stan Smithers Sales
    Mark, Richards Marketing
    Jenny, Lane Marketing
    John, Lee Sales
    I NEED TO LOAD THE FOREIGN KEY IN DIMUSER FROM THE DIMSPECIALTY TABLE?
    BY USING THE LOOKUP TABLE TO MARCH THE NAMES UNDER THE Engineer COLUMN, SPECIALTY COLUMNE DISTICTIVLY BY JOINING THE DIMSPECILTY TO RISTIVE THE PRIMARY KEY AND FILL IT IN THE DIMUSER TABLE AS A FOREIGNE KEY.

  • CE function to get distinct values from Column table

    Hi All,
    Could you please let me know the appropriate CE function to get the distinct values from column table.
    IT_WORK = SELECT DISTINCT AUFNR FROM :IT_WO_DETAILS;
    Thank you.

    Hi,
    If you have 10g, you can use Model( with model performance is better than connect by )
    Solution
    ========================================================================
    WITH t AS
    (SELECT '0989.726332, 1234.567432, 3453.736379, 3453.736379, 0989.726332, 3453.736379, 1234.567432, 1234.567432, 0989.726332'
    txt
    FROM DUAL)
    SELECT DISTINCT TRIM(CHAINE)
    FROM T
    MODEL
    RETURN UPDATED ROWS
    DIMENSION BY (0 POSITION)
    MEASURES (CAST( ' ' AS VARCHAR2(50)) AS CHAINE ,txt ,LENGTH(REGEXP_REPLACE(txt,'[^,]+',''))+1 NB_MOT)
    RULES
    (CHAINE[FOR POSITION FROM  1 TO NVL(NB_MOT[0],1) INCREMENT 1] =
    CASE WHEN NB_MOT[0] IS NULL THEN TXT[0] ELSE REGEXP_SUBSTR(txt[0],'[^,]+',1,CV(POSITION)) END );
    =========================================================================
    Demo
    =======================================================================
    SQL> WITH t AS
    2 (SELECT '0989.726332, 1234.567432, 3453.736379, 3453.736379, 0989.726332, 3453.736379, 123
    4.567432, 1234.567432, 0989.726332'
    3 txt
    4 FROM DUAL)
    5 SELECT DISTINCT TRIM(CHAINE)
    6 FROM T
    7 MODEL
    8 RETURN UPDATED ROWS
    9 DIMENSION BY (0 POSITION)
    10 MEASURES (CAST( ' ' AS VARCHAR2(50)) AS CHAINE ,txt ,LENGTH(REGEXP_REPLACE(txt,'[^,]+',''))+1 NB_MOT)
    11 RULES
    12 (CHAINE[FOR POSITION FROM  1 TO NVL(NB_MOT[0],1) INCREMENT 1] =
    13 CASE WHEN NB_MOT[0] IS NULL THEN TXT[0] ELSE REGEXP_SUBSTR(txt[0],'[^,]+',1,CV(POSITION)) END );
    TRIM(CHAINE)
    3453.736379
    1234.567432
    0989.726332
    SQL>
    ========================================================================

  • Deleting a row from parent table

    Dear Guru's
    I am having two table with parent - child relationship. My problem is when I am deleting a row from parent table the curresponding child row from child table also should be deleted.
    My Primary table 'Employee, EMPID Primary key
    Child table 'Privilage' inthis EMPID referencing the EMPID of Employee table
    My need is when I am deleting a row from parent table the curresponding child row from child table also should be deleted
    I issued the SQL query like,
    delete from employee where empid='12345' cascade constraints;
    Then it showing me error like,
    ERROR at line 1:
    ORA-00933: SQL command not properly ended
    Please resolve my issue , Its Top urgent
    Thanks & Cheers
    Antony

    Choosing How Foreign Keys Enforce Referential Integrity
    Oracle Database allows different types of referential integrity actions to be enforced, as specified with the definition of a FOREIGN KEY constraint:
    Prevent Delete or Update of Parent Key The default setting prevents the deletion or update of a parent key if there is a row in the child table that references the key. For example:
    CREATE TABLE Emp_tab ( 
    FOREIGN KEY (Deptno) REFERENCES Dept_tab);Delete Child Rows When Parent Key Deleted The ON DELETE CASCADE action allows parent key data that is referenced from the child table to be deleted, but not updated. When data in the parent key is deleted, all rows in the child table that depend on the deleted parent key values are also deleted. To specify this referential action, include the ON DELETE CASCADE option in the definition of the FOREIGN KEY constraint. For example:
    CREATE TABLE Emp_tab (
        FOREIGN KEY (Deptno) REFERENCES Dept_tab 
            ON DELETE CASCADE); Set Foreign Keys to Null When Parent Key Deleted The ON DELETE SET NULL action allows data that references the parent key to be deleted, but not updated. When referenced data in the parent key is deleted, all rows in the child table that depend on those parent key values have their foreign keys set to null. To specify this referential action, include the ON DELETE SET NULL option in the definition of the FOREIGN KEY constraint. For example:
    CREATE TABLE Emp_tab (
        FOREIGN KEY (Deptno) REFERENCES Dept_tab 
            ON DELETE SET NULL);
    SQL> conn scott/tiger
    Connected.
    SQL> create table ppk ( no number primary key);
    Table created.
    SQL> begin for inn in 1..10 loop insert into ppk values (inn); end loop; end;
    PL/SQL procedure successfully completed.
    SQL> create table ffk ( no number references ppk(no));
    Table created.
    SQL> begin for inn in 1..10 loop insert into ffk values (inn); end loop; end;
    PL/SQL procedure successfully completed.
    SQL> drop table ppk cascade constraints;
    Table dropped.Message was edited by:
    user52
    Message was edited by:
    user52
    Message was edited by:
    user52

Maybe you are looking for