一、常用sql
1.查看版本
SELECT * FROM V$VERSION;
SELECT version FROM V$INSTANCE
2.数据库发生死锁时,跟踪文件的位置
关于跟踪文件,大义是oracle发生错误时,会写日志到跟踪文件,比如发生死锁时,该文件就是排查利器:
Each server and background process can write to an associated trace file. When an internal error is detected by a process, it dumps information about the error to its trace file. Some of the information written to a trace file is intended for the database administrator, and other information is for Oracle Support Services. Trace file information is also used to tune applications and instances.
SELECT VALUE FROM V$DIAG_INFO WHERE NAME = 'Default Trace File';
注意该路径为服务器上的路径,本机oracle服务器为windows。
3.查询当前实例的所有跟踪文件
SELECT VALUE FROM V$DIAG_INFO WHERE NAME = 'Diag Trace';
4.查询oracle实例上所有线程各自的跟踪文件
SELECT PID, PROGRAM, TRACEFILE FROM V$PROCESS;
二、会话相关
1、查询当前会话列表
select * from v$session
关于该视图:
v$session:This view has one row for every session connected to the database instance. The sessions include user sessions, as well as background processes like DBWR, LGWR, archiver.
下面链接可以查看对应的字段的含义:
https://www.cnblogs.com/shengs/p/4895085.html
2.结束一个会话
ALTER SYSTEM KILL SESSION '7,15'; 其中,7为select * from v$session结果中的SID,15为SERIAL#
结束一个会话时,这个会话上的所有活跃事务全部回滚,该会话持有的资源,如锁和内存区域,会马上释放,供其他会话使用。
3.查询某个用户的全部会话
SELECT SID, SERIAL#, STATUS FROM V$SESSION WHERE USERNAME = 'CAD';
关于status字段:
active:表示正在进行sql操作;
inactive:当前没正在进行sql操作。
官方解释:
A session is ACTIVE
when it is making a SQL call to Oracle Database. A session is INACTIVE
if it is not making a SQL call to the database.
三、约束
在利用navicat for oracle时,如果一个字段开始时为 非空,则会创建一个约束。
但是在取消字段非空的限制后,(没删检查),该检查会依然存在,此时会导致数据写入报错。