开发者社区> 问答> 正文

Write a PL/SQL code ?

已解决

Write a PL/SQL code to count the number of Sundays between the two inputted dates.

展开
收起
1780169608831412 2021-10-16 18:09:52 774 0
1 条回答
写回答
取消 提交回答
  • 网络规划设计师、敏捷专家、CISP、ITSS服务经理、ACA全科目、ACP4项、ACE、CBP、CDSP、CZTP等。拥有 PRINCE2 Foundation/Practitioner、CCSK、ITIL、ISO27001、PMP等多项国际认证。 专利5+、期刊10+、知识产权师。核心期刊审稿人。
    采纳回答
    --declare 2 dates of type Date
    DECLARE
       start_date Date; 
       end_date Date; 
       sundays_count Number:=0; 
    BEGIN
       -- input 2 dates
       start_date:='&input_start_date'; 
       end_date:='&input_end_date';
       /* 
       Returns the date of the first day after the mentioned date 
       and matching the day specified in second parameter.
       */
       start_date:=NEXT_DAY(start_date-1, 'SUNDAY');
       --check the condition of dates by using while loop. 
       while(start_date<=end_date) 
       LOOP 
           sundays_count:=sundays_count+1; 
           start_date:=start_date+7; 
       END LOOP; 
       
       -- print the count of sundays
       dbms_output.put_line('Total number of Sundays between the two dates:'||sundays_count); 
    END; 
    /
    
    2021-10-16 18:29:30
    赞同 1 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
SQL Server 2017 立即下载
GeoMesa on Spark SQL 立即下载
原生SQL on Hadoop引擎- Apache HAWQ 2.x最新技术解密malili 立即下载