   |  | | Dynamic SQL | Dynamic SQL 2006-04-06 - By Freeman, Donald
Why don't you post the error you are getting.
-- --Original Message-- -- From: oracle-l-bounce@(protected) [mailto:oracle-l-bounce@(protected)] On Behalf Of ora_forum Sent: Thursday, April 06, 2006 11: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>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD><TITLE>Message</TITLE> <META http-equiv=Content-Type content="text/html; charset=iso-8859-1"> <META content="MSHTML 6.00.2800.1528" name=GENERATOR></HEAD> <BODY> <DIV><SPAN class=550570817-06042006><FONT face=Arial color=#0000ff size=2>Why don't you post the error you are getting. </FONT></SPAN></DIV> <BLOCKQUOTE style="MARGIN-RIGHT: 0px"> <DIV></DIV> <DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left><FONT face=Tahoma size=2>-- --Original Message-- --<BR><B>From:</B> oracle-l-bounce@(protected) [mailto:oracle-l-bounce@(protected)] <B>On Behalf Of </B>ora_forum<BR><B>Sent:</B> Thursday, April 06, 2006 11:53 AM<BR><B>To:</B> oracle-l@(protected)<BR><B>Subject:</B> Dynamic SQL <BR><BR></FONT></DIV> <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</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></DIV> <DIV><FONT size=2><FONT color=#000000></FONT></FONT> </DIV> <DIV><FONT size=2><FONT color=#000000>Thanks.</FONT></DIV></FONT></FONT><FONT size=2></FONT></DIV> <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">Great rates starting at 1¢/min.</A></BLOCKQUOTE></BODY></HTML>
|
|
 |