Introducing PL/SQL to SQL Users

Introducing PL/SQL to SQL Users

Author:Djoni Darmawikarta
Language: eng
Format: mobi
Published: 2015-12-13T22:00:00+00:00


Other data types frequently used are: INT (for storing integer), CHAR (for fixed length character string), VARCHAR2 (for variable length string), and DATE.

In the following example, we also declare reduced_price variable.

Its data type is the same as that of the price_avg.

In the Executable part, reduced_price is assigned the result of price_avg * 0.05.

We use the := operator (colon equal-sign) to assign a variable on its left with the value on its right, as in the example.

DECLARE

price_avg NUMBER(6,2);

reduced_price price_avg%type;

BEGIN

UPDATE prod SET unit_price = unit_price + 1 WHERE unit_price < 2;

SELECT AVG (unit_price) INTO price_avg FROM prod ;

dbms_output.put_line (price_avg);

IF price_avg > 1.5 THEN

ROLLBACK;

reduced_price := price_avg * 0.05;

UPDATE prod SET unit_price = reduced_price + 1 WHERE unit_price < 2;

ELSE

COMMIT;

END IF;

END;



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.