a.一个用户下的表明細+表注释+字段明细+字段注释
select ATC.OWNER, atC.TABLE_NAME, utc.comments, ATC.COLUMN_NAME, ATC.DATA_TYPE, ATC.DATA_LENGTH, ATC.NULLABLE, ucc.comments from (select ATC.OWNER, atC.TABLE_NAME, ATC.COLUMN_NAME, ATC.DATA_TYPE, ATC.DATA_LENGTH, ATC.NULLABLE from all_tab_columns ATC where ATC.owner in ('UserName') ) atc left outer join user_col_comments ucc on atc.table_name=ucc.table_name and atc.column_name=ucc.column_name left outer join user_tab_comments utc on atc.table_name=utc.table_name order by atc.table_name,atc.column_name
b.多个用户下的表明細+表注釋+字段明細+字段注釋
select ATC.OWNER, atC.TABLE_NAME, ATC.COLUMN_NAME, utc.comments, ATC.DATA_TYPE, ATC.DATA_LENGTH, ATC.NULLABLE, ucc.comments from (select ATC.OWNER, atC.TABLE_NAME, ATC.COLUMN_NAME, ATC.DATA_TYPE, ATC.DATA_LENGTH, ATC.NULLABLE from all_tab_columns ATC where ATC.owner in ('UserName1','UserName2') ) atc left outer join all_col_comments ucc on atc.table_name=ucc.table_name and atc.column_name=ucc.column_name left outer join all_tab_comments utc on atc.table_name=utc.table_name order by atc.table_name,atc.column_name
a. SET TIMING ON
说明:显示SQL语句的运行时间。默认值为OFF。
在SQLPLUS中使用,时间精确到0.01秒。也就是10毫秒。
在PL/SQL DEVELOPER 中,时间精确到0.001秒:
b.SET AUTOTRACE ON
说明:设置允许对执行的SQL进行分析。默认值为OFF。
SET AUTOTRACE OFF:不生成AUTOTRACE 报告,这是缺省模式 SET AUTOTRACE ON EXPLAIN:AUTOTRACE只显示优化器执行路径报告 SET AUTOTRACE ON STATISTICS:只显示执行统计信息 SET AUTOTRACE ON:包含执行计划和统计信息 SET AUTOTRACE TRACEONLY:同SET AUTOTRACE ON,但是不显示查询输出
c.SET TRIMOUT ON
去除标准输出每行的拖尾空格,缺省为OFF
d.SET ECHO ON
显示START启动的脚本中的每个SQL命令,缺省为ON
e.SET FEEDBACK ON
设置显示“已选择XX行”
显示本次SQL命令处理的记录条数,缺省为ON
f.SET TERMOUT OFF
显示脚本中的命令的执行结果,缺省为ON
g. SET SERVEROUTPUT ON
设置允许显示输出类似DBMS_OUTPUT
size 10000000
1、查找表中多余的重复记录,重复记录是根据单个字段(Id)来判断
select * from 表 where Id in (select Id from 表 group byId having count(Id) > 1)
2、删除表中多余的重复记录,重复记录是根据单个字段(Id)来判断,只留有rowid最小的记录
DELETE from 表 WHERE (id) IN ( SELECT id FROM 表 GROUP BY id HAVING COUNT(id) > 1) AND ROWID NOT IN (SELECT MIN(ROWID) FROM 表 GROUP BY id HAVING COUNT(*) > 1);
3、查找表中多余的重复记录(多个字段)
select * from 表 a where (a.Id,a.seq) in(select Id,seq from 表 group by Id,seq having count(*) > 1)
4、删除表中多余的重复记录(多个字段),只留有rowid最小的记录
delete from 表 a where (a.Id,a.seq) in (select Id,seq from 表 group by Id,seq having count(*) > 1) and rowid not in (select min(rowid) from 表 group by Id,seq having count(*)>1)
5、查找表中多余的重复记录(多个字段),不包含rowid最小的记录
select * from 表 a where (a.Id,a.seq) in (select Id,seq from 表 group by Id,seq having count(*) > 1) and rowid not in (select min(rowid) from 表 group by Id,seq having count(*)>1)
最近写了一个oracle的job,运行的时间间隔是1分钟。但是发现这个job并没有运行,最开始怀疑是时间间隔写错了,但是一检查发现不是时间间隔并没有写错;又怀疑是存储过程有问题,但是单独执行存储过程是没有问题的。后来上网查了一下发现可能是系统参数 job_queue_process 的问题。job_queue_process 表示oracle能够并发的job的数量.
show parameter job_queue_process;
来查看oracle中job_queue_process的值。当job_queue_process值为0时表示全部停止oracle的job。
ALTER SYSTEM SET job_queue_processes = 10;
来修改oracle中job_queue_process的值(这里改为10,job_queue_process的值该设为多少是另外的问题);
不过这种修改是动态的,当oracle重新启动后job_queue_process的值将仍然从\%ORACLE_HOME%\admin\mydb\pfile\init.ora文件中读取。
oracle 11g job:
-- Drop existing database link
drop database link TEST_LINK;
-- Create database link
create database link TEST_LINK connect to 数据库实例名 IDENTIFIED BY 数据库密码 using '(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.189.56.56)(PORT = 1521)) ) (CONNECT_DATA = (SID = 数据库实例名) (SERVER = DEDICATED) ) )';