Oracle查询今天、昨天、本周、上周、本月、上月数据

查询今天数据:

SELECT COUNT(1) FROM T_CALL_RECORDS WHERE TO_CHAR(T_RKSJ,'YYYY-MM-DD')=TO_CHAR(SYSDATE,'YYYY-MM-DD')
查询昨天数据:

SELECT COUNT(1) FROM T_CALL_RECORDS WHERE TO_CHAR(T_RKSJ,'YYYY-MM-DD')=TO_CHAR(SYSDATE-1,'YYYY-MM-DD') 
查询本周数据:

SELECT COUNT(1) FROM T_CALL_RECORDS WHERE T_RKSJ >= TRUNC(NEXT_DAY(SYSDATE-8,1)+1) AND T_RKSJ < TRUNC(NEXT_DAY(SYSDATE-8,1)+7)+1
查询上周数据:

SELECT COUNT(1) FROM T_CALL_RECORDS WHERE T_RKSJ >= TRUNC(NEXT_DAY(SYSDATE-8,1)-6) AND T_RKSJ < TRUNC(NEXT_DAY(SYSDATE-8,1)+1)
查询本月数据:

SELECT COUNT(1) FROM T_CALL_RECORDS WHERE TO_CHAR(T_RKSJ,'YYYY-MM')=TO_CHAR(SYSDATE,'YYYY-MM')
查询上月数据:

SELECT COUNT(1) FROM T_CALL_RECORDS WHERE TO_CHAR(T_RKSJ,'YYYY-MM')=TO_CHAR(ADD_MONTHS(SYSDATE,-1),'YYYY-MM')
查询表名及字段信息数据:

SELECT A.TABLE_NAME 表名,A.COLUMN_NAME 字段名,A.COMMENTS 字段注释,B.DATA_TYPE 字段类型,B.DATA_LENGTH 字段长度,B.NULLABLE 是否为空,C.INDEX_NAME 索引名称
FROM USER_COL_COMMENTS A 
LEFT JOIN USER_TAB_COLUMNS B ON A.COLUMN_NAME = B.COLUMN_NAME AND A.TABLE_NAME=B.TABLE_NAME
LEFT JOIN USER_IND_COLUMNS C ON A.COLUMN_NAME = C.COLUMN_NAME AND A.TABLE_NAME=C.TABLE_NAME 
WHERE A.TABLE_NAME = '表名'
ORDER BY B.COLUMN_ID

 

posted @ 2020-12-30 19:44  韩梦芫  阅读(4033)  评论(0编辑  收藏  举报