Parsing order (Was: "select ... connect by... " in the view) 2004-03-10 - By Igor Neyman
Ok, I see no takers on my original question (how to create a view based
on "select . connect by. and prior. start with. " to get the hierarchy).
May be this will spark some interest, I guess it 's about parsing order.
The view I 'm using looks like this:
SQL*Plus: Release 9.2.0.1.0 - Production on Wed Mar 10 08:42:51 2004
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
SQL > create or replace view test_view_ms as
2 SELECT
3 vt.model_id, vt.lvl "LEVEL ", vt.parent_subassembly_id,
vt.subassembly_id
4 FROM test_ms tm, TABLE(m_tree(tm.model_id)) vt;
View created.
And it works fine; "m_tree " is a function that hides "select . connect
by. and prior. start with. ".
"test_ms " table added to the join in order to be able to specify
"model_id " when querying this view.
But, if I change the order in the "FROM " list, I get an error:
SQL > create or replace view test_view_ms as
2 SELECT
3 vt.model_id, vt.lvl "LEVEL ", vt.parent_subassembly_id,
vt.subassembly_id
4 FROM TABLE(m_tree(tm.model_id)) vt, test_ms tm;
FROM TABLE(m_tree(tm.model_id)) vt, test_ms tm
*
ERROR at line 4:
ORA-00904 (See ORA-00904.ora-code.com): "TM ". "MODEL_ID ": invalid identifier
Is it because of the way (order) Oracle is parsing this view?
Igor Neyman, OCP DBA
ineyman@(protected)
-- --Original Message-- --
From: oracle-l-bounce@(protected)
[mailto:oracle-l-bounce@(protected)] On Behalf Of Igor Neyman
Sent: Thursday, February 26, 2004 11:44 AM
To: oracle-l@(protected)
Subject: "select ... connect by... " in the view
Just wonder if anyone has (or came across) better solution for this.
I had a request from developer to put "select . connect by. " into view.
He wants to get the hierarchy in one step, but the "framework " he is
using doesn 't allow him to issue "select . connect by. ".
I 've got rather ugly solution for him (which I can share if anyone
interested, didn 't want this message to be long), using user types,
function, and the final view looks like this:
create or replace view test_view_ms as
SELECT
vt.model_id, vt.lvl "LEVEL ", vt.parent_subassembly_id, vt.subassembly_id
FROM test_ms tm, TABLE(m_tree(tm.model_id)) vt;
So, now he can get the hierarchy for specified model with just:
select from test_view_ms where model_id = .
Igor Neyman, OCP DBA
ineyman@(protected)
<html >
<head >
<META HTTP-EQUIV= "Content-Type " CONTENT= "text/html; charset=us-ascii " >
<meta name=Generator content= "Microsoft Word 10 (filtered) " >
<style >
<!--
/* Font Definitions */
@(protected)
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family: "Times New Roman ";}
a:link, span.MsoHyperlink
{color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{color:purple;
text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
{margin:0in;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family: "Courier New ";}
span.emailstyle17
{font-family:Arial;
color:windowtext;}
span.EmailStyle19
{font-family:Arial;
color:navy;}
@(protected) Section1
{size:8.5in 11.0in;
margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
{page:Section1;}
-- >
</style >
</head >
<body lang=EN-US link=blue vlink=purple >
<div class=Section1 >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' >Ok, I see no takers on my original question
(how to create a view based on “select … connect by… and
prior… start with…” to get the hierarchy). </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' >May be this will spark some interest, I
guess it’s about parsing order. </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' > </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' >The view I’m using looks like this: </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' > </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' >SQL*Plus: Release 9.2.0.1.0 - Production
on Wed Mar 10 </span > </font > <font size=2 color=navy face=Arial > <span
style= 'font-size:10.0pt;font-family:Arial;color:navy ' >08:42:51 </span > </font > <font
size=2 color=navy face=Arial > <span style= 'font-size:10.0pt;font-family:Arial;
color:navy ' > 2004 </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' > </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' >Copyright (c) 1982, 2002, Oracle
Corporation. All rights reserved. </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' > </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' >Connected to: </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' >Oracle9i </span > </font > <font size=2
color=navy face=Arial > <span style= 'font-size:10.0pt;font-family:Arial;
color:navy ' >Enterprise </span > </font > <font size=2 color=navy face=Arial > <span
style= 'font-size:10.0pt;font-family:Arial;color:navy ' > Edition Release
9.2.0.1.0 - Production </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' >With the Partitioning, OLAP and Oracle
Data Mining options </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' >JServer Release 9.2.0.1.0 - Production </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' > </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' >SQL> create or replace view test_view_ms
as </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' > 2 SELECT </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' > 3 vt.model_id, vt.lvl
"LEVEL", vt.parent_subassembly_id, vt.subassembly_id </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' > 4 FROM test_ms tm, TABLE(m_tree(tm.model_id))
vt; </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' > </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' >View created. </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' > </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' >And it works fine; “m_tree” is
a function that hides “select … connect by… and prior…
start with…”. </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' >“test_ms” table added to the
join in order to be able to specify “model_id” when querying this
view. </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' > </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' >But, if I change the order in the “FROM”
list, I get an error: </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' > </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' >SQL> create or replace view test_view_ms
as </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' > 2 SELECT </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' > 3 vt.model_id, vt.lvl
"LEVEL", vt.parent_subassembly_id, vt.subassembly_id </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' > 4 FROM TABLE(m_tree(tm.model_id))
vt, test_ms tm; </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' >FROM TABLE(m_tree(tm.model_id)) vt, test_ms
tm </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' >
* </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' >ERROR at line 4: </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' >ORA-00904 (See ORA-00904.ora-code.com):
"TM"."MODEL_ID": invalid identifier </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' > </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' >Is it because of the way (order) Oracle is
parsing this view? </span > </font > </p >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' > </span > </font > </p >
<div >
<p class=MsoPlainText > <font size=2 color=navy face= "Courier New " > <span
style= 'font-size:10.0pt;color:navy ' >Igor Neyman, OCP DBA </span > </font > </p >
<p class=MsoPlainText > <font size=2 color=navy face= "Courier New " > <span
style= 'font-size:10.0pt;color:navy ' >ineyman@(protected) </span > </font > </p >
<p class=MsoPlainText > <font size=2 color=navy face= "Courier New " > <span
style= 'font-size:10.0pt;color:navy ' > </span > </font > </p >
</div >
<p class=MsoNormal > <font size=2 color=navy face=Arial > <span style= 'font-size:
10.0pt;font-family:Arial;color:navy ' > </span > </font > </p >
<p class=MsoNormal style= 'margin-left:.5in ' > <font size=2 face=Tahoma > <span
style= 'font-size:10.0pt;font-family:Tahoma ' >-- --Original Message-- -- <br >
<b > <span style= 'font-weight:bold ' >From: </span > </b > oracle-l-bounce@(protected)
[mailto:oracle-l-bounce@(protected)] <b > <span style= 'font-weight:bold ' >On
Behalf Of </span > </b >Igor Neyman <br >
<b > <span style= 'font-weight:bold ' >Sent: </span > </b > </span > </font > <font size=2 face=Tahoma > <span style= 'font-size:10.0pt;font-family:Tahoma ' >Thursday,
February 26, 2004 </span > </font > <font size=2 face=Tahoma > <span
style= 'font-size:10.0pt;font-family:Tahoma ' > </span > </font > <font
size=2 face=Tahoma > <span style= 'font-size:10.0pt;font-family:Tahoma ' >11:44 AM </span > </font > <font
size=2 face=Tahoma > <span style= 'font-size:10.0pt;font-family:Tahoma ' > <br >
<b > <span style= 'font-weight:bold ' >To: </span > </b > oracle-l@(protected) <br >
<b > <span style= 'font-weight:bold ' >Subject: </span > </b > "select ... connect
by..." in the view </span > </font > </p >
<p class=MsoNormal style= 'margin-left:.5in ' > <font size=3 face= "Times New Roman " > <span
style= 'font-size:12.0pt ' > </span > </font > </p >
<p class=MsoNormal style= 'margin-left:.5in ' > <font size=2 face=Arial > <span
style= 'font-size:10.0pt;font-family:Arial ' >Just wonder if anyone has (or came
across) better solution for this. </span > </font > </p >
<p class=MsoNormal style= 'margin-left:.5in ' > <font size=2 face=Arial > <span
style= 'font-size:10.0pt;font-family:Arial ' > </span > </font > </p >
<p class=MsoNormal style= 'margin-left:.5in ' > <font size=2 face=Arial > <span
style= 'font-size:10.0pt;font-family:Arial ' >I had a request from developer to
put “select … connect by…” into view. </span > </font > </p >
<p class=MsoNormal style= 'margin-left:.5in ' > <font size=2 face=Arial > <span
style= 'font-size:10.0pt;font-family:Arial ' >He wants to get the hierarchy in one
step, but the “framework” he is using doesn’t allow him to
issue “select … connect by…”. </span > </font > </p >
<p class=MsoNormal style= 'margin-left:.5in ' > <font size=2 face=Arial > <span
style= 'font-size:10.0pt;font-family:Arial ' >I’ve got rather ugly solution
for him (which I can share if anyone interested, didn’t want this message
to be long), using user types, function, and the final view looks like this: </span > </font > </p >
<p class=MsoNormal style= 'margin-left:.5in ' > <font size=2 face=Arial > <span
style= 'font-size:10.0pt;font-family:Arial ' > </span > </font > </p >
<p class=MsoNormal style= 'margin-left:.5in ' > <font size=2 face=Arial > <span
style= 'font-size:10.0pt;font-family:Arial ' >create or replace view test_view_ms
as </span > </font > </p >
<p class=MsoNormal style= 'margin-left:.5in ' > <font size=2 face=Arial > <span
style= 'font-size:10.0pt;font-family:Arial ' >SELECT </span > </font > </p >
<p class=MsoNormal style= 'margin-left:.5in ' > <font size=2 face=Arial > <span
style= 'font-size:10.0pt;font-family:Arial ' >vt.model_id, vt.lvl
"LEVEL", vt.parent_subassembly_id, vt.subassembly_id </span > </font > </p >
<p class=MsoNormal style= 'margin-left:.5in ' > <font size=2 face=Arial > <span
style= 'font-size:10.0pt;font-family:Arial ' >FROM test_ms tm,
TABLE(m_tree(tm.model_id)) vt; </span > </font > </p >
<p class=MsoNormal style= 'margin-left:.5in ' > <font size=2 face=Arial > <span
style= 'font-size:10.0pt;font-family:Arial ' > </span > </font > </p >
<p class=MsoNormal style= 'margin-left:.5in ' > <font size=2 face=Arial > <span
style= 'font-size:10.0pt;font-family:Arial ' >So, now he can get the hierarchy for
specified model with just: </span > </font > </p >
<p class=MsoNormal style= 'margin-left:.5in ' > <font size=2 face=Arial > <span
style= 'font-size:10.0pt;font-family:Arial ' >select from test_view_ms where
model_id = … </span > </font > </p >
<p class=MsoNormal style= 'margin-left:.5in ' > <font size=2 face=Arial > <span
style= 'font-size:10.0pt;font-family:Arial ' > </span > </font > </p >
<p class=MsoPlainText style= 'margin-left:.5in ' > <font size=2 face= "Courier New " > <span
style= 'font-size:10.0pt ' >Igor Neyman, OCP DBA </span > </font > </p >
<p class=MsoPlainText style= 'margin-left:.5in ' > <font size=2 face= "Courier New " > <span
style= 'font-size:10.0pt ' >ineyman@(protected) </span > </font > </p >
<p class=MsoPlainText style= 'margin-left:.5in ' > <font size=2 face= "Courier New " > <span
style= 'font-size:10.0pt ' > </span > </font > </p >
<p class=MsoNormal style= 'margin-left:.5in ' > <font size=3 face= "Times New Roman " > <span
style= 'font-size:12.0pt ' > </span > </font > </p >
</div >
</body >
</html >
|
|