Tuesday, March 26, 2013

V$RESERVED_WORDS

This was run on an Oracle 11.1 database. The v$reserved_words view lists Oracle's reserved words:

SQL> desc v$reserved_words
Name                       Null?    Type
-------------------------- -------- ------------------
KEYWORD                             VARCHAR2(30)
LENGTH                              NUMBER
RESERVED                            VARCHAR2(1)
RES_TYPE                            VARCHAR2(1)
RES_ATTR                            VARCHAR2(1)
RES_SEMI                            VARCHAR2(1)
DUPLICATE                           VARCHAR2(1)
 
SQL>

It has 1733 rows:

SQL> select count(*) from v$reserved_words
  2  /
 
  COUNT(*)
----------
      1733
 
SQL>

Of these, 2 contain null keywords:

SQL> select * from v$reserved_words
  2  where keyword is null
  3  /
 
KEYWORD                            LENGTH R R R R D
------------------------------ ---------- - - - - -
                                        0 Y N N N N
                                        0 N N N N N
 
SQL>

The remaining 1731 contain unique reserved words:

SQL> select count(distinct keyword)
  2  from v$reserved_words
  3  /
 
COUNT(DISTINCTKEYWORD)
----------------------
                  1731
 
SQL>

The length column records the length of the keyword. I'm not sure why you need this as you can get it yourself using the length function if you so desire:

SQL> select count(*) from v$reserved_words
  2  where keyword is not null
  3  and length = length(keyword)
  4  /
 
  COUNT(*)
----------
      1731
 
SQL>

The reserved column has values of Y and N:

SQL> select reserved, count(*)
  2  from v$reserved_words
  3  group by reserved
  4  /
 
R   COUNT(*)
- ----------
Y        100
N       1633
 
SQL>

If reserved is N, you can use the keyword as an identifier:

SQL> select keyword
  2  from v$reserved_words
  3  where keyword is not null
  4  and rownum < 11
  5  and reserved = 'N'
  6  /
 
KEYWORD
------------------------------
}
NOMONITORING
SYS_OP_VECXOR
GLOBAL
INFORMATIONAL
SEQUENCED
TIMES
SYS_OP_XPTHATG
PENDING
EXPLOSION
 
10 rows selected.
 
SQL> create table global (col1 number)
  2  /
 
Table created.
 
SQL>

Conversely, if reserved is Y, you cannot use the keyword as an identifier:

SQL> select keyword
  2  from v$reserved_words
  3  where keyword is not null
  4  and rownum < 11
  5  and reserved = 'Y'
  6  /
 
KEYWORD
------------------------------
FLOAT
TRIGGER
START
CONNECT
TABLE
DROP
ELSE
SYNONYM
DECIMAL
SIZE
 
10 rows selected.
 
SQL> create table decimal (col1 number)
  2  /
create table decimal (col1 number)
             *
ERROR at line 1:
ORA-00903: invalid table name
 
SQL>

No comments:

Post a Comment