Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Semestr2 / 1 - Oracle / Oracle selected docs / SQL reference.pdf
Скачиваний:
24
Добавлен:
12.05.2015
Размер:
11.92 Mб
Скачать

MONTHS_BETWEEN

m - n * FLOOR(m/n)

The following table illustrates the difference between the MOD function and the classical modulus:

m

n

MOD(m,n)

Classical Modulus

 

 

 

 

11

4

3

3

11

-4

3

-1

-11

4

-3

1

-11

-4

-3

-3

 

 

 

 

See Also: FLOOR on page 6-71

MONTHS_BETWEEN

Syntax months_between::=

MONTHS_BETWEEN ( date1 , date2 )

Purpose

MONTHS_BETWEEN returns number of months between dates date1 and date2. If date1 is later than date2, then the result is positive. If date1 is earlier than date2, then the result is negative. If date1 and date2 are either the same days of the month or both last days of months, then the result is always an integer. Otherwise Oracle calculates the fractional portion of the result based on a 31-day month and considers the difference in time components date1 and date2.

Examples

The following example calculates the months between two dates:

SELECT MONTHS_BETWEEN (TO_DATE(’02-02-1995’,’MM-DD-YYYY’),

TO_DATE(’01-01-1995’,’MM-DD-YYYY’) ) "Months" FROM DUAL;

Functions 6-99

NCHR

Months

----------

1.03225806

NCHR

Syntax nchr::=

NCHR ( number )

Purpose

NCHR returns the character having the binary equivalent to number in the national character set. This function is equivalent to using the CHR function with the USING NCHAR_CS clause.

See Also: CHR on page 6-31

Examples

The following examples return the nchar character 187:

SELECT NCHR(187) FROM DUAL;

NC

--

>

SELECT CHR(187 USING NCHAR_CS) FROM DUAL;

CH

--

>

NEW_TIME

Syntax new_time::=

NEW_TIME ( date , zone1 , zone2 )

6-100 Oracle9i SQL Reference

NEW_TIME

Purpose

NEW_TIME returns the date and time in time zone zone2 when date and time in time zone zone1 are date. Before using this function, you must set the NLS_DATE_ FORMAT parameter to display 24-hour time.

Note: This function takes as input only a limited number of time zones. You can have access to a much greater number of time zones by combining the FROM_TZ function and the datetime expression. See FROM_TZ on page 6-71 and the example for "Datetime Expressions" on page 4-9.

The arguments zone1 and zone2 can be any of these text strings:

AST, ADT: Atlantic Standard or Daylight Time

BST, BDT: Bering Standard or Daylight Time

CST, CDT: Central Standard or Daylight Time

EST, EDT: Eastern Standard or Daylight Time

GMT: Greenwich Mean Time

HST, HDT: Alaska-Hawaii Standard Time or Daylight Time.

MST, MDT: Mountain Standard or Daylight Time

NST: Newfoundland Standard Time

PST, PDT: Pacific Standard or Daylight Time

YST, YDT: Yukon Standard or Daylight Time

Examples

The following example returns an Atlantic Standard time, given the Pacific Standard time equivalent:

ALTER SESSION SET NLS_DATE_FORMAT = ’DD-MON-YYYY HH24:MI:SS’;

SELECT NEW_TIME(TO_DATE(

’11-10-99 01:23:45’, ’MM-DD-YY HH24:MI:SS’), ’AST’, ’PST’) "New Date and Time" FROM DUAL;

New Date and Time

--------------------

09-NOV-1999 21:23:45

Functions 6-101

NEXT_DAY

NEXT_DAY

Syntax next_day::=

NEXT_DAY ( date , char )

Purpose

NEXT_DAY returns the date of the first weekday named by char that is later than the date date. The argument char must be a day of the week in the date language of your session, either the full name or the abbreviation. The minimum number of letters required is the number of letters in the abbreviated version. Any characters immediately following the valid abbreviation are ignored. The return value has the same hours, minutes, and seconds component as the argument date.

Examples

This example returns the date of the next Tuesday after February 2, 2001:

SELECT NEXT_DAY(’02-FEB-2001’,’TUESDAY’) "NEXT DAY"

FROM DUAL;

NEXT DAY

-----------

06-FEB-2001

NLS_CHARSET_DECL_LEN

Syntax nls_charset_decl_len::=

NLS_CHARSET_DECL_LEN ( byte_count , char_set_id )

Purpose

NLS_CHARSET_DECL_LEN returns the declaration width (in number of characters) of an NCHAR column. The byte_count argument is the width of the column. The char_set_id argument is the character set ID of the column.

6-102 Oracle9i SQL Reference

Соседние файлы в папке Oracle selected docs