Solved

from ansi sql to oracle sql

Posted on 2011-09-02
7
368 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 74

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 74

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 74

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
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.  …
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

740 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