字符转数字型 | to_number(字符型字段,'999999999999999999') |
字符转日期型 | TO_DATE('${TXNDATE}','YYYY-MM-DD') |
如果是空设置成date类型nulldate | COALESCE(P9_START_DATE,CAST('${NULLDATE}' AS DATE)) |
如果是空设置成timestamp类型0001-01-01 00:00:00 | COALESCE(TMS,CAST('0001-01-01 00:00:00' AS TIMESTAMP)) |
数字型转字符串 | TO_CHAR(20210630,'YYYY-MM-DD') |
显示建表 | select show_table('schema.表') |
pg批量捞表名语句 | select *from pg_tables where tablename ilike '%关键词%' |
numerical转timestamp | to_timestamp(to_char(TMS,'FM99999999999999999'),'yyyymmddHH24missms') |
case when 判断 | case when then END |
pg批量捞视图名语句 | SELECT* FROM PG_VIEWS WHERE VIEWNAME ilike '表名' |
pg中数字型和字符型通常上限 | numeric最大1000,varchar最大4000 |
sql中group by注意点 | group by sum不加进来 |
表授权语句 | grant all on 表 to 用户名 |
表回收权限语句 | revoke all on 表 from 用户名 |
月末表达式 | TO_DATE(SUBSTR(DATE'${TXNDATE}',1,8)||'01','YYYY-MM-DD')-1 |
如何判定重复核心语句 | GROUP BY 1 HAVING COUNT(1)>1 |
建立备份表 | create 备份table as select * from table |
删除重复 | delete from (select *from ((select row_number() over(partition by 分布键 order by 主键,日期) as rn,* from table)t where t.rn>1 ) ) |
建立备份视图 | create 备份view as select * from view |
SQL中的常用小知识点
最新推荐文章于 2023-10-14 20:59:34 发布