Oracle常见问题1-15

 

1. 查看oracle线程:ps -ef | grep ora

 

2.用什么语句查询字段呢?

select table_name from all_tables;
desc table_name
可以查询表的结构

select * from all_tab_columns where table_name='??'

 

3.如何查询数据库有多少表?
select count(*) from all_tables;

 

4.如何显示当前连接用户

show user;

 

5.如何执行脚本SQL文件

@$PATH/filename.sql;

 

6.CHR()的反函数是?
ASCII()

select chr(65) from dual;

select ascii('A') from dual;

 

7.返回大于等于N的最小整数值?
SELECT CEIL(N) FROM DUAL;

SELECT CEIL(2008.1) FROM DUAL; //2009

SELECT CEIL(-2008.1) FROM DUAL; //-2008

 

8.返回小于等于N的最小整数值?
SELECT FLOOR(N) FROM DUAL;

SELECT FLOOR(2008.1) FROM DUAL; // 2008

SELECT FLOOR(-2008.1) FROM DUAL; //-2009

 

9.如何测试SQL语句执行所用的时间?
set timing on ;
select * from tablename;

10.怎么把select出来的结果导到一个文本文件中?
spool /home/winnie/test.txt;
select * from mytable;
spool off;

 

11. ROWID 返回行的物理地址
select rowid from mytable;

ROWID

------------------

AAACtGAAKAAABD8AAA

AAACtGAAKAAABD8AAB

 

12. currval nextval 为表创建序列

create sequence myseq start with 1 increment by 1;

select myseq.currval from dual;

insert into mytable values(myseq.nextval,…);

删除序列:drop sequence myseq;

 

13. 如何查找重复记录?

select rowid,bm,mc from a where a.rowid!=(select max(rowid) from a b where a.bm=b.bm and a.mc=b.mc);

 

14. 删除重复记录
delete from a a where a.rowid!=(select max(rowid) from a b where a.bm=b.bm and a.mc=b.mc);

15. 查询oracle的锁

//查询oracle的锁

SELECT /*+ rule */ lpad(' ',decode(l.xidusn ,0,3,0))||l.oracle_username User_name, o.owner,o.object_name,o.object_type,s.sid,s.serial#,s.MACHINE FROM v$locked_object l,dba_objects o,v$session s WHERE l.object_id=o.object_id AND l.session_id=s.sid ORDER BY o.object_id,xidusn DESC

//然后kill锁

alter system kill session 'sid,serial#';



 

你可能感兴趣的:(oracle,session,kill,user,table,delete)