码迷,mamicode.com
首页 > 数据库 > 详细

Oracle常用SQL语句

时间:2020-04-07 17:05:10      阅读:84      评论:0      收藏:0      [点我收藏+]

标签:sel   mod   create   start   bms   ||   for   where   serial   

递归查询部门

    select * from table start with id= ? connect by prior id = parent_id;//查询id的子部门(包 括id自身)
    select * from table start with id= ? connect by prior parent_id= id;//查询id的父部门(包括id自身)

copy表

create table tableName as select * from tableName;//copy表

设置百分点

concat(to_char(count(distinct l.person_id) /
                              count(l.person_id) * 100,
                              ‘990.99‘),
                      ‘%‘) baifen

for循环执行SQL语句

declare
    begin
    for i in 1..100
    loop
    dbms_output.put_line(‘sql语句‘||i);
    end loop;
    end;

oracle查询已锁住的表

SELECT
	OBJECT_NAME,
	SESSION_ID SID,
	MACHINE,
	VS.MODULE,
	‘ALTER SYSTEM KILL SESSION ‘‘‘ || SESSION_ID || ‘, ‘ || SERIAL#|| ‘‘‘; ‘ KILL_SESSION,
	VS.STATUS,
	VS.ACTION,
	SERIAL#,
	ORACLE_USERNAME,
	OS_USER_NAME
FROM
	V$LOCKED_OBJECT VO,
	V$SESSION VS,
	ALL_OBJECTS AO
WHERE
	VO.SESSION_ID = VS.SID
	AND AO.OBJECT_ID = VO.OBJECT_ID
	AND NVL(VS.ACTION, ‘ ‘) <> ‘Service Management ‘
ORDER BY
	OBJECT_NAME,
	MACHINE,
	VS.MODULE;

其中KILL_SESSION为对应解锁的SQL,需要具有权限才能执行

Oracle常用SQL语句

标签:sel   mod   create   start   bms   ||   for   where   serial   

原文地址:https://www.cnblogs.com/yxb-blog/p/12654244.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!