Oracle - 工作中一些有用的SQL总结

1. 建表

1 create table table_name as SELECT * FROM table_name WHERE rownum < 1;

 

2. 查询表结构

1 select t.COLUMN_NAME,t.DATA_TYPE||'('||t.data_length||')',t.nullable,a.comments
2 from user_tab_columns t,user_col_comments a
3  where t.table_name=a.table_name and t.column_name=a.column_name
4  and  t.table_name= 'TABLE_NAME' ORDER BY COLUMN_ID;

 

3.正则表达式

1 --  查询value不是纯数字的记录
2 select value from table_name where not regexp_like(value, '^[[:digit:]]+$'); 

3 -- 查询value不包含任何数字的记录
4 select value from table_name where regexp_like(value, '^[^[:digit:]]+$');
1 -- 去掉前后除数字外其他字符
2 select value, translate(value, '#' || translate(value, '0123456789', '#'), '/') AS newname
3 from table_name WHERE value IS NOT NULL ;

 

 

 

posted on 2017-11-17 18:42  Reazengry  阅读(527)  评论(1编辑  收藏  举报

导航