trunc

How to show 0 when no row found

匿名 (未验证) 提交于 2019-12-03 08:33:39
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a SQL query in which I am passing sysdate to the query problem is that when there is no matching date in table with sysdate then it don't shows the zero even if there is nvl applied here is my query select * from molasses where trunc(trn_dte) = trunc(sysdate) But it show data only when current date is present in table but I want to show zero if no data found in table.please help me to do this in oracle 10 g. Because some times the situation is like above and I have to display zero when no data found 回答1: This is weird and I wouldn't

trunc and round function in sql

匿名 (未验证) 提交于 2019-12-03 02:33:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is trunc and round the same with negative arguments? SQL> select round(123456.76,-4) from dual; ROUND(123456.76,-4) ------------------- 120000 SQL> select trunc(123456.76,-4) from dual; TRUNC(123456.76,-4) ------------------- 120000 回答1: No, behavior depends on the value of the significant digit (the 3rd digit (the 3) is the significant one in your case, as it is below 5 round and trunc do the same ) try select trunc(125456.76,-4) from dual (result is 120000) vs select round(125456.76,-4) from dual (result is 130000). Now when the

Oracle date function for the previous month

匿名 (未验证) 提交于 2019-12-03 02:15:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have the query below where the date is hard-coded. My objective is to remove the harcoded date; the query should pull the data for the previous month when it runs. select count(distinct switch_id) from xx_new.xx_cti_call_details@appsread.prd.com where dealer_name = 'XXXX' and TRUNC(CREATION_DATE) BETWEEN '01-AUG-2012' AND '31-AUG-2012' Should I use sysdate-15 function for that? 回答1: Modifying Ben's query little bit, select count(distinct switch_id) from xx_new.xx_cti_call_details@appsread.prd.com where dealer_name = 'XXXX' and creation

SQL Join on Nearest less than date

匿名 (未验证) 提交于 2019-12-03 01:12:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Normally I would just do this in the code itself, but I am curious if this can be accomplished efficiently in TSQL. Table 1 Date - Value Table 2 Date - Discount Table 1 contains entries for each day. Table 2 contains entries only when the discount changes. A discount applied to a value is considered valid until a new discount is entered. Example data: Table 1 1 / 26 / 2010 - 10 1 / 25 / 2010 - 9 1 / 24 / 2010 - 8 1 / 24 / 2010 - 9 1 / 23 / 2010 - 7 1 / 22 / 2010 - 10 1 / 21 / 2010 - 11 Table 2 1 / 26 / 2010 - 2 1 / 23 / 2010 - 1 1

Oracle审计表AUD$处理方法

匿名 (未验证) 提交于 2019-12-03 00:15:02
Oracle版本:11.2.0,其他版本要测试DBMS_AUDIT_MGMT能否成功 1. 查询表,然后truncate 2.创建表空间 create tablespace adttbs SELECT table_name, tablespace_name 3.aud$表移动到新tablespace BEGIN DBMS_AUDIT_MGMT.SET_AUDIT_TRAIL_LOCATION(audit_trail_type => DBMS_AUDIT_MGMT.AUDIT_TRAIL_DB_STD, audit_trail_location_value => 'ADTTBS'); END; / 4.sys用户procedure: create or replace procedure sp_trunc_audit_log is begin end; 授权: grant execute on sp_trunc_audit_log to system; 5.system用户procedure: create or replace procedure sp_job_trunc_audit_log is begin end; 6.自动调度job BEGIN END; ―――――――――――――――― 版权声明:本文为CSDN博主「gyanp」的原创文章,遵循 CC 4.0 BY-SA

oracle之TRUNC函数

匿名 (未验证) 提交于 2019-12-02 23:57:01
MONTHS_BETWEEN的使用    MONTHS_BETWEEN函数返回两个日期之间的月份数。 oracle之TRUNC函数 TRUNC(number,num_digits) Num_digits 用于指定取整精度的数字,Num_digits 的默认值为 0。如果Num_digits为正数,则截取小数点后Num_digits位;如果为负数,则先保留整数部分,然后从个位开始向前数,并将遇到的数字都变为0。 TRUNC()函数在截取时不进行四舍五入,直接截取。 针对日期的案例,如: decode函数: decode(X,A,B,C,D,E) 这个函数运行的结果是,当X = A,函数返回B;当X != A 且 X = C,函数返回D;当X != A 且 X != C,函数返回E。 其中,X、A、B、C、D、E都可以是表达式,这个函数使得某些sql语句简单了许多 oracle函数详解: https://www.cnblogs.com/lxl57610/p/7442130.html 来源:博客园 作者: bai白 链接:https://www.cnblogs.com/bai123/p/11447308.html

Oracle - 获取当前周别函数

匿名 (未验证) 提交于 2019-12-02 23:55:01
1 CREATE OR REPLACE FUNCTION GET_WEEK ( V_RQ in DATE ) return varchar2 as 2 str varchar2 ( 20 ); 3 str1 varchar2 ( 20 ); 4 5 begin 6 str := TRIM ( TO_CHAR ( TRUNC (( V_RQ + TO_CHAR ( TRUNC ( V_RQ , 'YYYY' ), 'D' )- 1 - TRUNC ( V_RQ , 'YYYY' ))/ 7 )+ 1 , '00' )); 7 return str ; 8 end ; 来源:博客园 作者: JJ_JeremyWu 链接:https://www.cnblogs.com/jeremywucnblog/p/11421775.html

Oracle trunc()函数的用法

匿名 (未验证) 提交于 2019-12-02 23:49:02
Oracle trunc()函数的用法 日期 select trunc(sysdate) from dual --2019/7/21 今天的日期为2019/7/21 select trunc(sysdate, 'mm') from dual --2019/7/1 返回当月第一天. select trunc(sysdate,'yy') from dual --2019/1/1 返回当年第一天 select trunc(sysdate,'dd') from dual --2019/7/21 返回当前年月日(当天) select trunc(sysdate,'yyyy') from dual --2019/1/1返回当年第一天 select trunc(sysdate,'dd') from dual --2019/7/21 (星期天)返回当前星期的第一天 select trunc(sysdate, 'hh') from dual --2019/7/21 23:00:00 当前时间为23:02(整点) select trunc(sysdate, 'mi') from dual --2019/7/21 23:02:00 TRUNC()函数没有秒的精确 数字 TRUNC(number,num_digits) Number 需要截尾取整的数字。 Num_digits 用于指定取整精度的数字

plsql定时执行存储过程之DBMS_JOBS配置

匿名 (未验证) 提交于 2019-12-02 23:43:01
What值填写存储过程名时后面须加分号 时间间隔 1:每分钟执行 Interval => TRUNC(sysdate,'mi') + 1/(24*60) 2:每天定时执行 例如:每天的凌晨1点执行 Interval => TRUNC(sysdate) + 1 +1/(24) 3:每周定时执行 例如:每周一凌晨1点执行 Interval => TRUNC(next_day(sysdate,'星期一'))+1/24 4:每月定时执行 例如:每月1日凌晨1点执行 Interval =>TRUNC(LAST_DAY(SYSDATE))+1+1/24 5:每季度定时执行 例如每季度的第一天凌晨1点执行 Interval => TRUNC(ADD_MONTHS(SYSDATE,3),'Q') + 1/24 6:每半年定时执行 例如:每年7月1日和1月1日凌晨1点 Interval => ADD_MONTHS(trunc(sysdate,'yyyy'),6)+1/24 7:每年定时执行 例如:每年1月1日凌晨1点执行 Interval =>ADD_MONTHS(trunc(sysdate,'yyyy'), 12)+1/24 查看jobs SELECT * FROM dba_jobs; ֹͣjob 再次查看job 发现已经停止 文章来源: https://blog.csdn.net/mar5342