横表、纵表以及表字段查询通用sql总结(Oracle)

tech2023-01-11  123

1. 横表与纵表

示例1:

示例2:

示例3:

oracle数据库中表字段注释表:

2. 通用类SQL

//获取当前用户表 SELECT * FROM USER_TABLES t; //获取指定用户表 SELECT * FROM ALL_TABLES t WHERE t.OWNER='ICIFNEW'; //获取表字段 select * from user_tab_columns t where t.TABLE_NAME = 'ECUSR'; //获取表注释 select * from user_tab_comments t where t.table_name = 'ECUSR'; //获取字段注释 select * from user_col_comments t where t.table_name = 'ECUSR'; //联合查询,查询表字段名称、类型,注释; select t.TABLE_NAME, t.COLUMN_NAME, m.comments, t.DATA_TYPE from user_tab_columns t left join user_col_comments m on t.TABLE_NAME = m.table_name where t.COLUMN_NAME = m.column_name and t.TABLE_NAME = 'ECUSR';

示例

3. 为表增加联合主键(唯一约束)

违反唯一约束示例:

4. 查询序列

select * from user_sequences; select * from user_sequences where sequence_name = 'USRSEQ';

示例:

可以通过view查看序列的生成SQL语句.

5. oracle分页

SELECT * FROM ( SELECT A.*, ROWNUM RN FROM (SELECT * FROM REMOTE_LIST WHERE 1 = 1 ) A WHERE ROWNUM < 20) WHERE RN >= 15 order by input_time desc;

 

最新回复(0)