   |  | | Dynamic SQL | Dynamic SQL 2006-04-06 - By Reidy, Ron
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.
<html>
<head> <meta http-equiv=Content-Type content="text/html; charset=iso-8859-1"> <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:blue; text-decoration:underline;} p {margin-right:0in; margin-left:0in; font-size:12.0pt; font-family:"Times New Roman";} span.EmailStyle18 {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=blue>
<div class=Section1>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size: 10.0pt;font-family:Arial;color:navy'>You cannot test for NULL with the ‘=, <>, !=’, etc. operators. The correct syntax is “… IS NOT NULL”.</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'>Also, what is not working?</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'> </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>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> oracle-l@(protected)<br> <b><span style='font-weight:bold'>Subject:</span></b> Dynamic SQL </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>
<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman" ><span style='font-size:12.0pt'>Hi All:</span></font></p>
</div>
<div>
<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman" ><span style='font-size:12.0pt'>Could you tell me what I'm doing wrong?</span></font>< /p>
</div>
<div>
<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman" ><span style='font-size:12.0pt'>I need pass different schema owner in SQL, also in some tables there are multiple records will be returned. </span></font></p>
</div>
<div>
<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman" ><span style='font-size:12.0pt'> </span></font></p>
</div>
<div>
<div>
<p class=MsoNormal style='margin-left:.5in'><font size=2 color=blue face="Times New Roman"><span style='font-size:10.0pt;color:blue'>DECLARE<br> </span></font><font size=2 color=black><span style='font-size:10.0pt; color:black'>m_dated </span></font><font size=2 color=blue><span style='font-size:10.0pt;color:blue'>DATE</span></font><font size=2 color=black> <span style='font-size:10.0pt;color:black'>;<br> m_count </span></font><font size=2 color=blue><span style='font-size:10.0pt; color:blue'>NUMBER</span></font><font size=2 color=black><span style='font-size:10.0pt;color:black'>(10);<br> m_details </span></font><font size=2 color=blue><span style='font-size:10.0pt; color:blue'>varchar2</span></font><font size=2 color=black><span style='font-size:10.0pt;color:black'>(4000);<br> m_moduser </span></font><font size=2 color=blue><span style='font-size:10.0pt; color:blue'>varchar2</span></font><font size=2 color=black><span style='font-size:10.0pt;color:black'>(250);<br> </span></font><font size=2 color=blue><span style='font-size:10.0pt;color:blue' >BEGIN<br> FOR</span></font><font size=2 color=black><span style='font-size:10.0pt; color:black'> r </span></font><font size=2 color=blue><span style='font-size: 10.0pt;color:blue'>IN</span></font><font size=2 color=black><span style='font-size:10.0pt;color:black'> (</span></font><font size=2 color=blue> <span style='font-size:10.0pt;color:blue'>SELECT</span></font><font size=2 color=black><span style='font-size:10.0pt;color:black'> owner </span></font> <font size=2 color=blue><span style='font-size:10.0pt;color:blue'>FROM</span></font> <font size=2 color=black><span style='font-size:10.0pt;color:black'> all_tables < /span></font><font size=2 color=blue><span style='font-size:10.0pt;color:blue'>WHERE</span></font> <font size=2 color=black><span style='font-size:10.0pt;color:black'> table_name=< /span></font><font size=2 color=blue><span style='font-size:10.0pt;color:blue'>upper</span></font> <font size=2 color=black><span style='font-size:10.0pt;color:black'>(</span></font> <font size=2 color=red><span style='font-size:10.0pt;color:red'>'Audittrail'</span>< /font><font size=2 color=black><span style='font-size:10.0pt;color:black'>) </span></font> <font size=2 color=blue><span style='font-size:10.0pt;color:blue'>order</span></font> <font size=2 color=black><span style='font-size:10.0pt;color:black'> </span></font> <font size=2 color=blue><span style='font-size:10.0pt;color:blue'>by</span></font> <font size=2 color=black><span style='font-size:10.0pt;color:black'> owner)<br> </span></font><font size=2 color=blue><span style='font-size:10.0pt;color:blue' >LOOP<br> FOR</span></font><font size=2 color=black><span style='font-size:10.0pt; color:black'> n </span></font><font size=2 color=blue><span style='font-size: 10.0pt;color:blue'>IN</span></font><font size=2 color=black><span style='font-size:10.0pt;color:black'> (</span></font><font size=2 color=blue> <span style='font-size:10.0pt;color:blue'>SELECT</span></font><font size=2 color=black><span style='font-size:10.0pt;color:black'> </span></font><font size=2 color=blue><span style='font-size:10.0pt;color:blue'>ROWID</span></font> <font size=2 color=black><span style='font-size:10.0pt;color:black'> </span></font> <font size=2 color=blue><span style='font-size:10.0pt;color:blue'>FROM</span></font> <font size=2 color=black><span style='font-size:10.0pt;color:black'> r.Audittrail < /span></font><font size=2 color=blue><span style='font-size:10.0pt;color:blue'>where</span></font> <font size=2 color=black><span style='font-size:10.0pt;color:black'> action=8)<br> </span></font><font size=2 color=blue><span style='font-size:10.0pt;color:blue' >LOOP<br> IF</span></font><font size=2 color=black><span style='font-size:10.0pt; color:black'> </span></font><font size=2 color=blue><span style='font-size: 10.0pt;color:blue'>ROWID</span></font><font size=2 color=black><span style='font-size:10.0pt;color:black'><></span></font><font size=2 color=red><span style='font-size:10.0pt;color:red'>'NULL'</span></font><font size=2 color=black><span style='font-size:10.0pt;color:black'> </span></font> <font size=2 color=blue><span style='font-size:10.0pt;color:blue'>or</span></font> <font size=2 color=black><span style='font-size:10.0pt;color:black'> </span></font> <font size=2 color=blue><span style='font-size:10.0pt;color:blue'>ROWID</span></font> <font size=2 color=black><span style='font-size:10.0pt;color:black'><>0 </span> </font><font size=2 color=blue><span style='font-size:10.0pt;color:blue'>THEN<br> EXECUTE</span></font><font size=2 color=black><span style='font-size:10.0pt; color:black'> </span></font><font size=2 color=blue><span style='font-size: 10.0pt;color:blue'>IMMEDIATE</span></font><font size=2 color=black><span style='font-size:10.0pt;color:black'> </span></font><font size=2 color=red><span style='font-size:10.0pt;color:red'>'SELECT Dated, Details, Moduser FROM '</span ></font><font size=2 color=black><span style='font-size:10.0pt;color:black'> || R.owner ||< /span></font><font size=2 color=red><span style='font-size:10.0pt;color:red'>'.Audittrail where rowid='</span></font><font size=2 color=black><span style='font-size:10.0pt; color:black'>||n||</span></font><font size=2 color=red><span style='font-size: 10.0pt;color:red'>'.rowid'</span></font><font size=2 color=black><span style='font-size:10.0pt;color:black'> </span></font><font size=2 color=blue> <span style='font-size:10.0pt;color:blue'>into</span></font><font size=2 color=black> <span style='font-size:10.0pt;color:black'> m_dated, m_details, m_moduser; <br> dbms_output.put_line ( m_dated,m_details, m_moduser);<br> </span></font><font size=2 color=blue><span style='font-size:10.0pt;color:blue' >ELSE<br> NULL</span></font><font size=2 color=black><span style='font-size:10.0pt; color:black'>;<br> </span></font><font size=2 color=blue><span style='font-size:10.0pt;color:blue' >END</span></font><font size=2 color=black><span style='font-size:10.0pt;color:black'> </span></font> <font size=2 color=blue><span style='font-size:10.0pt;color:blue'>IF</span></font> <font size=2 color=black><span style='font-size:10.0pt;color:black'>;<br> </span></font><font size=2 color=blue><span style='font-size:10.0pt;color:blue' >END</span></font><font size=2 color=black><span style='font-size:10.0pt;color:black'> </span></font> <font size=2 color=blue><span style='font-size:10.0pt;color:blue'>LOOP</span></font> <font size=2 color=black><span style='font-size:10.0pt;color:black'>;<br> </span></font><font size=2 color=blue><span style='font-size:10.0pt;color:blue' >END</span></font><font size=2 color=black><span style='font-size:10.0pt;color:black'> </span></font> <font size=2 color=blue><span style='font-size:10.0pt;color:blue'>LOOP</span></font> <font size=2 color=black><span style='font-size:10.0pt;color:black'>;<br> </span></font><font size=2 color=blue><span style='font-size:10.0pt;color:blue' >END</span></font><font size=2 color=black><span style='font-size:10.0pt;color:black'>;<br> /</span></font></p>
</div>
<div>
<p class=MsoNormal style='margin-left:.5in'><font size=2 color=blue face="Times New Roman"><span style='font-size:10.0pt;color:blue'> </span>< /font></p>
</div>
<div>
<p class=MsoNormal style='margin-left:.5in'><font size=2 color=black face="Times New Roman"><span style='font-size:10.0pt;color:black'>Thanks.</span ></font></p>
</div>
</div>
<div class=MsoNormal align=center style='margin-left:.5in;text-align:center'> <font size=3 face="Times New Roman"><span style='font-size:12.0pt'>
<hr size=1 width="100%" align=center>
</span></font></div>
<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman" ><span style='font-size:12.0pt'>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">Great rates starting at 1¢/min.</a></span></font></p>
</div>
</body>
<P align=left style="MARGIN-RIGHT: 0px"><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></P></html>
|
|
 |