Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
50
Добавлен:
16.04.2013
Размер:
5.97 Mб
Скачать

Summary of PL/SQL Built-In Functions

The function REPLACE returns the value of its first argument if its second argument is null, whether the optional third argument is present or not. For example, the following call to REPLACE does not make any change to the value of OLD_STRING:

DECLARE

string_type VARCHAR2(60);

old_string string_type%TYPE := 'Apples and oranges'; my_string string_type%TYPE := 'more apples';

--NULL is a valid argument to REPLACE, but does not match

--anything so no replacement is done.

new_string string_type%TYPE := REPLACE(old_string, NULL, my_string);

BEGIN

dbms_output.put_line('Old string = ' || old_string); dbms_output.put_line('New string = ' || new_string);

END;

/

If its third argument is null, REPLACE returns its first argument with every occurrence of its second argument removed. For example, the following call to REPLACE removes all the dashes from DASHED_STRING, instead of changing them to another character:

DECLARE

string_type VARCHAR2(60);

dashed string_type%TYPE := 'Gold-i-locks';

--When the substitution text for REPLACE is NULL,

--the text being replaced is deleted.

name string_type%TYPE := REPLACE(dashed, '-', NULL);

BEGIN

 

 

 

 

dbms_output.put_line('Dashed name

=

'

||

dashed);

dbms_output.put_line('Dashes removed =

'

||

name);

END;

 

 

 

 

/

 

 

 

 

If its second and third arguments are null, REPLACE just returns its first argument.

Summary of PL/SQL Built-In Functions

PL/SQL provides many powerful functions to help you manipulate data. These built-in functions fall into the following categories:

error reporting number character

datatype conversion date

object reference miscellaneous

Table 2–3 shows the functions in each category. For descriptions of the error-reporting functions, see Chapter 13. For descriptions of the other functions, see Oracle Database SQL Reference.

Except for the error-reporting functions SQLCODE and SQLERRM, you can use all the functions in SQL statements. Also, except for the object-reference functions DEREF, REF, and VALUE and the miscellaneous functions DECODE, DUMP, and VSIZE, you can use all the functions in procedural statements.

2-28 PL/SQL User's Guide and Reference

Summary of PL/SQL Built-In Functions

Although the SQL aggregate functions (such as AVG and COUNT) and the SQL analytic functions (such as CORR and LAG) are not built into PL/SQL, you can use them in SQL statements (but not in procedural statements).

Fundamentals of the PL/SQL Language 2-29

Summary of PL/SQL Built-In Functions

Table 2–3 Built-In Functions

Error

Number Character

Conversion

Date

Obj Ref Misc

 

 

 

 

 

SQLCODE

ABS

ASCII

SQLERRM

ACOS

ASCIISTR

 

ASIN

CHR

 

ATAN

COMPOSE

 

ATAN2

CONCAT

 

BITAND

DECOMPOSE

 

CEIL

INITCAP

 

COS

INSTR

 

COSH

INSTR2

 

 

 

EXP

INSTR4

 

 

 

FLOOR

INSTRB

 

 

 

LN

INSTRC

 

 

 

LOG

LENGTH

 

 

 

MOD

LENGTH2

 

LENGTH4

 

 

 

POWER

LENGTHB

 

 

 

REMAIND

LENGTHC

 

ER

 

 

ROUND

LOWER

 

 

 

SIGN

LPAD

 

 

 

SIN

LTRIM

 

 

 

SINH

NCHR

 

 

 

SQRT

NLS_INITCAP

 

 

 

TAN

NLS_LOWER

 

 

 

TANH

NLSSORT

 

 

 

TRUNC

NLS_UPPER

 

 

 

 

REGEXP_INSTR

 

 

REGEXP_LIKE

 

 

REGEXP_REPLACE

 

 

REGEXP_SUBSTR

 

 

REPLACE

 

 

RPAD

 

 

RTRIM

 

 

SOUNDEX

 

 

SUBSTR

 

 

SUBSTR2

 

 

SUBSTR4

 

 

SUBSTRB

 

 

SUBSTRC

 

 

TRANSLATE

 

 

TRIM

 

 

UNISTR

 

 

UPPER

CHARTOROWID

ADD_MONTHS

DEREF

BFILENAME

CONVERT

CURRENT_DATE

REF

COALESCE

HEXTORAW

CURRENT_TIME

TREAT

DECODE

RAWTOHEX

CURRENT_TIMESTAMP

VALUE

DUMP

RAWTONHEX

DBTIMEZONE

 

EMPTY_BLOB

ROWIDTOCHAR

EXTRACT

 

EMPTY_CLOB

TO_BINARY_DOUBLE

FROM_TZ

 

GREATEST

TO_BLOB

LAST_DAY

 

LEAST

TO_BINARY_FLOAT

LOCALTIMESTAMP

 

NANVL

TO_CHAR

MONTHS_BETWEEN

 

NLS_CHARSET_DECL_LEN

TO_CLOB

NEW_TIME

 

NLS_CHARSET_ID

TO_DATE

NEXT_DAY

 

NLS_CHARSET_NAME

TO_MULTI_BYTE

NUMTODSINTERVAL

 

NULLIF

TO_NCHAR

NUMTOYMINTERVAL

 

NVL

TO_NCLOB

ROUND

 

SYS_CONTEXT

TO_NUMBER

SESSIONTIMEZONE

 

SYS_GUID

TO_SINGLE_BYTE

SYS_EXTRACT_UTC

 

UID

 

SYSDATE

 

USER

 

SYSTIMESTAMP

 

USERENV

 

TO_DSINTERVAL

 

VSIZE

 

TO_TIME

 

 

 

TO_TIME_TZ

 

 

 

TO_TIMESTAMP

 

 

 

TO_TIMESTAMP_TZ

 

 

 

TO_YMINTERVAL

 

 

 

TRUNC

 

 

 

TZ_OFFSET

 

 

2-30 PL/SQL User's Guide and Reference

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