不管接下来发生什么事,你都不能停止前进

Oracle语法记录

1.四舍五入保留两位小数

select cast(123456 as number(18,2)) as aa from dual;

2.生成数据字典

select m.*, decode(n.column_name, null, '', 'Y') 主键, a.nullable 非空
  from (select t.table_name 表代码,
               t2.comments 表名称,
               t.column_name 字段代码,
               t1.comments 字段名称,
               t.data_type 字段类型,
               decode(t.data_type, 'NUMBER', T.DATA_PRECISION, T.DATA_LENGTH) 字段长度,
               T.DATA_SCALE 小数位数
          from user_tab_cols t, user_col_comments t1, user_tab_comments t2
         where t.table_name = t1.table_name
           and t.column_name = t1.column_name
           and t.table_name = t2.table_name) m
  left join (select t3.table_name, t4.column_name
               from user_constraints t3, user_cons_columns t4
              where t3.constraint_name = t4.constraint_name
                and t3.constraint_type = 'P') n on m.表代码 = n.table_name
                                               and m.字段代码 = n.column_name
  left join (select t5.table_name, t5.column_name, t5.nullable
               from user_tab_columns t5) a on m.表代码 = a.table_name
                                          and m.字段代码 = a.column_name
 order by m.表代码, M.字段代码

3.多表数量查询
最后一张表不加 union all

select '表名',count(*) from 表名 union all

4.数据库中存储的性别是1和2,查询的时候怎么让1和2变成男,女显示出来

select case when 性别 = 1 then '男' when  性别 = 2 then '女' else '不男不女' end from table;

5.查询所有用户

select * from all_users;

6.空值放在末尾

select * from 表代码 t order by 过滤字段 nulls last

7.查看Oracle数据库服务端字符集

select * from nls_database_parameters

8.少量数据误删除恢复语句,时间为要回滚的时间节点

select * from xbbf_dydb_gbjl as of timestamp to_timestamp('2020-01-07 23:30:00','yyyy-mm-dd HH24:MI:SS') 
posted @ 2019-11-06 12:48  普罗旺斯_S  阅读(124)  评论(0编辑  收藏  举报