Unlock the Potential of Programming: Coding for Solutions

Monday, June 22, 2015

OraclePLSQL--INTRO OF DECLARE VARIABLES PART#02

PL/SQL program

INTRO OF DECLARE VARIABLES PART#02

Date and Timestamp Types

DECLARE
      v_date01  DATE  := '04-JUN-83';
      v_date02  DATE  := '09-FEB-1999';
      v_date03  DATE  := TO_DATE('19800118','YYYYMMDD');
    BEGIN
      dbms_output.put_line(v_date01);
      dbms_output.put_line(v_date02);
      dbms_output.put_line(v_date03);
   END;

anonymous block completed
04-JUN-83
09-FEB-99
18-JAN-80





   DECLARE
      v_date  DATE  := '18-JAN-1980';
    BEGIN
      v_date := v_date + 8;
      dbms_output.put_line(v_date);
    END;

anonymous block completed
26-JAN-80





  
DECLARE
      v_date_1  DATE  := SYSDATE;
      v_date_2  DATE  := v_date_1;
    BEGIN
      dbms_output.put_line(TO_CHAR(v_date_1,'DD-MON-YY HH24:MI:SS'));
      dbms_output.put_line(TO_CHAR(TRUNC(v_date_2),'DD-MON-YY HH24:MI:SS'));
    END;

anonymous block completed
22-JUN-15 20:08:26
22-JUN-15 00:00:00






Intervals



     DECLARE
      O_interval  INTERVAL DAY TO SECOND;
      O_end_day   DATE :=  SYSDATE;
      O_start_day DATE := '23-JUN-2015';
    BEGIN
      O_interval := TO_TIMESTAMP(O_end_day) - TO_TIMESTAMP(O_start_day);
      dbms_output.put_line(O_interval);
    END;
anonymous block completed
-00 03:22:08.000000







DECLARE
      p_interval  INTERVAL DAY(9) TO SECOND;
      p_end_day   TIMESTAMP := SYSTIMESTAMP;
      p_start_day TIMESTAMP := '23-JUN-2015';
    BEGIN
      p_interval := p_end_day - p_start_day;
      dbms_output.put_line(p_interval);
    END;

anonymous block completed
-000000000 03:14:19.749000








No comments:

Post a Comment