home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

6.5 The Predefined Datatypes

The PLV package provides several centrally located, predefined datatypes. These elements are used throughout PL/Vision, but you can make use of them as well.

The two variables that are to be used as predefined datatypes are the following:

plsql_identifier VARCHAR2(100) := 'IRRELEVANT';
max_varchar2 VARCHAR2(32767) := 'IRRELEVANT';

Use the plsql_identifier variable whenever you need to declare a VARCHAR2 variable or constant that holds a PL/SQL identifier, such as a table name or column name or program name. Currently these names are limited to 30 characters. That may, however, change in the future and you will find errors popping up in your utilities if you declare variables like this:

v_table_name VARCHAR2(30);

Instead, use the predefined datatype as follows:

v_table_name PLV.plsql_identifier%TYPE;

Use the max_varchar2 variable whenever you need to declare a string variable to the maximum number of characters allowable in PL/SQL . Again, today that maximum size is 32,767, but this value may increase in the future. By relying on max_varchar2 in your declarations and parameter definitions, you (or the supplier of PL/Vision) can change the definition in one place and, with a compile, upgrade all your code.

NOTE: Do you notice any conflict between the declarations of these predefined datatypes and the best practices I described earlier in this book? I have declared variables in my package specification; the best practice recommends strongly that you always hide your data structures in the package body. At the very least, you might be thinking, I should make the plsql_identifier and max_varchar2 data structures constants, so their values cannot be changed.

Well, take a look at the default value for these variables. It doesn't matter what value is assigned to these variables. They are only to be used in %TYPE anchored declarations to pass on the datatype and constraint. And I couldn't make them CONSTANTs even if I wanted to (I tried that on the first pass). It turns out that you cannot anchor variables to constants; if you want to use %TYPE, you must remove the CONSTANT keyword.


Previous: 6.4 PLV Utilities Advanced Oracle PL/SQL Programming with Packages Next: 6.6 The Predefined Constants
6.4 PLV Utilities Book Index 6.6 The Predefined Constants

The Oracle Library Navigation

Copyright (c) 2000 O'Reilly & Associates. All rights reserved.

Library Home Oracle PL/SQL Programming, 2nd. Ed. Guide to Oracle 8i Features Oracle Built-in Packages Advanced PL/SQL Programming with Packages Oracle Web Applications Oracle PL/SQL Language Pocket Reference Oracle PL/SQL Built-ins Pocket Reference










??????????????@Mail.ru