oracle查询技巧

1. 普通用户查询表结构

SELECT USER_TAB_COLS.COLUMN_NAME as 列名 , USER_TAB_COLS.DATA_TYPE as 数据类型, USER_TAB_COLS.DATA_LENGTH as 长度, USER_TAB_COLS.NULLABLE as 是否为空, case
when (SELECT col.column_name FROM user_constraints con, user_cons_columns col where con.constraint_name = col.constraint_name and con.constraint_type='P' and col.table_name = '表名' and col.column_name = USER_TAB_COLS.COLUMN_NAME) = USER_TAB_COLS.COLUMN_NAME THEN 'Y' ELSE 'N' END as 是否主键, case when (select count(*) from user_constraints con, user_cons_columns col, (select t2.table_name,t2.column_name,t1.r_constraint_name from user_constraints t1,user_cons_columns t2 where t1.r_constraint_name=t2.constraint_name and t1.table_name='表名') r where con.constraint_name=col.constraint_name and con.r_constraint_name=r.r_constraint_name and con.table_name='表名' and col.column_name = USER_TAB_COLS.COLUMN_NAME) > 0 then 'Y' else 'N' END as 是否外键 , user_col_comments.comments as 备注 FROM USER_TAB_COLS inner join user_col_comments on user_col_comments.TABLE_NAME = USER_TAB_COLS.TABLE_NAME and user_col_comments.COLUMN_NAME=USER_TAB_COLS.COLUMN_NAME and USER_TAB_COLS.TABLE_NAME = '表名' ORDER BY USER_TAB_COLS.COLUMN_ID;

2. 利用rownum实现top功能

select  * from table_name where rownum<10 order by rownum asc

posted @ 2012-05-30 14:36  vigarbuaa  阅读(238)  评论(0编辑  收藏  举报