Solved

from ansi sql to oracle sql

Posted on 2011-09-02
7
364 Views
Last Modified: 2012-05-12
we have inherted some code from another depratment,and we need to convert it to oracle from ansi we have done this alot before ,but this one is confusing because we have too many (( and )) and we do not really know how they affect the from and where clause,
please advise.

thanks


    FROM    (  (  (  ( subj

                         LEFT JOIN
                            (   care_inc
                             LEFT JOIN
                                (   v_mat
                                 LEFT JOIN
                                    MATERIAL
                                 ON v_mat.MATERIAL_ID =
                                       MATERIAL.MATERIAL_ID)
                             ON (care_inc.one_ID =
                                    v_mat.one_ID)
                                AND care_inc.care_seq =
                                       v_mat.care_seq)
                         ON (subj.care_seq =
                                care_inc.care_seq)
                            AND (subj.one_ID =
                                    care_inc.one_ID))
                     LEFT JOIN
                        one
                     ON subj.one_ID = one.one_ID)
                 LEFT JOIN
                    BASIC_MODULE_one_INFO
                 ON (subj.MODULE_ID =
                        BASIC_MODULE_one_INFO.MODULE_ID)
                    AND (subj.care_seq =
                            BASIC_MODULE_one_INFO.care_seq)
                    AND (subj.one_ID =
                            BASIC_MODULE_one_INFO.one_ID))
             LEFT JOIN
                one_FACILITY_INFO
             ON (care_inc.FACILITY_ID =
                    one_FACILITY_INFO.FACILITY_ID)
                AND (care_inc.one_ID =
                        one_FACILITY_INFO.one_ID))
         LEFT JOIN
            PERSON
         ON subj.worker_TEXT = PERSON.FULL_NAME
 
0
Comment
Question by:it-rex
  • 4
  • 3
7 Comments
 
LVL 73

Expert Comment

by:sdstuber
ID: 36473522
why convert?  Oracle supports ANSI joins since 9i

and the extra ()  aren't doing anythig, you can remove them
0
 
LVL 11

Author Comment

by:it-rex
ID: 36473532
management wants to convert all sql to oracle sql as they more readable and understandable..
not my choice.
0
 
LVL 73

Accepted Solution

by:
sdstuber earned 500 total points
ID: 36473554
I'd keep it like this...

SELECT *
  FROM subj
      LEFT JOIN care_inc
          ON subj.care_seq = care_inc.care_seq AND subj.one_id = care_inc.one_id
      LEFT JOIN v_mat
          ON care_inc.one_id = v_mat.one_id AND care_inc.care_seq = v_mat.care_seq
      LEFT JOIN material
          ON v_mat.material_id = material.material_id
      LEFT JOIN one
          ON subj.one_id = one.one_id
      LEFT JOIN basic_module_one_info
          ON     subj.module_id = basic_module_one_info.module_id
             AND subj.care_seq = basic_module_one_info.care_seq
             AND subj.one_id = basic_module_one_info.one_id
      LEFT JOIN one_facility_info
          ON care_inc.facility_id = one_facility_info.facility_id
             AND care_inc.one_id = one_facility_info.one_id
      LEFT JOIN person
          ON subj.worker_text = person.full_name



but if you're force too

SELECT *
  FROM subj,
       care_inc,
       v_mat,
       material,
       one,
       basic_module_one_info,
       one_facility_info,
       person
 WHERE     subj.care_seq = care_inc.care_seq(+)
       AND subj.one_id = care_inc.one_id(+)
       AND care_inc.one_id = v_mat.one_id(+)
       AND care_inc.care_seq = v_mat.care_seq(+)
       AND v_mat.material_id = material.material_id(+)
       AND subj.one_id = one.one_id(+)
       AND subj.module_id = basic_module_one_info.module_id(+)
       AND subj.care_seq = basic_module_one_info.care_seq(+)
       AND subj.one_id = basic_module_one_info.one_id(+)
       AND care_inc.facility_id = one_facility_info.facility_id(+)
       AND care_inc.one_id = one_facility_info.one_id(+)
       AND subj.worker_text = person.full_name(+)
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 11

Author Comment

by:it-rex
ID: 36473695
sdstuber;
I thought that we only outer using (+) whenever we see "on";
but if there is "and" we show the join as is without (+),
please advise
0
 
LVL 73

Expert Comment

by:sdstuber
ID: 36473716
no,

if you do this...


AND x.col1 = y.col1(+)
and x.col2 = y.col2

that's the same thing as...

ON x.col1 = y.col
WHERE x.col2 = y.col2

which is the same thing as...

AND x.col1 = y.col1
AND c.col2=y.col2

which is an inner join

in order to do outer joins you must put the (+) on ALL references to the outer joined table in the where clause



0
 
LVL 11

Author Comment

by:it-rex
ID: 36473735
your works,you are the man.
0
 
LVL 11

Author Closing Comment

by:it-rex
ID: 36473739
great
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
Via a live example, show how to take different types of Oracle backups using RMAN.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now