.ora-code.com

Links
Home
Oracle DBA Forum
Frequent Oracle Errors
TNS:could not resolve the connect identifier specified
Backtrace message unwound by exceptions
invalid identifier
PL/SQL compilation error
internal error
missing expression
table or view does not exist
end-of-file on communication channel
TNS:listener unknown in connect descriptor
insufficient privileges
PL/SQL: numeric or value error string
TNS:protocol adapter error
ORACLE not available
target host or object does not exist
invalid number
unable to allocate string bytes of shared memory
resource busy and acquire with NOWAIT specified
error occurred at recursive SQL level string
ORACLE initialization or shutdown in progress
archiver error. Connect internal only, until freed
snapshot too old
unable to extend temp segment by string in tablespace
Credential retrieval failed
missing or invalid option
invalid username/password; logon denied
unable to create INITIAL extent for segment
out of process memory when trying to allocate string bytes
shared memory realm does not exist
cannot insert NULL
TNS:unable to connect to destination
remote database not found'>ora-02019
exception encountered: core dump
inconsistent datatypes
no data found
TNS:operation timed out
PL/SQL: could not find program
existing state of packages has been discarded
maximum number of processes exceeded
error signaled in parallel query server
ORACLE instance terminated. Disconnection forced
TNS:packet writer failure
see ORA-12699
missing right parenthesis
name is already used by an existing object
cannot identify/lock data file
invalid file operation
quoted string not properly terminated
Dynamic SQL

Dynamic SQL

2006-04-06       - By ora_forum
Reply:     1     2     3     4     5     6     7     8     9     10  

Thank you all for help!
 
 Greg

Jared Still <jkstill@(protected)> wrote:
 This is probably close to what you are trying to do:

create table audittrail
as
select created dated, object_name details, owner moduser, 8 action
from
dba_objects
where rownum <= 10
/



DECLARE
  m_dated DATE;
  m_count NUMBER(10);
  m_details varchar2(4000);
  m_moduser varchar2(250);
  type weakCurTyp is ref cursor;
  m_cursor weakCurTyp;
  m_rowid rowid;
BEGIN
  FOR r IN (SELECT owner FROM all_tables WHERE table_name=upper('Audittrail')
order by owner)
  LOOP
     open m_cursor for 'select Dated, Details, Moduser from ' || r.owner || '
.audittrail where action = 8';
     LOOP
        fetch m_cursor into m_dated,m_details,m_moduser;
        exit when m_cursor%notfound;
        dbms_output.put_line ( m_dated || ':' || m_details || ':' || m_moduser
);
     END LOOP;
  END LOOP;
END;
/

Some serious study of the PL/SQL, PL/SQL supplied packages and SQL manuals is
suggested


 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.  





--
Jared Still
Certifiable Oracle DBA and Part Time Perl Evangelist


   
-- ---- ---- ---- ---- ---- -----
New Yahoo! Messenger with Voice. Call regular phones from your PC and save big.
<div>Thank you all for help!</div>  <div>&nbsp;</div>  <div>Greg<BR><BR><B><I
>Jared Still &lt;jkstill@(protected)&gt;</I></B> wrote:</div>  <BLOCKQUOTE class
=replbq style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px
solid">This is probably close to what you are trying to do:<BR><BR>create table
audittrail<BR>as<BR>select created dated, object_name details, owner moduser, 8
action<BR>from<BR>dba_objects<BR>where rownum &lt;= 10<BR>/<BR><BR><BR><BR
>DECLARE<BR>&nbsp;&nbsp; m_dated DATE;<BR>&nbsp;&nbsp; m_count NUMBER(10);<BR>
&nbsp;&nbsp; m_details varchar2(4000);<BR>&nbsp;&nbsp; m_moduser varchar2(250);
<BR>&nbsp;&nbsp; type weakCurTyp is ref cursor;<BR>&nbsp;&nbsp; m_cursor
weakCurTyp;<BR>&nbsp;&nbsp; m_rowid rowid;<BR>BEGIN<BR>&nbsp;&nbsp; FOR r IN
(SELECT owner FROM all_tables WHERE table_name=upper('Audittrail') order by
owner) <BR>&nbsp;&nbsp; LOOP<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; open m_cursor
for 'select Dated, Details, Moduser from ' || r.owner ||
'.audittrail where action = 8';<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LOOP<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fetch m_cursor into m_dated,m
_details,m_moduser;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit
when m_cursor%notfound; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
dbms_output.put_line ( m_dated || ':' || m_details || ':' || m_moduser);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; END LOOP;<BR>&nbsp;&nbsp; END LOOP;<BR>END;<BR>/
<BR><BR>Some serious study of the PL/SQL, PL/SQL supplied packages and SQL
manuals is suggested <BR><BR><BR>  <DIV><SPAN class=gmail_quote>On 4/6/06, <B
class=gmail_sendername>ora_forum</B> &lt;<A href="mailto:ora_forum@(protected)"
>ora_forum@(protected)</A>&gt; wrote:</SPAN>  <BLOCKQUOTE class=gmail_quote style=
"PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px
solid">  <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>&nbsp;</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>&lt;&gt;</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>&lt;&gt;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>&nbsp;</DIV>  <DIV><FONT size=2><FONT color=#000000>Thanks.</FONT></FONT><
/DIV></DIV>  <DIV style="DIRECTION: ltr"><SPAN
class=ad><FONT size=2></FONT>  <div></div>  <HR SIZE=1>  Talk is cheap. Use
Yahoo! Messenger to make PC-to-Phone calls. <A onclick="return top.js
.OpenExtLink(window,event,this)" href="http://us.rd.yahoo.com/mail_us/taglines
/postman7/*http://us.rd.yahoo.com/evt=39666/*http://beta.messenger.yahoo.com"
target=_blank>Great rates starting at 1?/min. </A>  <div></div></SPAN></DIV><
/BLOCKQUOTE></DIV><BR><BR clear=all><BR>-- <BR>Jared Still<BR>Certifiable Oracle
DBA and Part Time Perl Evangelist<BR></BLOCKQUOTE><BR><p>
    <hr size=1>New Yahoo! Messenger with Voice. <a href="http://us.rd.yahoo.com
/mail_us/taglines/postman5/*http://us.rd.yahoo.com/evt=39666/*http://beta
.messenger.yahoo.com">Call regular phones from your PC</a> and save big.