Skip to Content
Oracle PL/SQL Programming: A Developer's Workbook
book

Oracle PL/SQL Programming: A Developer's Workbook

by Steven Feuerstein, Andrew Odewahn
May 2000
Intermediate to advanced
594 pages
11h 32m
English
O'Reilly Media, Inc.
Content preview from Oracle PL/SQL Programming: A Developer's Workbook

Intermediate

Q:

19-10.

I would use a combination of TRUNC and NEXT_DAY, as shown here:

DECLARE
   first_monday DATE;
BEGIN
   first_monday := NEXT_DAY (
      TRUNC (SYSDATE, 'MONTH'), 'MONDAY');
   DBMS_OUTPUT.PUT_LINE (first_monday);
END;
/

Q:

19-11.

We’re talking time-zone differences, so the NEW_TIME function should work perfectly well. London is on Greenwich Mean Time, while the folks in Chicago are on Central Standard Time. Here is a function that does the conversion:


/* Filename on web page: chitime.sf */
CREATE OR REPLACE FUNCTION chitime RETURN DATE
IS
BEGIN
   RETURN NEW_TIME (SYSDATE, 'GMT', 'CST');
END;
/

Q:

19-12.

TRUNC to the rescue once again:

CREATE OR REPLACE FUNCTION chitime RETURN DATE
IS
BEGIN
   RETURN TRUNC (SYSDATE, 'MONTH');
END;
/

Q:

19-13.

Well, first you have to truncate the current date/time back to the beginning of the century (which also sets the time component to midnight), then move forward 25 years, make sure you’re on the first day of that year, and move forward nine hours. Here goes:

DECLARE
   amaze_me DATE;
BEGIN
   amaze_me := TRUNC (
        ADD_MONTHS (TRUNC (SYSDATE, 'CC'), 25 * 12), 'MONTH') + 9 / 24;
   DBMS_OUTPUT.put_line (
      TO_CHAR (
         amaze_me,
         'MM/DD/YY HH24:MI:SS'
      )
   );
END;
/

Isn’t this fun?

Q:

19-14.

The four pieces of information displayed are:

30-JAN-99 -> 28-FEB-99
27-FEB-99 -> 27-MAR-99
31-JAN-99 -> 28-FEB-99
28-FEB-99 -> 31-MAR-99

Q:

19-15.

Statement (b) describes accurately the behavior ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Oracle Database 12c PL/SQL Advanced Programming Techniques

Oracle Database 12c PL/SQL Advanced Programming Techniques

Michael McLaughlin, John Harper

Publisher Resources

ISBN: 9781449324070Errata Page