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
Solved

from ansi sql to oracle sql

Posted on 2011-09-02
7
367 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 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
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 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
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…
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

840 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