NUMBER(p, s)p stands for precision (total number of digits) and s stands for scale (number of digits to the right of the decimal point). The p and s are optional. The default precision is 38 and the default scale is 0. The precision can range from 1 to 38 and the scale can range from -84 to 127. If a value exceeds the precision, Oracle will give an error. If it exceeds the scale, Oracle will round it.
Examples:
Input Data | Specified As | Stored As |
1,234.56 | NUMBER | 1234.56 |
1,234.56 | NUMBER(*,1) | 1234.6 |
1,234.56 | NUMBER(6) | 1235 |
1,234.56 | NUMBER(3,2) | (not accepted, exceeds precision) |
1,234.56 | NUMBER(6,2) | 1,234.56 |
1,234.56 | NUMBER(6,-2) | 1200 (round to left of decimal point) |
More examples are provided in the Appendix at the end of this set of
tutorials.
There is no such thing as a date literal. Instead, you must define
it as a character or a numeric value and then use the TO_DATE function
to convert it. A function called SYSDATE exists that returns the current
date and time.
DATE datatypes can be added or subtracted, but not multiplied or divided.
Other functions exist like ADD_MONTHS or MONTHS_BETWEEN that adds the number
of months to a DATE datatype or calculates the number of months in between
two dates, respectively. For more information, see the section on
Functions.
Group functions may ignore null, so be careful! For example, the average of (1000, null, null, null, 2000) is 1500 since (1000 + 2000)/2 = 1500.
Only two comparison operators exist for null. They are IS NULL and IS NOT NULL.
All of you should already know truth tables with TRUE and FALSE. Consider
NULL to be a third value. The NOT, AND, and OR truth tables for Oracle
appear at the end of this document.
Table 1. Default External Datatype
Assignments for C/C++ Types
C/C++ Type, or Pseudotype
(these can be used in a DECLARE SECTION) |
Oracle External
Type
(these cannot be used in a DECLARE SECTION; they are used by the precompiler) |
|
char, char[n], char*
|
VARCHAR2
CHARZ
STRING
CHARF
|
(DBMS=V6 default or CHAR_MAP=VARCHAR2)
(DBMS=V7, V8 default)
(CHAR_MAP=STRING)
(CHAR_MAP=CHARF) ***
|
int, int*
|
INTEGER
|
|
short, short*
|
INTEGER
|
|
long, long*
|
INTEGER
|
|
float, float*
|
FLOAT
|
|
double, double*
|
FLOAT
|
|
VARCHAR*,
VARCHAR[n]
|
VARCHAR
|
VARCHAR is the same as VARCHAR2 |
Source: Advanced
Topics. Pro*C/C++ Precompiler Programmer's Guide Release 8.1.6.
18 May 2001.
*** These are possible precompiler settings. For all versions
of Oracle 8, the default external datatype for char, char[n], and char*
is CHARZ.
Table 2. C/C++ Datatypes Normally
Used with each External Datatype
External Datatype | Code | C/C++ Datatype |
---|---|---|
VARCHAR2
|
1
|
char[n]
|
NUMBER
|
2
|
char[n] ( n <= 22)
|
INTEGER
|
3
|
int
|
FLOAT
|
4
|
float
|
STRING
|
5
|
char[n+1]
|
LONG
|
8
|
char[n]
|
VARCHAR
|
9
|
char[n+2]
|
DATE
|
12
|
char[n]
|
RAW
|
23
|
unsigned char[n]
|
LONG RAW
|
24
|
unsigned char[n]
|
CHAR
|
96
|
char[n]
|
CHARF (same as CHAR)
|
96
|
char[n]
|
CHARZ
|
97
|
char[n+1]
|
Source: Oracle
Dynamic SQL: Method 4. Pro*C/C++ Precompiler Programmer's
Guide Release 8.1.6. 18 May 2001.
Table 3. Implicit Conversion Possibilities
between Oracle External and Internal Datatypes
EXTERNAL
DATATYPES |
INTERNAL DATATYPES (these types are used for table columns) | ||||||
VARCHAR2 | NUMBER | LONG | DATE | RAW | LONG RAW | CHAR | |
---|---|---|---|---|---|---|---|
VARCHAR
|
I/O
|
I/O
|
I/O
|
I/O(1)
|
I/O(2)
|
I/O(2)
|
|
NUMBER
|
I/O(3)
|
I/O
|
I
|
|
I/O(3)
|
||
INTEGER
|
I/O(3)
|
I/O
|
I
|
I/O(3)
|
|||
FLOAT
|
I/O(3)
|
I/O
|
I
|
|
|
I/O(3)
|
|
STRING
|
I/O
|
I/O
|
I/O
|
I/O(1)
|
I/O(2)
|
I/O(2, 4)
|
I/O
|
LONG
|
I/O
|
I/O
|
I/O
|
I/O(1)
|
I/O(2)
|
I/O(2, 4)
|
I/O
|
VARCHAR
|
I/O
|
I/O
|
I/O
|
I/O(1)
|
I/O(2)
|
I/O(2, 4)
|
I/O
|
DATE
|
I/O
|
|
I
|
I/O
|
|
|
I/O
|
RAW
|
I/O(5)
|
|
I(4, 5)
|
I/O
|
I/O
|
I/O(5)
|
|
LONG RAW
|
O(5)
|
I(4, 5)
|
|
I/O
|
I/O
|
O(5)
|
|
CHAR
|
I/O
|
I/O
|
I/O
|
I/O(1)
|
I/O(2)
|
I(2)
|
I/O
|
CHARZ
|
I/O
|
I/O
|
I/O
|
I/O(1)
|
I/O(2)
|
I(2)
|
I/O
|
Notes:
(2) For input, host string must be in hex format.
(3) For output, column value must represent a valid number. (4) Length must be less than or equal to 2000. (5) On input, column value is stored in hex format.
|
Legend:
I = Conversion valid for input only (from external to internal)
O = Conversion valid for output only (from internal to
external)
I/O = Conversion valid for input or output
|
Source: Datatypes.
Oracle Call Interface Programmer's Guide Release 8.1.6. 18
May 2001.