I have one small problem. Below is my query which is running on the sql prompt:
*select username||'('||sid||','||serial#||') ospid = ' || process ||' program = ' || program username,to_char(LOGON_TIME,' Day HH24:MI') logon_time,to_char(sysdate,' Day HH24:MI') current_time,sql_address, LAST_CALL_ET from **v$session@(protected)* <v$session@(protected)> *where status = 'ACTIVE' and rawtohex(sql_address) <> '00' and username is not null order by last_call_et;*
* select max(decode(piece,0,sql_text,null)) ||max(decode(piece,1,sql_text,null)) ||max(decode(piece,2,sql_text,null)) ||max(decode(piece,3,sql_text,null)) sql_text from ** v$sqltext_with_newlines@(protected)*<v$sqltext_with_newlines@(protected)> *where address = x.sql_address and piece < 4;*
but when I am using the same sql in the PL/SQL block as below:
*create or replace procedure showsql as -- x number; cursor c1 is select username||'('||sid||','||serial#|| ') ospid = ' || process || ' program = ' || program username, to_char(LOGON_TIME,' Day HH24:MI') logon_time, to_char(sysdate,' Day HH24:MI') current_time, sql_address, LAST_CALL_ET from v$session@(protected) where status = 'ACTIVE' and rawtohex(sql_address) <> '00' and username is not null order by last_call_et; cursor c2 is select max(decode(piece,0,sql_text,null)) || max(decode(piece,1,sql_text,null)) || max(decode(piece,2,sql_text,null)) || max(decode(piece,3,sql_text,null)) sql_text from v$sqltext_with_newlines@(protected) where address = x.sql_address and piece < 4; begin for x in c1 loop for y in c2 loop if ( y.sql_text not like '%listener.get_cmd%' and y.sql_text not like '%RAWTOHEX(SQL_ADDRESS)%') then dbms_output.put_line( '-- ---- ---- ---- --' ); dbms_output.put_line( x.username ); dbms_output.put_line( x.logon_time || ' ' || x.current_time|| ' last et = ' || x.LAST_CALL_ET); dbms_output.put_line( substr( y.sql_text, 1, 250 ) ); end if; end loop; end loop; end; /* Its throwing the following error: *
Warning: Procedure created with compilation errors.
SQL> sho err Errors for PROCEDURE SHOWSQL:
LINE/COL ERROR -- ----- -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -- 4/2 PL/SQL: ORA-04052 (See ORA-04052.ora-code.com): error occurred when looking up remote object SYS.V_$SESSION@(protected) ORA-02030 (See ORA-02030.ora-code.com): can only select from fixed tables/views
4/2 PL/SQL: SQL Statement ignored 15/2 PL/SQL: SQL Statement ignored 21/37 PL/SQL: ORA-00904 (See ORA-00904.ora-code.com): "X"."SQL_ADDRESS": invalid identifier 26/13 PL/SQL: Statement ignored 26/18 PLS-00364: loop index variable 'Y' use is invalid SQL>
<div>hi all,</div> <div> </div> <div>I have one small problem. Below is my query which is running on the sql prompt:</div> <div> </div> <div><strong>select username||'('||sid||','||serial#||') ospid = ' || process ||' program = ' || program username,to_char(LOGON_TIME,' Day HH24:MI') logon_time,to_char(sysdate,' Day HH24:MI') current_time,sql_address, LAST_CALL _ET from </strong><a href="mailto:v$session@(protected)"><strong>v$session@(protected) _cochin</strong></a> <strong>where status = 'ACTIVE' and rawtohex(sql _address) <> '00' and username is not null order by last_call_et;< /strong> </div> <div> </div> <div><strong> select max(decode(piece,0,sql_text,null)) ||max(decode(piece ,1,sql_text,null)) ||max(decode(piece,2,sql_text,null)) ||max(decode(piece,3,sql _text,null)) sql_text from </strong><a href="mailto:v$sqltext_with _newlines@(protected)"> <strong>v$sqltext_with_newlines@(protected)</strong></a> <strong>where address = x.sql_address and piece < 4;</strong><br> </div> <div> </div> <div>but when I am using the same sql in the PL/SQL block as below: </div> <div> </div> <div><strong>create or replace procedure showsql as<br>-- x number;<br> cursor c1 is <br> select username||'('||sid| |','||serial#||<br> ') ospid = ' || process ||<br> ' program = ' || program username, <br> to _char(LOGON_TIME,' Day HH24:MI') logon_time,<br> to_char(sysdate,' Day HH24:MI') current_time,<br> sql_address, LAST_CALL_ET<br> from <a href="mailto:v$session@(protected)"> v$session@(protected)</a><br> where status = 'ACTIVE'<br> and rawtohex(sql_address) <> '00'<br> and username is not null order by last_call_et;<br> cursor c2 is<br> select max(decode(piece,0,sql_text,null)) || <br> max(decode(piece,1,sql_text,null)) ||<br> max(decode(piece,2,sql_text,null)) ||<br> max (decode(piece,3,sql_text,null))<br> sql_text <br> from <a href="mailto:v$sqltext _with_newlines@(protected)">v$sqltext_with_newlines@(protected)</a><br>  ; where address = x.sql_address<br> and piece < 4; <br>begin<br> for x in c1 loop<br> for y in c2 loop<br>   ; if ( y.sql_text not like '%listener.get_cmd%' and<br> y.sql_text not like '%RAWTOHEX(SQL_ADDRESS)%')<br>  ; then<br> dbms_output.put_line( '-- ---- ---- ---- --' ); <br> dbms_output.put_line( x.username );<br> dbms _output.put_line( x.logon_time || ' ' ||<br> x.current_time||<br>   ; ' last et = ' || <br> x.LAST _CALL_ET);<br> dbms_output.put_line(<br> substr( y.sql_text, 1, 250 ) );<br> end if;<br> end loop;<br> end loop; <br>end;<br>/</strong></div> <div>Its throwing the following error: </div> <div><strong> <p>Warning: Procedure created with compilation errors.</p> <p>SQL> sho err<br>Errors for PROCEDURE SHOWSQL:</p> <p>LINE/COL ERROR<br>-- ----- -- ---- ---- ---- ---- ---- ---- ---- ---- ------ -- ---- ---- ---<br>4/2 PL/SQL: ORA-04052 (See ORA-04052.ora-code.com): error occurred when looking up remote object<br> <a href="mailto:SYS.V_$SESSION@(protected)"> SYS.V_$SESSION@(protected)</a><br> ORA-02030 (See ORA-02030.ora-code.com): can only select from fixed tables/views</p> <p>4/2 PL/SQL: SQL Statement ignored<br>15/2  ; PL/SQL: SQL Statement ignored<br>21/37 PL /SQL: ORA-00904 (See ORA-00904.ora-code.com): "X"."SQL_ADDRESS": invalid identifier<br>26 /13 PL/SQL: Statement ignored<br>26/18 PLS -00364: loop index variable 'Y' use is invalid <br>SQL></p> <p></p></strong>Any idea???????<br clear="all"><br>-- <br>Thanks & Regards, <br>T. Onkar Nath<br>OneAPPS Enterprise Technology Pvt. Ltd.<br> <a href="mailto:to_onkar@(protected)">to_onkar@(protected)< /a><br> <a href="mailto:onkarnath.tiwary @(protected)"> onkarnath.tiwary@(protected)</a><br> </div>