DISQUS

Eddie Awad’s Blog: When ANSI SQL Join Syntax Does Not Work in Oracle

  • Andy Todd · 2 years ago

    Yes its a bug. Although I haven't had any success getting official confirmation of that.


    My workaround is to continue using ANSI join syntax but to use in-line tables in my from clause.


    e.g. instead of


    FROM table_a a JOIN table_b b ON a.fk=b.pk


    I use
    FROM (SELECT fk, other_col FROM table_a) a
    JOIN (SELECT pk, other_other_col FROM table_b) b ON a.fk = b.pk


    Its a nasty bodge but still gives much more readable SQL (IMHO of course).

  • Andy Todd · 2 years ago

    Sorry, where I said readable SQL what I should have added is that it is more readable because it still allows you to separate the join predicates from the actual where predicates.


    Which is my major problem with the 'good old' Oracle syntax.

  • Don Seiler · 2 years ago

    Eep definitely a bug. Does it happen when the total number of columns selected exceeds 1050, or if the total number of columns in the tables exceeds 1050 (regardless of which columns are actually specified)?

  • Patrick Barel · 2 years ago

    Judging from the example Eddie it is the total number of colums, regardless of how many columns are actually selected. Select null from ... tells me that it doesn't matter how many columns are actually selected ;-). I would have to try this out myself, but it appears I don't want to switch over to Ansi SQL, when there is no need for it.
    Good pointer, thanks Eddie.

  • Patrick Wolf · 2 years ago

    A dump question, but who has 1050 columns in 1 table or 7 tables? That are still 150 each!


    I would question the data model...


    Patrick

  • Eddie Awad · 2 years ago

    Let's see how many total columns exist in the tables I select from in my example above:


    <pre>APPS@sigma> SELECT COUNT (*)
    2 FROM all_tab_columns
    3 WHERE table_name IN
    4 ('OE_ORDER_HEADERS_ALL',
    5 'OE_ORDER_LINES_ALL',
    6 'RA_CUSTOMERS',
    7 'MTL_SYSTEM_ITEMS_B',
    8 'ORG_ORGANIZATION_DEFINITIONS',
    9 'RA_SALESREPS_ALL',
    10 'HR_LOCATIONS_ALL'
    11 );

    COUNT(*)
    ----------
    1072
    </pre>

    The table OE_ORDER_LINES_ALL alone has 340 columns. These are all standard Oracle EBS tables.

  • Patrick Wolf · 2 years ago

    As I already said, "interesting" data model :-)


    Never had to do anything with Oracle Applications, probably SAP will not be better from a data model point of view.


    Patrick

  • Laurent Schneider · 2 years ago

    what about this...


    select u1.object_name, u1.object_type, u2.object_type, u2.object_type
    from all_objects u1 full outer join all_objects u2 on
    (u1.object_name=u2.object_name);


    from all_objects u1 full outer join all_objects u2 on
    *
    ERROR at line 2:
    ORA-00904: "XML_SCHEMA_NAME_PRESENT"."IS_SCHEMA_PRESENT": invalid identifier

  • Laurent Schneider · 2 years ago

    well, to make sense the query condition should contain


    and u1.owner='FOO' and u2.owner='BAR'


    but the bug is the same... not found on metalink yet

  • Eddie Awad · 2 years ago

    Thanks for pointing out another ANSI join error Laurent. Too bad there is no corresponding FULL OUTER JOIN syntax in the "good old" Oracle join syntax, so we can compare. I wonder if Oracle DB 11g had these bugs fixed.

  • Mike Studholme · 2 years ago
    I just had this problem reported to me and as I was provided nice little(ish) test case I was able to take an export of the schema involved and try it on Oracle 11g.

    I'm happy to say that the query that was failing in Oracle 10.2.0.3.0 interim patch 12 works fine in Oracle 11.1.0.6.0.

    I haven't found the bit of documentation that stated if the 1050 limit has been increased but I suspect this it what has changed.

    I suspect also that the Oracle pseudo columns are included in the limit as the number of columns in the query that was failing was only just over 1000.
  • jabber2 · 1 year ago
    Nice looking site providing detailled information about sql syntax: www.sqlexikon.de have a look (ooch, this site is german)
  • Paul Hartness · 1 year ago
    I'm experiencing this problem and it erks me that I have to switch my queries from ANSI to non-ANSI. However it erks me even more that I have to deal with a table with over 300 columns!!! I find it staggering that any professional organisation that relies on such a database for mission critical operations involving billions for euros can allow such a thing to happen.
  • Sanjay · 1 year ago
    Take a look at the Query itself... putting a (+) on the Left Side does not mean a LEFT OUTER JOIN as you have written... i mean for example in the old way if we put the (+) on RIGHT side that actually should interprete as LEFT OUTER JOIN keeping the Tables in the same sqquence... so please check the Query itself... sould work... simple stuff!
  • Juanky · 1 year ago
    Question? What syntax is more efficient for writing PLSQL... ANSI or the old Oracle way?? When I say efficient is performance, and maintainability wise..
    Thanks
  • Eddie Awad · 1 year ago
    Juanky, you meant writng SQL not PL/SQL, right? Performance should be the same unless proven otherwise. I personally prefer ANSI SQL because it's easier to read.
  • Brian Tkatch · 1 year ago
    I personally prefer Oracle's was because it’s easy to read, and i personally find the ANSI syntax to be very hard to follow especially once it starts to nest.