Oracle 取Oracle 表名 欄位名

2021-08-31 10:16:23 字數 3153 閱讀 8761

--檢視oracle 資料庫中本使用者下的所有表

select table_name from user_tables;<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

--檢視oracle 資料庫中所有使用者下的所有表

select user,table_name from all_tables;

--檢視oracle 資料庫中本使用者下的所有列

select table_name,column_name from user_tab_columns;

--檢視oracle 資料庫中本使用者下的所有列

select user,table_name,column_name from all_tab_columns;

--檢視oracle 資料庫中的序列號

select * from user_sequences;

--上面的所有物件,都可以通過下面的sql語句查詢得到

-- 查詢所有的使用者生成的oracle物件

select * from user_objects;

--檢視oracle 資料庫中所有表的注釋

select table_name,comments from user_tab_comments;

--檢視oracle 資料庫中所有列的注釋

select table_name,column_name,comments from user_col_comments;

--給表加oracle的注釋

comment on table aa10 is '系統參數列';

--給列加oracle的注釋

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;

--檢視資料庫中表、索引占用的資料庫空間大小

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;

//將oracle資料庫的注釋同步到pb中 **開始

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 '%';

commit;

-- 將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';

Oracle 修改表名

oracle修改表名的方式有以下幾種 方式一 1.先通過create table new table name as select from old table name 建立乙個新的表。2.檢查old table name上的約束,並把該約束應用到new table name上。3.禁用old t...

oracle 動態表名的游標寫法

在開發中,經常會碰到動態表名的游標的寫法,正好在工作中碰到乙個,如下所示 declare stralltable varchar2 100 type cur typ is ref cursor c cur typ c id number 18 c code varchar2 100 begin fo...

oracle給列取別名 給表取別名

當前sc表資料 sno cno score s001 c001 78.90 s002 c001 80.90 s003 c001 81.90 s004 c001 60.90 s001 c002 82.90 s002 c002 72.90 s003 c002 81.90 s001 c003 59.00 ...