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

Lexical Units

t2 TIMESTAMP WITH TIME ZONE := TIMESTAMP ’1997-01-31 09:26:56.66 +02:00’;

--Three years and two months

--(For greater precision, we would use the day-to-second interval) i1 INTERVAL YEAR TO MONTH := INTERVAL ’3-2’ YEAR TO MONTH;

--Five days, four hours, three minutes, two and 1/100 seconds

i2 INTERVAL DAY TO SECOND := INTERVAL ’5 04:03:02.01’ DAY TO SECOND;

You can also specify whether a given interval value is YEAR TO MONTH or DAY TO SECOND. For example, current_timestamp - current_timestamp produces a value of type INTERVAL DAY TO SECOND by default. You can specify the type of the interval using the formats:

(interval_expression) DAY TO SECOND

(interval_expression) YEAR TO MONTH

For details on the syntax for the date and time types, see the Oracle Database SQL Reference. For examples of performing date/time arithmetic, see Oracle Database Application Developer's Guide - Fundamentals.

Comments

The PL/SQL compiler ignores comments, but you should not. Adding comments to your program promotes readability and aids understanding. Generally, you use comments to describe the purpose and use of each code segment. PL/SQL supports two comment styles: single-line and multi-line.

Single-Line Comments

Single-line comments begin with a double hyphen (--) anywhere on a line and extend to the end of the line. A few examples follow:

DECLARE

howmany NUMBER;

 

 

BEGIN

 

 

-- begin processing

 

 

SELECT count(*) INTO

howmany FROM user_objects

WHERE object_type

= 'TABLE'; -- Check number of tables

howmany := howmany *

2;

-- Compute some other value

END;

 

 

/

 

 

Notice that comments can appear within a statement at the end of a line.

While testing or debugging a program, you might want to disable a line of code. The following example shows how you can "comment-out" the line:

-- DELETE FROM employees WHERE comm_pct IS NULL;

Multi-line Comments

Multi-line comments begin with a slash-asterisk (/*), end with an asterisk-slash (*/), and can span multiple lines. Some examples follow:

DECLARE

some_condition BOOLEAN;

pi NUMBER := 3.1415926; radius NUMBER := 15; area NUMBER; BEGIN

/* Perform some simple tests and assignments */ IF 2 + 2 = 4 THEN

some_condition := TRUE; /* We expect this THEN to always be done */

Fundamentals of the PL/SQL Language 2-7

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