set serverout on declare n number := 1000000. ret varchar2(100). begin ret := trunc(n/3600) || 小时 || to_char(to_date(mod(n,3600), sssss ), fmmi"分 "ss"秒" ) . dbms_output.put_line(ret). end.
137. 如何查询做比较大的排序的进程?
0select b.tablespace, b.segfile#, b.segblk#, b.blocks, a.sid, a.serial#, a.username, a.osuser, a.status from v$session a,v$sort_usage b where a.saddr = b.session_addr order by b.tablespace, b.segfile#, b.segblk#, b.blocks .
138. 如何查询做比较大的排序的进程的sql语句?
0select /* ordered */ sql_text from v$sqltext a where a.hash_value = ( 0select sql_hash_value from v$session b where b.sid = &.sid and b.serial# = &.serial) order by piece asc .
139. 如何查找重复记录?
0select * from table_name where rowid!=(0select max(rowid) from table_name d where table_name.col1=d.col1 and table_name.col2=d.col2).
140. 如何删除重复记录?
0delete from table_name where rowid!=(0select max(rowid) from table_name d where table_name.col1=d.col1 and table_name.col2=d.col2).
141. 如何快速编译所有视图?
sql >spool view1.sql sql >0select ‘alter view ‘||tname||’ compile.’ from tab. sql >spool off 然后执行view1.sql即可。 sql >@view1.sql.
create or replace procedure testccb(i in number) as begin dbms_output.put_line( 输入参数是 ||to_char(i)). end.
sql>wrap iname=a.sql. pl/sql wrapper: release 8.1.7.0.0 - production on tue nov 27 22:26:48 2001 copyright (c) oracle corporation 1993, 2000. all rights reserved. processing aa.sql to aa.plb 运行aa.plb sql> @aa.plb .
145. 如何监控事例的等待?
0select event,sum(decode(wait_time,0,0,1)) "prev", sum(decode(wait_time,0,1,0)) "curr",count(*) "tot" from v$session_wait group by event order by 4.
146. 如何回滚段的争用情况?
0select name, waits, gets, waits/gets "ratio" from v$rollstat c, v$rollname d where c.usn = d.usn.
147. 如何监控表空间的 i/o 比例?
0select b.tablespace_name name,b.file_name "file",a.phyrds pyr, a.phyblkrd pbr,a.phywrts pyw, a.phyblkwrt pbw from v$filestat a, dba_data_files b where a.file# = b.file_id order by b.tablespace_name.
148. 如何监控文件系统的 i/o 比例?
0select substr(c.file#,1,2) "#", substr(c.name,1,30) "name", c.status, c.bytes, d.phyrds, d.phywrts from v$datafile c, v$filestat d where c.file# = d.file#.
149. 如何在某个用户下找所有的索引?
0select user_indexes.table_name, user_indexes.index_name,uniqueness, column_name from user_ind_columns, user_indexes where user_ind_columns.index_name = user_indexes.index_name and user_ind_columns.table_name = user_indexes.table_name order by user_indexes.table_type, user_indexes.table_name, user_indexes.index_name, column_position.