Variables and Types


Variables declared within the DECLARE section of a PL/SQL block may only be referenced within that block. As you saw in the previous example, a variable declaration has both a name and a type. For example, the width variable was declared as:

 width INTEGER; 
Note  

The PL/SQL types are similar to the database column types. You can see all the available types in Appendix A.

The following example illustrates some more variable declarations that may be used to store the column values from the products table:

 product_id      INTEGER; product_type_id INTEGER; name            VARCHAR2(30); description     VARCHAR2(50); price           NUMBER(5, 2); 

You may also specify a variable s type using the %TYPE keyword, which tells PL/SQL to use the same type as a specified column in a table. The following example uses %TYPE to declare a variable of the same type as the price column of the products table, which is NUMBER(5, 2):

 product_price products.price%TYPE; 



Oracle Database 10g SQL
Oracle Database 10g SQL (Osborne ORACLE Press Series)
ISBN: 0072229810
EAN: 2147483647
Year: 2004
Pages: 217

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net