Home » SQL & PL/SQL » SQL & PL/SQL » Same query not working in different schema's (Oracle 10g Rel 2)
Same query not working in different schema's [message #606414] Thu, 23 January 2014 09:42 Go to next message
chat2raj.s
Messages: 161
Registered: October 2010
Location: Chennai, India
Senior Member
Dear Friend,

I have a peculiar issue, where my below query is able to fetch me results in one schema, where as not in the other schema. The error i face is ORA-00904: "B"."ASC_ITEM_CODE": invalid identifier. Actually it is a bigger query, i broke down to make it small to get the same error as i got in original query.

Error found in : Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bi
Working fine in : Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
Both have same : PL/SQL Release 10.2.0.1.0 - Production

Is that 64bi and Prod, makes a difference.

SELECT asc_item_code,
       asc_item_name,
       asc_grade_code_1,
       asc_alloc_qty,
       (SELECT lcs_stk_qty_bu
        FROM   (SELECT lcs_stk_qty_bu
                FROM   os_locn_curr_stk
                WHERE  B.asc_item_code = lcs_item_code))ASC_FREE_STK
FROM   ov_alloc_stk_ctc B;


Pls help.

Regards
RajS
Re: Same query not working in different schema's [message #606415 is a reply to message #606414] Thu, 23 January 2014 09:53 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
That query shouldn't work in either enviroment.
When referring to a table defined in an outer query you're only allowed to refer to tables that are defined one level out.
In your example b is defined two levels out.

That only works because of a bug - you'll have to rewrite it.
Re: Same query not working in different schema's [message #606417 is a reply to message #606415] Thu, 23 January 2014 10:14 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
That only works because of a bug.


I confirm, it is a bug in 10.2.0.1 and only 10.2.0.1.

Re: Same query not working in different schema's [message #606430 is a reply to message #606417] Thu, 23 January 2014 13:47 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
Michel Cadot wrote on Thu, 23 January 2014 11:14

I confirm, it is a bug in 10.2.0.1 and only 10.2.0.1.


SQL> select banner from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
CORE    11.2.0.2.0      Production
TNS for HPUX: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production

SQL> select (select dummy z from (select dummy y from dual where dummy=d.dummy)) z from dual d
  2  /
select (select dummy z from (select dummy y from dual where dummy=d.dummy)) z from dual d
                                                                  *
ERROR at line 1:
ORA-00904: "D"."DUMMY": invalid identifier


SQL> connect scott@pdborcl12
Enter password: *****
Connected.
SCOTT@pdborcl12 > select banner from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
PL/SQL Release 12.1.0.1.0 - Production
CORE    12.1.0.1.0      Production
TNS for 64-bit Windows: Version 12.1.0.1.0 - Production
NLSRTL Version 12.1.0.1.0 - Production

SCOTT@pdborcl12 > select (select dummy z from (select dummy y from dual where dummy=d.dummy)) z from dual d
  2  /

Z
-
X

SCOTT@pdborcl12 > 


And:

SCOTT@pdborcl12 > var c clob
SCOTT@pdborcl12 > exec dbms_utility.expand_sql_text('select (select dummy z from (select dummy y from dual where dummy=d.dummy)) z from dual d',:c);

PL/SQL procedure successfully completed.

SCOTT@pdborcl12 > print c

C
---------------------------------------------------------------
SELECT  (SELECT "A1"."DUMMY" "Z" FROM  (SELECT "A3"."DUMMY" "Y"
 FROM "SYS"."DUAL" "A3" WHERE "A3"."DUMMY"=:B1) "A2") "Z" FROM
"SYS"."DUAL" "A1"

SCOTT@pdborcl12 > 


Didn't have a chance to open SR with Oracle to find out if it is a bug or starting 12C we can correlate more than one level deep (nothing in docs - at least I couldn't find any references).

SY.
Re: Same query not working in different schema's [message #606431 is a reply to message #606430] Thu, 23 January 2014 14:06 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
Didn't have a chance to open SR with Oracle to find out if it is a bug or starting 12C we can correlate more than one level deep


I think it is the same bug than in 10.2.0.1; standard says correlation can be done on one level only (unless a new standard came since).

Re: Same query not working in different schema's [message #606461 is a reply to message #606414] Fri, 24 January 2014 04:09 Go to previous messageGo to next message
chat2raj.s
Messages: 161
Registered: October 2010
Location: Chennai, India
Senior Member
Dear friends,

Thanks to all. Let me try to rewrite the query to avoid this bug.
Re: Same query not working in different schema's [message #606523 is a reply to message #606461] Sat, 25 January 2014 11:12 Go to previous message
Kevin Meade
Messages: 2103
Registered: December 1999
Location: Connecticut USA
Senior Member
different schemas = different tables. This would explain your error of invalid identifier. Check to see what objects have the same name and compare their definitions.


Kevin
Previous Topic: how to Fast Compare
Next Topic: Populating Primary Key Column using Sequence
Goto Forum:
  


Current Time: Fri Apr 19 04:01:56 CDT 2024