AntDB-Oracle Compatibility Developer's Manual P3–2
Published: 2023-08-30 07:36:57


#### Constant

Constants of the type specified in the implicit state in AntDB are strings and values. We can also specify the type of constants explicitly, which allows for more precise representation of constants and also facilitates more efficient processing of constants by the system.

These alternative methods are discussed later in this section.

#### String Constants

A string constant in SQL is an arbitrary string enclosed in single quotes, for example, 'This is a string' is a string constant. If you want to include a single quote in a string constant, you need to write 2 consecutive single quotes, for example, 'Dianne''s horse'. Note that this is not the same as including double quotes.

##### Numerical Constants

The following are some of the numeric constants that can be used.

```
digits
digits.[digits][e[+-]digits]
[digits].digits[e[+-]digits]
digitse[+-]digits
```

Where digits is one or more digits (each digit ranges from 0 to 9). If a decimal point is used, then there must be at least one digit before or after the decimal point. If an exponential base(e) is present, then the base of the exponent must be followed by at least one digit. No spaces or characters other than those mentioned above may be embedded in the constant. Note that a positive or negative sign appearing before a constant is not part of the constant, but is just an operator on the constant.

The following are some examples of valid numeric constants.

```
42
3.5
4.
0.001
5e2
1.925e-3
```

If a numeric constant contains neither a decimal point nor an exponent, and its value matches the INTEGER type (32 bit), then the value is considered to be of type INTEGER in its initial state, and if its value matches the BIGINT type (64 bit), then it is considered to be of type BIGINT, otherwise it is treated as a NUMBER. We treat constants that contain decimal points or exponents as NUMBER types.

In the initial state, the data type assigned to a numeric constant is only the beginning of the type resolution algorithm. In most cases, the most appropriate data type is automatically assigned to the constant based on the usage environment. When necessary, the value of a numeric variable can be interpreted as the value of the specified data type by using what is described in the next section about assigning types.

##### Other types of constants

We can enter constants of any type using the following representation:

CAST('string' AS type)

To convert a constant to the type specified by type, the text of the string constant is passed to the input conversion section. The result of the conversion is a constant of the specified data type. If there is no ambiguity about the type of the constant (for example, directly assigning the constant to a data table column), then the explicit type assignment can be omitted.

CAST can also be used to specify the type conversion of arbitrary expressions at runtime.

#### Comments

A comment is a string starting with 2 dashes and continuing to the end of a line. For example:

```
-- This is a standard SQL comment
```

We can also use C-style comments:

```
/* multiline comment
* block
*/
```

Comments start with /\* and end when \*/ is encountered.

The comment is removed from the input SQL statement and replaced with a space before further syntax analysis is done.

### **Data Type**

The following table shows the commonly used built-in data types.

| Name| Alias| Description
|----------|----------|----------
| BLOB| | binary large object
| BOOLEAN| | Logical Boolean (true/false) type
| CHAR\[(n)]| CHARACTER\[(n)]| Fixed length for n string type
| CLOB| | String large objects
| DATE| | The compat parameter is a date-time type accurate to the second for oracle, and to the day in other cases
| DOUBLE PRECISION| FLOAT, FLOAT(25) – FLOAT(53), BINARY\_DOUBLE| Double precision floating point value type
| INTEGER| INT, BINARY\_INTEGER| Signed 4-byte length integer type
| NUMBER| DECIMAL, NUMERIC| Exact numeric type with decimal places
| NUMBER(p\[, s])| DECIMAL(p\[, s]),  NUMERIC(p\[, s])| Exact value type with maximum precision p using the value range s
| REAL| FLOAT(1) – FLOAT(24), BINARY\_FLOAT| Single precision floating point value type
| RAW\[(n)]| | Variable-length binary string type with maximum length n
| TIMESTAMP\[(p)]| | Date and time types that can be accurate to the second p
| VARCHAR2\[(n)]| CHAR VARYING\[(n)], CHARACTER VARYING\[(n)], VARCHAR\[(n)],  NVARCHAR2\[(n)]| Variable-length string types with a maximum length of n

Each of these data types is described in detail in the following sections.