欢迎来到福编程网,本站提供各种互联网专业知识!
您的位置:网站首页 > 数据库 > MsSql

非常好用的sql语句(日常整理)

发布时间:2015-09-12 作者:baiying 来源:转载
本文给大家分享几个比较好用的sql语句,在数据库中经常会用到,需要的朋友可以参考下本篇文章。

1. /* 得到trace文件路径和名称 */

代码
  1. SELECT d.VALUE
  2. || '/'
  3. || LOWER (RTRIM (i.INSTANCE, CHR (0)))
  4. || '_ora_'
  5. || p.spid
  6. || '.trc' trace_file_name
  7. FROM (SELECT p.spid
  8. FROM v$mystat m, v$session s, v$process p
  9. WHERE m.statistic# = 1 AND s.SID = m.SID AND p.addr = s.paddr) p,
  10. (SELECT t.INSTANCE
  11. FROM v$thread t, v$parameter v
  12. WHERE v.NAME = 'thread'
  13. AND (v.VALUE = 0 OR t.thread# = TO_NUMBER (v.VALUE))) i,
  14. (SELECT VALUE
  15. FROM v$parameter
  16. WHERE NAME = 'user_dump_dest') d

2./* 显示产生锁定的sql语句 */

代码
  1. select /*+ NO_MERGE(a) NO_MERGE(b) NO_MERGE(c) */ a.username, a.machine, a.sid,a.serial#, a.last_call_et "Seconds", b.id1, c.sql_text "SQL" from v$session a, v$lock b,v$sqltext c where a.username is not null and a.lockwait = b.kaddr and c.hash_value =a.sql_hash_value;

3./* 查看oracle隐藏参数 */

代码
  1. select name,
  2. value,
  3. decode(isdefault, 'TRUE', 'Y', 'N') as "Default",
  4. decode(ISEM, 'TRUE', 'Y', 'N') as SesMod,
  5. decode(ISYM, 'IMMEDIATE', 'I', 'DEFERRED', 'D', 'FALSE', 'N') as SysMod,
  6. decode(IMOD, 'MODIFIED', 'U', 'SYS_MODIFIED', 'S', 'N') as Modified,
  7. decode(IADJ, 'TRUE', 'Y', 'N') as Adjusted,
  8. description
  9. from ( --GV$SYSTEM_PARAMETER
  10. select x.inst_id as instance,
  11. x.indx + 1,
  12. ksppinm as name,
  13. ksppity,
  14. ksppstvl as value,
  15. ksppstdf as isdefault,
  16. decode(bitand(ksppiflg / 256, 1), 1, 'TRUE', 'FALSE') as ISEM,
  17. decode(bitand(ksppiflg / 65536, 3),
  18. 1,
  19. 'IMMEDIATE',
  20. 2,
  21. 'DEFERRED',
  22. 'FALSE') as ISYM,
  23. decode(bitand(ksppstvf, 7), 1, 'MODIFIED', 'FALSE') as IMOD,
  24. decode(bitand(ksppstvf, 2), 2, 'TRUE', 'FALSE') as IADJ,
  25. ksppdesc as description
  26. from x$ksppi x, x$ksppsv y
  27. where x.indx = y.indx
  28. and substr(ksppinm, 1, 1) = '_'
  29. and x.inst_id = USERENV('Instance'))
  30. order by name;

4./* 根据系统中oracle的pid来查看sql */

代码
  1. select /*+ ORDERED */ sql_text from v$sqltext a where (a.hash_value,a.address) IN (select decode (sql_hash_value,0,prev_hash_value,sql_hash_value),decode (sql_hash_value,0,prev_sql_addr,sql_address) from v$session b where b.paddr =( select addr from v$process c where c.spid = '&pid')) order by piece ASC;

以上就是本文给大家分享几个比较好用sql语句,希望大家喜欢。

相关推荐

返回顶部