Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Programming PL SQL.doc
Скачиваний:
2
Добавлен:
01.07.2025
Размер:
5.06 Mб
Скачать

10.4.9 The next_day Function

The NEXT_DAY function returns the date of the first day after the specified date that falls on the specified day of the week. Here is the specification for NEXT_ DAY:

FUNCTION NEXT_DAY (date_in IN DATE, day_name IN VARCHAR2) RETURN DATE

The day_name must be a day of the week in your session's date language (specified by the NLS_DATE_LANGUAGE database initialization parameter). The time component of the returned date is the same as that of the input date, date_in. If the day of the week of the input date matches the specified day_name, then NEXT_DAY will return the date seven days (one full week) after date_in. NEXT_ DAY does not return the input date if the day names match.

Here are some examples of the use of NEXT_DAY. Let's figure out the date of the first Monday and Wednesday in 1997 in all of these examples:

BEGIN

--You can use both full and abbreviated day names:

DBMS_OUTPUT.PUT_LINE(NEXT_DAY ('01-JAN-1997', 'MONDAY'));

DBMS_OUTPUT.PUT_LINE(NEXT_DAY ('01-JAN-1997', 'MON'));

--The case of the day name doesn't matter a whit:

DBMS_OUTPUT.PUT_LINE(NEXT_DAY ('01-JAN-1997', 'monday'));

--NEXT_DAY of Wednesday moves the date up a full week:

DBMS_OUTPUT.PUT_LINE(NEXT_DAY ('01-JAN-1997', 'WEDNESDAY'));

--If the date language were Spanish:

EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_DATE_LANGUAGE="SPANISH"';

DBMS_OUTPUT.PUT_LINE(NEXT_DAY ('01-ENE-1997', 'LUNES'));

END;

The output is:

06-JAN-97

06-JAN-97

06-JAN-97

08-JAN-97

06-ENE-97

Chapter 11. Records and Collections

Records and collections are examples of composite data structures, which means that they are composed of more than one element or component, each with its own value. Records in PL/SQL programs are very similar in concept and structure to the rows of a database table. The record as a whole does not have a value of its own; instead, each individual component or field has a value, and the record gives you a way to store and access these values as a group. Records can greatly simplify your life as a programmer, allowing you to write and manage your code more efficiently by shifting from field-level declarations and manipulation to record-level operations.

A collection is a data structure that acts like a list or single-dimensional array. Collections are, in fact, the closest you can get to traditional arrays in the PL/SQL language. You can use collections to manage lists of information in your programs. This chapter will help you decide which of the three different types of collections (associative array, nested table, or VARRAY) best fit your program requirements, and will show you how to define and manipulate those structures.

First, let's get to know records. They are simpler, and are often used within collections.

11.1 Records in pl/sql

A record is similar in structure to a row in a database table. Each row in a table has one or more columns of various datatypes. A record is composed of one or more fields. There are three different ways to define a record, but once defined, the same rules apply for referencing and changing fields in a record. Let's take a look at some of the benefits of using records. Then we'll examine the different ways to define a record, and finish up with examples of using records in your programs.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]