Dynamic SQL 2006-04-06 - By Jared Still
Sure, but you have to show us how it breaks.
On 4/6/06, ora_forum <ora_forum@(protected)> wrote: > > 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> > >
-- Jared Still Certifiable Oracle DBA and Part Time Perl Evangelist
Sure, but you have to show us how it breaks.<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>Hi All:</div> <div>Could you tell me what I 'm doing wrong?</div> <div>I need pass different schema owner in SQL, also in some tables there are multiple records will be returned. </div> <div> </div> <div><font color="#0000ff" size="2"><font color="#0000ff" size="2"> <div>DECLARE</div></font><font size="2"><br><font color="#000000">m _dated </font></font><font color="#0000ff" size="2">DATE</font><font color=" #000000" size="2"> ;<br>m_count </font><font color="#0000ff" size="2">NUMBER</font><font color=" #000000" size="2">(10);<br>m_details </font><font color="#0000ff" size="2" >varchar2</font><font color="#000000" size="2">(4000);<br>m_moduser </font> <font color="#0000ff" size="2">varchar2</font><font color="#000000" size="2"> (250);<br></font><font color="#0000ff" size="2">BEGIN</font><font size="2"><br>< /font><font color="#0000ff" size="2">FOR</font><font color="#000000" size="2"> r </font><font color="#0000ff" size="2">IN</font><font color="#000000" size="2 "> (</font><font color="#0000ff" size="2">SELECT</font><font color="#000000" size="2"> owner </font><font color="#0000ff" size="2">FROM</font><font color="#000000" size="2"> all_tables </font><font color="#0000ff" size="2">WHERE</font><font color="#000000" size="2"> table_name=</font><font color="#0000ff" size="2"> upper</font><font color="#000000" size="2">(</font><font color="#ff0000" size= "2">'Audittrail'</font><font color="#000000" size="2">) </font><font color=" #0000ff" size="2">order</font><font color="#000000" size="2"> </font> <font color="#0000ff" size="2">by</font><font color="#000000" size="2"> owner) <br></font><font color="#0000ff" size="2">LOOP</font><font size="2"><br></font> <font color="#0000ff" size="2">FOR</font><font color="#000000" size="2"> n </font><font color="#0000ff" size="2">IN</font><font color="#000000" size="2 "> (</font><font color="#0000ff" size="2">SELECT</font><font color="#000000" size="2"> </font><font color="#0000ff" size="2">ROWID</font><font color=" #000000" size="2"> </font><font color="#0000ff" size="2">FROM</font><font color="#000000" size="2 "> r.Audittrail </font><font color="#0000ff" size="2">where</font><font color=" #000000" size="2"> action=8)<br></font><font color="#0000ff" size="2"> LOOP</font><font size="2"><br></font><font color="#0000ff" size="2">IF</font> <font color="#000000" size="2"> </font><font color="#0000ff" size="2">ROWID< /font><font color="#000000" size="2"><></font><font color="#ff0000" size= "2"> 'NULL'</font><font color="#000000" size="2"> </font><font color="#0000ff" size= "2">or</font><font color="#000000" size="2"> </font><font color="#0000ff" size= "2">ROWID</font><font color="#000000" size="2"><>0 </font> <font color="#0000ff" size="2">THEN</font><font size="2"><br></font><font color ="#0000ff" size="2">EXECUTE</font><font color="#000000" size="2"> </font><font color="#0000ff" size="2">IMMEDIATE</font><font color="#000000" size="2"> </font><font color="#ff0000" size="2">'SELECT Dated, Details, Moduser FROM '< /font><font color="#000000" size="2"> || R.owner ||</font><font color="#ff0000" size="2">'.Audittrail where rowid='</font><font color="#000000" size="2"> ||n||</font><font color="#ff0000" size="2">'.rowid'</font><font color="#000000" size="2"> </font><font color="#0000ff" size="2">into</font><font color="#000000 " size="2"> m_dated, m_details, m_moduser; <br>dbms_output.put_line ( m_dated,m _details, m_moduser); <br></font><font color="#0000ff" size="2">ELSE</font><font size="2"><br></font> <font color="#0000ff" size="2">NULL</font><font color="#000000" size="2">;<br>< /font><font color="#0000ff" size="2">END</font><font color="#000000" size="2"> </font><font color="#0000ff" size="2">IF</font><font color="#000000" size="2"> ;<br></font><font color="#0000ff" size="2">END</font><font color="#000000" size= "2"> </font><font color="#0000ff" size="2">LOOP</font><font color="#000000" size ="2"> ;<br></font><font color="#0000ff" size="2">END</font><font color="#000000" size ="2"> </font><font color="#0000ff" size="2">LOOP</font><font color="#000000" size="2">;<br></font><font color="#0000ff" size="2">END</font><font size="2"> <font color="#000000">;<br>/</font></font></font></div> <div><font size="2"> <font color="#000000"></font></font> </div> <div><font size="2"><font color="#000000">Thanks.</font></font></div></div><div style="direction: ltr;"> <span class="ad"><font size="2"></font><p> </p><hr size="1">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><p></p></span></div></blockquote></div><br><br clear="all"><br>-- <br>Jared Still<br>Certifiable Oracle DBA and Part Time Perl Evangelist<br>
|
|