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;