Dynamic SQL 2006-04-06 - By Jared Still
rowid is a reserved word.
put it double quotes in uppercase, or alias the name to something else in the SQL
eg. select rowid my_rowid from table_name
On 4/6/06, ora_forum <ora_forum@(protected)> wrote: > > Sorry. > > * > ERROR at line 9: > ORA-06550 (See ORA-06550.ora-code.com): line 9, column 34: > PL/SQL: ORA-00942 (See ORA-00942.ora-code.com): table or view does not exist > ORA-06550 (See ORA-06550.ora-code.com): line 9, column 14: > PL/SQL: SQL Statement ignored > ORA-06550 (See ORA-06550.ora-code.com): line 11, column 8: > PLS-00204: function or pseudo-column 'ROWID' may be used inside a SQL > statement > only > ORA-06550 (See ORA-06550.ora-code.com): line 11, column 5: > PL/SQL: Statement ignored > > > *"Reidy, Ron" <Ron.Reidy@(protected)>* wrote: > > You cannot test for NULL with the '=, <>, !=', etc. operators. The > correct syntax is "? IS NOT NULL". > > Also, what is not working? > > > -- --Original Message-- -- > *From:* oracle-l-bounce@(protected) [mailto: > oracle-l-bounce@(protected)] *On Behalf Of *ora_forum > *Sent:* Thursday, April 06, 2006 9:53 AM > *To:* oracle-l@(protected) > *Subject:* Dynamic SQL > > Hi All: > Could you tell me what I'm doing wrong? > I need pass different schema owner in SQL, also in some tables there are > multiple records will be returned. > > DECLARE > m_dated DATE; > m_count NUMBER(10); > m_details varchar2(4000); > m_moduser varchar2(250); > BEGIN > FOR r IN (SELECT owner FROM all_tables WHERE table_name=upper('Audittrail') > order by owner) > LOOP > FOR n IN (SELECT ROWID FROM r.Audittrail where action=8) > LOOP > IF ROWID<>'NULL' or ROWID<>0 THEN > EXECUTE IMMEDIATE 'SELECT Dated, Details, Moduser FROM ' || R.owner ||' .Audittrail > where rowid='||n||'.rowid' into m_dated, m_details, m_moduser; > dbms_output.put_line ( m_dated,m_details, m_moduser); > ELSE > NULL; > END IF; > END LOOP; > END LOOP; > END; > / > > Thanks. > -- ---- ---- ---- ---- ---- -- > Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls. Great > rates starting at 1¢/min.<http://us.rd.yahoo.com/mail_us/taglines/postman7/ *http:/us.rd.yahoo.com/evt=39666/*http:/beta.messenger.yahoo.com> > -- ---- ---- ---- ---- ---- -- > This electronic message transmission is a PRIVATE communication which > contains information > which may be confidential or privileged. The information is intended to be > for the use of the individual > or entity named above. If you are not the intended recipient, please be > aware that any disclosure, > copying, distribution or use of the contents of this information is > prohibited. Please notify the sender > of the delivery error by replying to this message, or notify us by > telephone (877-633-2436, ext. 0), > and then delete it from your system. > > > -- ---- ---- ---- ---- ---- -- > How low will we go? Check out Yahoo! Messenger's low PC-to-Phone call > rates. > <http://us.rd.yahoo.com/mail_us/taglines/postman8/*http://us.rd.yahoo.com/evt =39663/*http://voice.yahoo.com> > >
-- Jared Still Certifiable Oracle DBA and Part Time Perl Evangelist
rowid is a reserved word.<br><br>put it double quotes in uppercase, or alias the name to <br>something else in the SQL<br><br>eg. select rowid my_rowid from table_name<br><br><br><div><span class="gmail_quote">On 4/6/06, <b class="gmail _sendername"> ora_forum</b> <<a href="mailto:ora_forum@(protected)">ora_forum@(protected)</a> > wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> <div style="direction: ltr;"><div>Sorry.</div> <div> </div> <div> *<br>ERROR at line 9:<br>ORA-06550 (See ORA-06550.ora-code.com): line 9, column 34:<br>PL/SQL: ORA-00942 (See ORA-00942.ora-code.com): table or view does not exist<br>ORA-06550 (See ORA-06550.ora-code.com): line 9, column 14: <br>PL/SQL: SQL Statement ignored<br>ORA-06550 (See ORA-06550.ora-code.com): line 11, column 8:<br>PLS-00204 : function or pseudo-column 'ROWID' may be used inside a SQL statement<br>only <br>ORA-06550 (See ORA-06550.ora-code.com): line 11, column 5:<br>PL/SQL: Statement ignored</div> <div style="direction: ltr;"><span class="e" id="q_10a703801564e5c4_1"><br><br> <b><i>"Reidy, Ron" <<a href="mailto:Ron.Reidy@(protected)" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> Ron.Reidy@(protected)</a>></i></b> wrote:</span></div><div style= "direction: ltr;"></div></div><div style="direction: ltr;"><span class="e" id="q _10a703801564e5c4_3"> <blockquote style="border-left: 2px solid rgb(16, 16, 255 ); padding-left: 5px; margin-left: 5px;"> <div> <div><font color="navy" face="Arial" size="2"><span style="font -size: 10pt; color: navy; font-family: Arial;">You cannot test for NULL with the '=, <>, !=', etc. operators. The correct syntax is "? IS NOT NULL". </span></font></div> <div><font color="navy" face="Arial" size="2"><span style ="font-size: 10pt; color: navy; font-family: Arial;"></span></font> </div> <div><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; color: navy; font-family: Arial;">Also, what is not working?</span></font></div > <div><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; color: navy; font-family: Arial;"> </span></font> </div> <div><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; color: navy; font-family: Arial;"></span></font> < /div> <div style="margin-left: 0.5in;"><font face="Tahoma" size="2"><span style ="font-size: 10pt; font-family: Tahoma;"> -- --Original Message-- --<br><b><span style="font-weight: bold;">From:</span>< /b> <a href="mailto:oracle-l-bounce@(protected)" target="_blank" onclick= "return top.js.OpenExtLink(window,event,this)">oracle-l-bounce@(protected) </a> [mailto:<a href="mailto:oracle-l-bounce@(protected)" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">oracle-l-bounce @(protected)</a>] <b><span style="font-weight: bold;">On Behalf Of </span> </b>ora_forum<br><b><span style="font-weight: bold;">Sent:</span></b> Thursday, April 06, 2006 9:53 AM<br><b><span style="font-weight: bold;">To:</span></b> <a href="mailto:oracle-l@(protected)" target="_blank" onclick="return top.js .OpenExtLink(window,event,this)"> oracle-l@(protected)</a><br><b><span style="font-weight: bold;">Subject:< /span></b> Dynamic SQL </span></font></div> <div style="margin-left: 0.5in;"> <font face="Times New Roman" size="3"><span style="font-size: 12pt;"> </span></font> </div> <div> <div style="margin-left: 0.5in;"><font face= "Times New Roman" size="3"><span style="font-size: 12pt;">Hi All:</span></font>< /div></div> <div> <div style="margin-left: 0.5in;"><font face="Times New Roman " size="3"> <span style="font-size: 12pt;">Could you tell me what I'm doing wrong?</span>< /font></div></div> <div> <div style="margin-left: 0.5in;"><font face="Times New Roman" size="3"><span style="font-size: 12pt;">I need pass different schema owner in SQL, also in some tables there are multiple records will be returned. </span></font></div></div> <div> <div style="margin-left: 0.5in;"><font face= "Times New Roman" size="3"><span style="font-size: 12pt;"></span></font> < /div></div> <div> <div> <div style="margin-left: 0.5in;"><font color="blue" face="Times New Roman" size="2"><span style="font-size: 10pt; color: blue;">DECLARE<br></span>< /font><font color="black" size="2"><span style="font-size: 10pt; color: black;"> m_dated </span></font><font color="blue" size="2"><span style="font-size: 10pt; color: blue;">DATE</span></font><font color="black" size="2"><span style="font -size: 10pt; color: black;">;<br>m_count </span></font><font color="blue" size= "2"> <span style="font-size: 10pt; color: blue;">NUMBER</span></font><font color= "black" size="2"><span style="font-size: 10pt; color: black;">(10);<br>m_details </span></font><font color="blue" size="2"><span style="font-size: 10pt; color: blue;"> varchar2</span></font><font color="black" size="2"><span style="font-size: 10pt ; color: black;">(4000);<br>m_moduser </span></font><font color="blue" size="2"> <span style="font-size: 10pt; color: blue;">varchar2</span></font> <font color="black" size="2"><span style="font-size: 10pt; color: black;">(250) ;<br></span></font><font color="blue" size="2"><span style="font-size: 10pt; color: blue;">BEGIN<br>FOR</span></font><font color="black" size="2"> <span style="font-size: 10pt; color: black;"> r </span></font><font color="blue " size="2"><span style="font-size: 10pt; color: blue;">IN</span></font><font color="black" size="2"><span style="font-size: 10pt; color: black;"> (</span></font><font color="blue" size="2"><span style="font-size: 10pt; color : blue;">SELECT</span></font><font color="black" size="2"><span style="font-size : 10pt; color: black;"> owner </span></font><font color="blue" size="2"> <span style="font-size: 10pt; color: blue;">FROM</span></font><font color= "black" size="2"><span style="font-size: 10pt; color: black;"> all_tables </span ></font><font color="blue" size="2"><span style="font-size: 10pt; color: blue;"> WHERE</span></font><font color="black" size="2"><span style="font-size: 10pt; color: black;"> table_name=</span></font><font color="blue" size="2"><span style="font-size: 10pt; color: blue;">upper</span></font><font color="black" size="2"> <span style="font-size: 10pt; color: black;">(</span></font><font color="red" size="2"><span style="font-size: 10pt; color: red;">'Audittrail'</span></font> <font color="black" size="2"><span style="font-size: 10pt; color: black;"> ) </span></font><font color="blue" size="2"><span style="font-size: 10pt; color : blue;">order</span></font><font color="black" size="2"><span style="font-size: 10pt; color: black;"> </span></font><font color="blue" size="2"> <span style="font-size: 10pt; color: blue;">by</span></font><font color="black" size="2"><span style="font-size: 10pt; color: black;"> owner)<br></span></font> <font color="blue" size="2"><span style="font-size: 10pt; color: blue;"> LOOP<br>FOR</span></font><font color="black" size="2"><span style="font-size: 10pt; color: black;"> n </span></font><font color="blue" size="2"><span style= "font-size: 10pt; color: blue;">IN</span></font><font color="black" size="2"> <span style="font-size: 10pt; color: black;"> (</span></font><font color="blue" size="2"><span style="font-size: 10pt; color: blue;">SELECT</span></font><font color="black" size="2"><span style="font-size: 10pt; color: black;"> </span></font><font color="blue" size="2"><span style="font-size: 10pt; color: blue;">ROWID</span></font><font color="black" size="2"><span style="font-size: 10pt; color: black;"> </span></font><font color="blue" size="2"> <span style="font-size: 10pt; color: blue;">FROM</span></font><font color= "black" size="2"><span style="font-size: 10pt; color: black;"> r.Audittrail < /span></font><font color="blue" size="2"><span style="font-size: 10pt; color: blue;"> where</span></font><font color="black" size="2"><span style="font-size: 10pt; color: black;"> action=8)<br></span></font><font color="blue" size="2"><span style="font-size: 10pt; color: blue;">LOOP<br>IF</span></font><font color= "black" size="2"> <span style="font-size: 10pt; color: black;"> </span></font><font color="blue" size="2"><span style="font-size: 10pt; color: blue;">ROWID</span></font><font color="black" size="2"><span style="font-size: 10pt; color: black;"> <></span></font><font color="red" size="2"><span style="font-size: 10pt; color: red;">'NULL'</span></font><font color="black" size="2"><span style="font -size: 10pt; color: black;"> </span></font><font color="blue" size="2"> <span style="font-size: 10pt; color: blue;">or</span></font><font color="black" size="2"><span style="font-size: 10pt; color: black;"> </span></font><font color="blue" size="2"><span style="font-size: 10pt; color: blue;"> ROWID</span></font><font color="black" size="2"><span style="font-size: 10pt; color: black;"><>0 </span></font><font color="blue" size="2"><span style= "font-size: 10pt; color: blue;">THEN<br>EXECUTE</span></font><font color="black" size="2"> <span style="font-size: 10pt; color: black;"> </span></font><font color="blue" size="2"><span style="font-size: 10pt; color: blue;">IMMEDIATE</span></font> <font color="black" size="2"><span style="font-size: 10pt; color: black;"> </span></font><font color="red" size="2"><span style="font-size: 10pt; color: red;">'SELECT Dated, Details, Moduser FROM '</span></font><font color="black" size="2"><span style="font-size: 10pt; color: black;"> || R.owner ||</span></font><font color="red" size="2"><span style="font-size: 10pt; color : red;">'.Audittrail where rowid='</span></font><font color="black" size="2"> <span style="font-size: 10pt; color: black;">||n||</span></font><font color="red " size="2"> <span style="font-size: 10pt; color: red;">'.rowid'</span></font><font color= "black" size="2"><span style="font-size: 10pt; color: black;"> </span></font> <font color="blue" size="2"><span style="font-size: 10pt; color: blue;"> into</span></font><font color="black" size="2"><span style="font-size: 10pt; color: black;"> m_dated, m_details, m_moduser; <br>dbms_output.put_line ( m _dated,m_details, m_moduser);<br></span></font><font color="blue" size="2"> <span style="font-size: 10pt; color: blue;">ELSE<br>NULL</span></font><font color="black" size="2"><span style="font-size: 10pt; color: black;">;<br></span ></font><font color="blue" size="2"><span style="font-size: 10pt; color: blue;"> END</span></font><font color="black" size="2"><span style="font-size: 10pt; color: black;"> </span></font><font color="blue" size="2"><span style="font -size: 10pt; color: blue;">IF</span></font><font color="black" size="2"> <span style="font-size: 10pt; color: black;">;<br></span></font><font color= "blue" size="2"><span style="font-size: 10pt; color: blue;">END</span></font> <font color="black" size="2"><span style="font-size: 10pt; color: black;"> </span></font><font color="blue" size="2"><span style="font-size: 10pt; color: blue;">LOOP</span></font><font color="black" size="2"><span style="font-size: 10pt; color: black;">;<br></span></font><font color="blue" size="2"> <span style="font-size: 10pt; color: blue;">END</span></font><font color="black " size="2"><span style="font-size: 10pt; color: black;"> </span></font><font color="blue" size="2"><span style="font-size: 10pt; color: blue;"> LOOP</span></font><font color="black" size="2"><span style="font-size: 10pt; color: black;">;<br></span></font><font color="blue" size="2"><span style="font -size: 10pt; color: blue;">END</span></font><font color="black" size="2"> <span style="font-size: 10pt; color: black;">;<br>/</span></font></div></div> <div> <div style="margin-left: 0.5in;"><font color="blue" face="Times New Roman " size="2"><span style="font-size: 10pt; color: blue;"></span> </font> </div></div> <div> <div style="margin-left: 0.5in;"><font color= "black" face="Times New Roman" size="2"><span style="font-size: 10pt; color: black;">Thanks.</span></font></div></div></div> <div style="margin-left: 0.5in ; text-align: center;" align="center"> <font face="Times New Roman" size="3"><span style="font-size: 12pt;"> <hr align="center" size="1" width="100%"> </span></font></div> <div style="margin -left: 0.5in;"><font face="Times New Roman" size="3"><span style="font-size: 12pt;"> Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls. <a href="http://us.rd.yahoo.com/mail_us/taglines /postman7/*http:/us.rd.yahoo.com/evt=39666/*http:/beta.messenger.yahoo.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> Great rates starting at 1¢/min.</a></span></font></div></div> <div style= "margin-right: 0px;" align="left"><font face="Tahoma" size="2"><font color=" #0000ff"> <hr> </font></font><font face="Tahoma" size="2"><font color="#0000ff "> This electronic message transmission is a PRIVATE communication which contains information <br>which may be confidential or privileged. The information is intended to be for the use of the individual <br>or entity named above. If you are not the intended recipient, please be aware that any disclosure, <br>copying, distribution or use of the contents of this information is prohibited. Please notify the sender <br>of the delivery error by replying to this message, or notify us by telephone (877-633-2436, ext. 0), <br>and then delete it from your system. </font></font> <div></div></div></blockquote><br></span></div><div style= "direction: ltr;"><span class="ad"><p> </p><hr size="1">How low will we go? Check out Yahoo! Messenger's low <a href ="http://us.rd.yahoo.com/mail_us/taglines/postman8/*http://us.rd.yahoo.com/evt =39663/*http://voice.yahoo.com" target="_blank" onclick="return top.js .OpenExtLink(window,event,this)"> PC-to-Phone call rates. </a><p></p></span></div></blockquote></div><br><br clear="all"><br>-- <br>Jared Still<br>Certifiable Oracle DBA and Part Time Perl Evangelist<br>
|
|