oracle实用sql语句
-- 查看ORACLE 数据库中本用户下的所有表
SELECT table_name FROM user_tables;
SELECT table_name FROM user_tables;
-- 查看ORACLE 数据库中所有用户下的所有表
select user,table_name from all_tables;
select user,table_name from all_tables;
-- 查看ORACLE 数据库中本用户下的所有列
select table_name,column_name from user_tab_columns;
select table_name,column_name from user_tab_columns;
-- 查看ORACLE 数据库中本用户下的所有列
select user,table_name,column_name from all_tab_columns;
select user,table_name,column_name from all_tab_columns;
-- 查看ORACLE 数据库中的序列号
select * from user_sequences;
select * from user_sequences;
-- 上面的所有对象,都可以通过下面的SQL语句查询得到
-- 查询所有的用户生成的ORACLE对象
SELECT * FROM user_objects;
-- 查询所有的用户生成的ORACLE对象
SELECT * FROM user_objects;
-- 查看ORACLE 数据库中所有表的注释
select table_name,comments from user_tab_comments;
select table_name,comments from user_tab_comments;
-- 查看ORACLE 数据库中所有列的注释
select table_name,column_name,comments from user_col_comments;
select table_name,column_name,comments from user_col_comments;
-- 给表加ORACLE的注释
COMMENT ON TABLE aa10 IS '系统参数表';
COMMENT ON TABLE aa10 IS '系统参数表';
-- 给列加ORACLE的注释
COMMENT ON COLUMN aa10.aaa100 IS '参数类别';
COMMENT ON COLUMN aa10.aaa100 IS '参数类别';
-- 查看表中列的属性,包括 数据类型,是否非空等
DESC aa10;
-- 通过系统表,查看表中列的属性,包括 数据类型,是否非空等
SELECT table_name,COLUMN_ID,column_name,data_type,data_length, DATA_PRECISION,NULLABLE
FROM user_tab_columns
ORDER BY table_name,COLUMN_ID;
DESC aa10;
-- 通过系统表,查看表中列的属性,包括 数据类型,是否非空等
SELECT table_name,COLUMN_ID,column_name,data_type,data_length, DATA_PRECISION,NULLABLE
FROM user_tab_columns
ORDER BY table_name,COLUMN_ID;
-- 查看数据库中表、索引占用的数据库空间大小
SELECT * FROM user_segments;
-- 查看所有表的记录数
CREATE TABLE table_count(table_name VARCHAR2(50),columns NUMBER(20));
-- 通过PB运行下面的语句,得到结果集,将结果集在PB下执行,最后提交
select 'insert into table_count values('''||table_name||''', (select count(1) from '||table_name||'));//'||comments from user_tab_comments;
-- 所有表的记录都在table_count了
SELECT * FROM table_count;
CREATE TABLE table_count(table_name VARCHAR2(50),columns NUMBER(20));
-- 通过PB运行下面的语句,得到结果集,将结果集在PB下执行,最后提交
select 'insert into table_count values('''||table_name||''', (select count(1) from '||table_name||'));//'||comments from user_tab_comments;
-- 所有表的记录都在table_count了
SELECT * FROM table_count;
// 将ORACLE数据库的注释同步到PB中 代码开始
DELETE FROM PBCATCOL WHERE PBC_TNAM LIKE '%';
DELETE FROM PBCATTBL WHERE PBT_TNAM LIKE '%';
DELETE FROM PBCATCOL WHERE PBC_TNAM LIKE '%';
DELETE FROM PBCATTBL WHERE PBT_TNAM LIKE '%';
INSERT INTO PBCATTBL
( PBT_TNAM,
PBT_OWNR ,
PBT_CMNT)
SELECT ALL_TAB_COMMENTS.TABLE_NAME,
ALL_TAB_COMMENTS.OWNER,
ALL_TAB_COMMENTS.COMMENTS
FROM ALL_TAB_COMMENTS
WHERE ALL_TAB_COMMENTS.OWNER = 'LH'
AND TABLE_NAME LIKE '%';
// 同步字段名
INSERT INTO PBCATCOL
( PBC_TNAM,
PBC_OWNR,
PBC_CNAM,
PBC_LABL,
PBC_CMNT,
PBC_HDR)
SELECT ALL_COL_COMMENTS.TABLE_NAME,
ALL_COL_COMMENTS.OWNER,
ALL_COL_COMMENTS.COLUMN_NAME,
ALL_COL_COMMENTS.COMMENTS ,
ALL_COL_COMMENTS.COMMENTS ,
ALL_COL_COMMENTS.COMMENTS
FROM ALL_COL_COMMENTS
WHERE ALL_COL_COMMENTS.OWNER = 'LH'
AND TABLE_NAME LIKE '%';
( PBC_TNAM,
PBC_OWNR,
PBC_CNAM,
PBC_LABL,
PBC_CMNT,
PBC_HDR)
SELECT ALL_COL_COMMENTS.TABLE_NAME,
ALL_COL_COMMENTS.OWNER,
ALL_COL_COMMENTS.COLUMN_NAME,
ALL_COL_COMMENTS.COMMENTS ,
ALL_COL_COMMENTS.COMMENTS ,
ALL_COL_COMMENTS.COMMENTS
FROM ALL_COL_COMMENTS
WHERE ALL_COL_COMMENTS.OWNER = 'LH'
AND TABLE_NAME LIKE '%';
COMMIT;
-- 将ORACLE数据库的注释同步到PB中 代码结束
-- 将ORACLE数据库的注释同步到PB中 代码结束
--将PB注释同步到ORACLE中
select 'comment on table '||pbt_tnam||' is '''||pbt_cmnt||''';' from pbcattbl where pbt_tnam not like 'PB%'
UNION
select 'comment on column '||pbc_tnam||'.'||pbc_cnam||' is '''||pbc_cmnt||''';' from pbcatcol where pbC_tnam not like 'PB%';
--查进程
select object_id,session_id,locked_mode from v$locked_object;
select t2.username,t2.sid,t2.serial#,t2.logon_time
from v$locked_object t1,v$session t2
where t1.session_id=t2.sid order by t2.logon_time;
--杀进程
alter system kill session '3,6666';
from v$locked_object t1,v$session t2
where t1.session_id=t2.sid order by t2.logon_time;
--杀进程
alter system kill session '3,6666';