Вы находитесь на странице: 1из 15

Data Types

This section describes the data types used in the SAP HANA database.
Data type specifies the characteristics of a data value. A special value of NULL is included in every data
type to indicate the absence of a value. The following table shows the built-in data types available in the
SAP HANA database.
Classification of Data Types
Datetime Types
Date Formats
Time Formats
Timestamp Formats
Additional Formats
Supported Functions for Date/Time types
Numeric Types
Character String Types
Binary Types
Large Object (LOB) Types
Mapping between SQL Data Type and Column Store Data Type
Data Type Conversion
Typed Constant
Classification of Data Types
In the SAP HANA database each data type can be classified by its characteristic as follows:
Table 1: Table 2: Classification of data types
Classification Data Type
Datetime types DATE, TIME, SECONDDATE, TIMESTAMP
Numeric types TINYINT, SMALLINT, INTEGER, BIGINT,
SMALLDECIMAL, DECIMAL, REAL, DOUBLE
Character string types VARCHAR, NVARCHAR, ALPHANUM, SHORTTEXT
Binary types VARBINARY
Large Object types BLOB, CLOB, NCLOB, TEXT
The Best-Run Businesses Run SAP
SAP In-Memory Computing SAP HANA SAP HANA Platform SPS 08
Datetime Types
DATE
The DATE data type consists of year, month, and day information to represent a date value. The
default format for the DATE data type is 'YYYY-MM-DD'. YYYY represents the year, MM
represents the month, and DD represents the day. The range of date value is 0001-01-01 through
9999-12-31.
TIME
The TIME data type consists of hour, minute, and second to represent a time value. The default
format for the TIME data type is 'HH24:MI:SS'. HH24 represents the hour from 0 to 24, MI
represents the minute from 0 to 59, SS represents the second from 0 to 59.
SECONDDATE
The SECONDDATE data type consists of year, month, day, hour, minute and second information
to represent a date with time value. The default format for the SECONDDATE data type is 'YYYY-
MM-DD HH24:MI:SS'. YYYY represents the year, MM represents the month, DD represents the
day, HH24 represents hour, MI represents minute, and SS represents seconds. The range of date
value is 0001-01-01 00:00:01 through 9999-12-31 24:00:00.
TIMESTAMP
The TIMESTAMP data type consists of date and time information. Its default format is 'YYYY-MM-
DD HH24:MI:SS.FF7'. FFn represents the fractional seconds where n indicates the number of
digits in fractional part. . The range of the timestamp value is 0001-01-01 00:00:00.0000000 through
9999-12-31 23:59:59.9999999.
For all Datetime Types, there is an ABAP-specific special value 'EMPTY'. It is different from NULL. For
instance, ADD_DAYS('00000000', 1) returns 0001-01-02. It is ABAP's behavior. HANA introduced it for
harmonization with ABAP.
For details on supported formats for datetime types, refer to Table 4, Table 5, Table 6 and Table 7 below.
Date Formats
The following date/time formats can be used when parsing a string into a date/time type and converting a
date/time type value into a string value. Please note that format for Timestamp is the combination of Date
and Time with the additional support for fractional seconds.
Table 2: Table 4: Supported formats for Date
Format Description Examples
YYYY-MM-DD Default format INSERT INTO my_tbl VALUES
('1957-06-13');
YYYY/MM/DD
YYYY/MM-DD
YYYY-MM/DD
YYYY from 0001 to 9999, MM from 1
to 12, DD from 1 to 31. If year has
less than four digits, month has
less than two digits, or day has
less than two digits, then values
will be padded by one or more
zeros. For example, a two digit year
45 will be saved as year 0045, a
one digit month 9 will be saved as
INSERT INTO my_tbl VALUES
('1957-06-13');
INSERT INTO my_tbl VALUES
('1957/06/13');
INSERT INTO my_tbl VALUES
('1957/06-13');
INSERT INTO my_tbl VALUES
('1957-06/13');
09, and a one digit day 2 will be
saved as 02.
YYYYMMDD ABAP Data Type, DATS format. INSERT INTO my_tbl VALUES
('19570613');
MON Abbreviated name of month. (JAN. ~
DEC.)
INSERT INTO my_tbl VALUES
(TO_DATE('2040-Jan-10', 'YYYY-
MON-DD'));
INSERT INTO my_tbl VALUES
(TO_DATE('Jan-10', 'MON-DD'));
MONTH Name of month. (JANUARY -
DECEMBER).
INSERT INTO my_tbl VALUES
(TO_DATE('2040-January-10',
'YYYY-MONTH-DD'));
INSERT INTO my_tbl VALUES
(TO_DATE('January-10', 'MONTH-
DD'));
RM Roman numeral month (I-XII; JAN =
I).
INSERT INTO my_tbl VALUES
(TO_DATE('2040-I-10', 'YYYY-RM-
DD'));
INSERT INTO my_tbl VALUES
(TO_DATE('I-10', 'RM-DD'));
DDD Day of year (1-366). INSERT INTO my_tbl VALUES
(TO_DATE('204', 'DDD'));
INSERT INTO my_tbl VALUES
(TO_DATE('2001-204','YYYY-
DDD'));
Time Formats
Table 3: Table 5: Supported formats for Time
Format Description Examples
HH24:MI:SS Default format
HH:MI[:SS][AM|PM]
HH12:MI[:SS][AM|PM]
HH24:MI[:SS]
HH from 0 to 23. MI from 0 to 59. SS
from 0 to 59. FFF from 0 to 999.
If one digit hour, minute, second is
specified, then 0 will be inserted
into the value. For example, 9:9:9
will be saved as 09:09:09.
HH12 indicates 12 hour clock and
HH24 indicates 24 hour clock.
AM or PM can be specified as a
suffix to indicate the time value is
before or after noon.
INSERT INTO my_tbl VALUES
('23:59:59');
INSERT INTO my_tbl VALUES
('3:47:39 AM');
INSERT INTO my_tbl VALUES
('9:9:9 AM');
INSERT INTO my_tbl VALUES
(TO_TIME('11:59:59','HH12:MI:SS');
SSSSS Seconds past midnight (0-86399). INSERT INTO my_tbl VALUES
(TO_TIME('12345', 'SSSSS'));
Timestamp Formats
Table 4: Table 6: Supported formats for Timestamp
Format Description Examples
YYYY-MM-DD HH24:MI:SS.FF7 Default format
FF [1..7] Fractional seconds has the range 1
to 7 after the FF parameter to
specify the number of digits in the
fractional second portion of the date
time value returned. If a digit is not
specified, the default value is used.
INSERT INTO my_tbl VALUES
(TO_TIMESTAMP('2011-05-11
12:59.999','YYYY-MM-DD
HH:SS.FF3'));
Additional Formats
Table 5: Table 7: Additional formats for Datetime
Format Description Example
D Day of week (1-7). TO_CHAR(CURRENT_TIMESTAMP
,'D')
DAY Name of day (MONDAY - SUNDAY). TO_CHAR(CURRENT_TIMESTAMP
,'DAY')
DY Abbreviated name of day (MON -
SUN).
TO_CHAR(CURRENT_TIMESTAMP
,'DY')
MON Abbreviated month name (JAN -
DEC)
TO_CHAR(CURRENT_TIMESTAMP
,'MON')
MONTH Full month name (JANUARY -
DECEMBER)
TO_CHAR(CURRENT_TIMESTAMP
,'MONTH')
RM Roman numeral month (I - XII; I is
for January)
TO_CHAR(CURRENT_TIMESTAMP
,'RM')
Q Quarter of year (1, 2, 3, 4) TO_CHAR(CURRENT_TIMESTAMP
,'Q')
W Week of month (1-5). TO_CHAR(CURRENT_TIMESTAMP
,'W')
WW Week of year (1-53). TO_CHAR(CURRENT_TIMESTAMP
,'WW')
Supported Functions for Date/Time types
ADD_DAYS
ADD_MONTHS
ADD_SECONDS
ADD_YEARS
COALESCE
CURRENT_DATE
CURRENT_TIME
CURRENT_TIMESTAMP
CURRENT_UTCDATE
CURRENT_UTCTIME
CURRENT_UTCTIMESTAMP
DAYNAME
DAYOFMONTH
DAYOFYEAR
DAYS_BETWEEN
EXTRACT
GREATEST
HOUR
IFNULL
ISOWEEK
LAST_DAY
LEAST
LOCALTOUTC
MINUTE
MONTH
MONTHNAME
NEXT_DAY
NULLIF
QUARTER
SECOND
SECONDS_BETWEEN
TO_DATE
TO_DATS
TO_TIME
TO_TIMESTAMP
UTCTOLOCAL
WEEK
WEEKDAY
YEAR
Numeric Types
Note
Each numeric type below has the maximum value and the minimum value. A numeric overflow
exception will be thrown if a value is smaller than the minimum value or greater than the maximum
value. NaN and infinity are not supported, which is IEEE754 compliance. -0.0 is stored as +0.0.
TINYINT
The TINYINT data type stores an 8-bit unsigned integer. The minimum value is 0 and the maximum
value is 255 for TINYINT.
SMALLINT
The SMALLINT data type stores a 16-bit signed integer. The minimum value is -32,768 and the
maximum value is 32,767 for SMALLINT.
INTEGER
The INTEGER data type stores a 32-bit signed integer. The minimum value is -2,147,483,648 and
the maximum value is 2,147,483,647 for INTEGER.
BIGINT
The BIGINT data type stores a 64-bit signed integer. The minimum value is
-9,223,372,036,854,775,808 and the maximum value is 9,223,372,036,854,775,807 for BIGINT.
DECIMAL(precision, scale) or DEC(p,s)
DECIMAL(p, s) is the SQL standard notation for fixed-point decimal. "p" specifies precision or the
number of total digits (the sum of whole digits and fractional digits). "s" denotes scale or the
number of fractional digits. For example, if a column is defined as DECIMAL(5, 4), the numbers
3.14, 3.1415, 3.141592 are stored in the column as 3.1400, 3.1415, 3.1415, respectively keeping
the specified precision(5) and scale(4).
The precision p, can range from 1 to 38. The scale can range from 0 to p. If the scale is not
specified, it defaults to 0.
When precision and scale are not specified, DECIMAL becomes a floating-point decimal number.
In this case, precision and scale can vary within the range 1 to 34 for precision and -6,111 to 6,176
for scale depending on the stored value.
Examples: 0.0000001234 (1234E-10) has the precision 4 and the scale 10. 1.0000001234
(10000001234E-10) has the precision 11 and scale 10. 1234000000 (1234E6) has the precision 4
and scale -6.
When precision and scale are not specified, DECIMAL becomes a floating-point decimal number.
In this case, precision and scale can vary within the range described above, 1~34 for precision and
-6,111~6,176 for scale depending on the stored value.
SMALLDECIMAL
The SMALLDECIMAL is a floating-point decimal number. The precision and scale can vary within
the range, 1~16 for precision and -369~368 for scale depending on the stored value.
SMALLDECIMAL is supported only on column store.
DECIMAL and SMALLDECIMAL are floating-point types. For instance, a decimal column can
store any of 3.14, 3.1415, 3.141592 whilst maintaining their precision.
DECIMAL(p, s) is the SQL standard notation for fixed-point decimal. For instance, 3.14, 3.1415,
3.141592 are stored in a decimal(5, 4) column as 3.1400, 3.1415, 3.1415, respectively keeping the
specified precision(5) and scale(4).
REAL
The REAL data type specifies a single-precision 32-bit floating-point number.
DOUBLE
The DOUBLE data type specifies a single-precision 64-bit floating-point number. The minimum
value is -1.7976931348623157E308 and the maximum value is 1.7976931348623157E308 . The
smallest positive DOUBLE value is 2.2250738585072014E-308 and the largest negative DOUBLE
value is -2.2250738585072014E-308.
REAL and DOUBLE types are stored in the system using binary numbers. The fractional part of
these numbers are represented using a combination of 1/2, 1/4, 1/8, 1/16, and so on. For this
reason they cannot completely represent rational numbers with fractional digits. For example, 0.1
cannot be represented exactly by combining these binary fractions, in this case you will get
inexact results when using the DOUBLE or REAL type. This is not an issue with the SAP HANA
database, this is the correct behavior for these data types. For a demonstration of this property of
these data types in action please see the example below.
SELECT TO_DOUBLE(0.1) + TO_DOUBLE(4.6) AS DOUBLE_SUM FROM DUMMY;
DOUBLE_SUM
4.6999999999
FLOAT(n)
The FLOAT(n) data type specifies a 32-bit or 64-bit real number, where n specifies the number of
significant bits and can range between 1 and 53.
When you use the FLOAT(n) data type, if n is smaller than 25, it becomes a 32-bit REAL data
type. If n is greater than or equal to 25, it then becomes a 64-bit DOUBLE data type. If n is not
declared, it becomes a 64-bit double data type by default.
Character String Types
The character string data types are used to store values that contain character strings. While VARCHAR
data types contain ASCII character strings, NVARCHAR are used for storing Unicode character strings.
Note
Collation expressions are not supported, and string-typed values are compared using a binary
comparison.
VARCHAR
The VARCHAR(n) data type specifies a variable-length character string, where n indicates the
maximum length in bytes and is an integer between 1 and 5000.
When the VARCHAR(n) data type is used in a DML query, for example CAST (A as
VARCHAR(n)), n indicates the maximum length in of the string in characters. For reason SAP
recommends only using VARCHAR with ASCII characters based strings. If the data you wish to
store contains characters other than ASCII characters, SAP recommends using NVARCHAR data
type instead.
NVARCHAR
The NVARCHAR(n) data type specifies a variable-length Unicode character set string, where n
indicates the maximum length in characters and is an integer between 1 and 5000.
ALPHANUM
The ALPHANUM(n) data type specifies a variable-length character string which contains alpha-
numeric characters, where n indicates the maximum length and is an integer between 1 and 127.
Note
Sorting among ALPHANUM typed values is done in alpha-representation. That is, in case of a
purely numeric value, the value can be considered as an alpha value with leading zeros.
SHORTTEXT
The SHORTTEXT(n) data type specifies variable-length character string which supports
textsearch-features and stringsearch-features. This data type cannot be defined for row tables, but
for column tables. This is not a standalone sql-type. Selecting a SHORTTEXT(n)-column yields a
column of type NVARCHAR(n).
<shorttext_type> ::= SHORTTEXT ( <unsigned_integer> )
<elem_list_shorttext>
<elem_list_shorttext> ::= <fulltext_elem> [{, <fulltext_elem>}...]
Binary Types
Binary types are used to store bytes of binary data.
Note
A binary typed value can be converted to (N)VARCHAR typed value if its size is smaller than or equal
to 8192. Hence, it can be used like a (N)VARCHAR typed value except for fulltext search operations
and numeric operations.
VARBINARY
The VARBINARY(n) data type is used to store binary data of a specified maximum length in
bytes, where n indicates the maximum length and is an integer between 1 and 5000.
Large Object (LOB) Types
LOB (large objects) data types, CLOB, NCLOB and BLOB, are used to store a large amount of data
such as text documents and images. The maximum size of an LOB is 2 GB.
BLOB
The BLOB data type is used to store large binary data.
CLOB
The CLOB data type is used to store large ASCII character data.
NCLOB
The NCLOB data type is used to store a large Unicode character object.
TEXT
The TEXT data type specifies which supports textsearch-features. This data type cannot be defined
for row tables, but for column tables. This is not a standalone sql-type. Selecting a TEXT-column
yields a column of type NCLOB.
Note
A TEXT typed value cannot be converted to (N)VARCHAR typed value implicitly, and string
functions (i.e., UPPER, LOWER, ...) cannot be applied to a TEXT typed value directly.
However, explicit conversion from a TEXT typed value to a (N)VARCHAR typed value is allowed.
That is, string functions can be applied to the converted value.
For columns of type TEXT the LIKE predicate is not supported.
<text_type> ::= TEXT <opt_fulltext_elem_list_text>
<opt_fulltext_elem_list_text> ::= <fulltext_elem> [{,
<fulltext_elem>}...]
BINTEXT
The BINTEXT data type is similar to data type TEXT, i.e. supports textsearch-features, but it is
possible to insert binary data. This data type cannot be defined for row tables, but for column
tables. This is not a standalone sql-type. Selecting a BINTEXT-column yields a column of type
NCLOB.
Note
For a BINTEXT typed value the same restrictions as for a TEXT typed value apply.
<bintext_type> ::= BINTEXT <opt_fulltext_elem_list_bintext>
<opt_fulltext_elem_list_bintext> ::= <fulltext_elem> [{,
<fulltext_elem>}...]
Syntax-rules common to TEXT, BINTEXT and SHORTTEXT
<fulltext_elem> ::= LANGUAGE COLUMN <column_name>
| LANGUAGE DETECTION ( <string_literal_list> )
| MIME TYPE COLUMN <column_name>
| <change_tracking_elem>
| FUZZY SEARCH INDEX <on_off>
| PHRASE INDEX RATIO <index_ratio>
| CONFIGURATION <string_literal>
| SEARCH ONLY <on_off>
| FAST PREPROCESS <on_off>
| TEXT ANALYSIS <on_off>
| MIME TYPE <string_literal>
| TOKEN SEPARATORS <string_literal>
<change_tracking_elem> ::= SYNC[HRONOUS]
| ASYNC[HRONOUS] [FLUSH [QUEUE]
<flush_queue_elem>]
<flush_queue_elem> ::= EVERY <integer_literal> MINUTES
| AFTER <integer_literal> DOCUMENTS
| EVERY <integer_literal> MINUTES OR AFTER
<integer_literal> DOCUMENTS
LOB types are provided for storing and retrieving such large data. CLOB and NCLOB typed values can be
converted to VARCHAR and NVARCHAR typed values, respectively. BLOB typed values can be
converted to VARBINARY typed values. LOB types support the following operations.
LENGTH() function for CLOB/NCLOB/BLOC typed values, which returns the LOB length in bytes.
SUBSTR() function for CLOB/NCLOB typed values, which returns the substring of a (N)CLOB
value.
COALESCE() function
LIKE and CONTAINS predicate for CLOB/NCLOB typed values
IS NULL predicate for CLOB/NCLOB/BLOB typed values
The LOB types have the following restrictions:
LOB columns cannot appear in ORDER BY or GROUP BY clauses.
LOB columns cannot appear in FROM clauses as a join predicate.
LOB columns cannot appear in WHERE clauses as a predicate except LIKE (i.e., no comparison
is allowed).
LOB columns cannot appear in SELECT clauses as an aggregate function argument.
LOB columns cannot appear in SELECT DISTINCT clauses.
LOB columns cannot be used in set operations such as EXCEPT. UNION ALL is an exception.
LOB columns cannot be used as a primary key.
LOB columns cannot be used in CREATE INDEX statements.
LOB columns cannot be used in statistics update statements.
Mapping between SQL Data Type and Column Store Data Type
SQL Type Column Store Type
Integer Types TINYINT, SMALLINT, INT CS_INT
BIGINT CS_FIXED(18,0)
Approximate Types REAL CS_FLOAT
DOUBLE CS_DOUBLE
FLOAT CS_DOUBLE
FLOAT(p) CS_FLOAT, CS_DOUBLE
Decimal Types DECIMAL CS_DECIMAL_FLOAT
DECIMAL(p,s) CS_FIXED(p-s,s)
SMALLDECIMAL CS_SDFLOAT
Character Types VARCHAR CS_STRING
NVARCHAR CS_STRING
CLOB, NCLOB CS_STRING
ALPHANUM CS_ALPHANUM
Binary Types BLOB CS_RAW
VARBINARY CS_RAW
Date/Time Types DATE CS_DAYDATE
TIME CS_SECONDTIME
TIME CS_SECONDTIME
TIMESTAMP CS_LONGDATE
SECONDDATE CS_SECONDDATE
Data Type Conversion
This section describes the data type conversion allowed in SAP HANA database.
Explicit type conversion
The type of an expression result, for example a field reference, a function on fields, or literals can
be converted using the following functions: CAST, TO_ALPHANUM, TO_BIGINT, TO_VARBINARY,
TO_BLOB, TO_CLOB, TO_DATE, TO_DATS, TO_DECIMAL, TO_DOUBLE, TO_INTEGER,
TO_INT, TO_NCLOB, TO_NVARCHAR, TO_REAL, TO_SECONDDATE, TO_SMALLINT,
TO_TINYINT, TO_TIME, TO_TIMESTAMP, TO_VARCHAR.
Implicit type conversion
When a given set of operand/argument types does not match what an operator/function expects, a
type conversion is carried out by the SAP HANA database. This conversion only occurs if a
relevant conversion is available and if it makes the operation/function executable. For instance, a
comparison of BIGINT and VARCHAR is performed by implicitly converting VARCHAR to BIGINT.
The entire explicit conversions can be used for implicit conversion except for the TIME and
TIMESTAMP data types. TIME and TIMESTAMP can be converted to each other using
TO_TIME(TIMESTAMP) and TO_TIMESTAMP(TIME).
Examples
Table 6: Table 8: Implicit Type conversion Examples
Input Expression Transformed Expression with Implicit
Conversion
BIGINT > VARCHAR BIGINT > BIGINT(VARCHAR)
BIGINT > DECIMAL DECIMAL(BIGINT) > DECIMAL
TIMESTAMP > DATE TIMESTAMP > TIMESTAMP(DATE)
DATE > TIME Error because there is no conversion available
between DATE and TIME
In the tables below,
Boxes with "OK" means data type conversions are allowed without any checks.
Boxes with "CHK" means the data type can be converted if the data is valid for the target type.
Boxes with "-" indicates that data type conversion is not allowed.
Conversion types
Numeric types to Numeric types: Least significant digits are truncated toward 0. Most
significant digits cannot be cut. Such cases lead to the overflow error.
DECIMAL(10,2) -> BIGINT : 12345.67 -> 12345
Character types to Numeric types: No truncation allowed, overflow error or invalid number
error can be returned
VARCHAR -> BIGINT : "12345.67" -> invalid number error
returned
VARCHAR -> TINYINT : "256" -> overflow error returned
Date/Time types to Date/Time types: Truncated to the target type when source types are
larger types, otherwise default value is added
TIMESTAMP -> DATE : 2013-07-03 01:23:45 123456789 -> 2013-07-
03
DATE -> TIMESTAMP : 2013-07-03 -> 2013-07-03 00:00:00
000000000
TIMESTAMP -> SECONDDATE : 2013-07-03 23:59:59 7777777 -> 2013-
07-03 23:59:59
Character types to Date/Time types: Truncated to the target type, invalid DATE, TIME of
TIMESTAMP error can be returned
VARCHAR -> DATE : "2013-07-03 00:00:00 000000000" -> 2013-07-
03
The rules shown are applicable to both implicit and explicit conversion except for Time to Timestamp
conversion. Only explicit conversions are allowed for converting the Time data type to Timestamp using
the TO_TIMESTAMP or CAST functions.
Table 7: Table 9a: Data type conversion table
Target/
Source
tinyint smallin
t
integer bigint decima
l
decima
l(p,s)
smalld
ecimal
real double varcha
r
nvarch
ar
tinyint - OK OK OK OK OK OK OK OK OK OK
smallin
t
CHK - OK OK OK OK OK OK OK OK OK
integer CHK CHK - OK OK OK OK OK OK OK OK
bigint CHK CHK CHK - OK CHK CHK CHK OK OK OK
decima
l
CHK CHK CHK CHK - CHK CHK CHK OK OK OK
decima
l(p,s)
CHK CHK CHK CHK CHK CHK CHK CHK CHK OK OK
smalld
ecimal
CHK CHK CHK CHK OK CHK - CHK CHK OK OK
real CHK CHK CHK CHK OK CHK CHK - OK OK OK
double CHK CHK CHK CHK CHK CHK CHK CHK - OK OK
varchar CHK CHK CHK CHK CHK CHK CHK CHK CHK - OK
nvarch
ar
CHK CHK CHK CHK CHK CHK CHK CHK CHK OK -
Table 8: Table 9b: Data type conversion table
Target/
Source
time date seconddate timestamp varchar nvarchar
Source
time - - - - OK OK
date - - OK OK OK OK
seconddate time date - timestamp OK OK
timestamp time date seconddate - OK OK
varchar CHK CHK CHK CHK - OK
nvarchar CHK CHK CHK CHK OK -
Table 9: Table 9c: Data type conversion table
Target/
Source
varbinary alphanum varchar nvarchar
varbinary - - - -
alphanum - - OK OK
varchar OK OK - OK
nvarchar OK OK OK -
Data Type Precedence
This section describes the data type precedence implemented by the SAP HANA database. Data type
precedence specifies that the data type with lower precedence is converted to the data type with higher
precedence.
Highest TIMESTAMP
SECONDDATE
DATE
TIME
DOUBLE
REAL
DECIMAL
SMALLDECIMAL
BIGINT
INTEGER
SMALLINT
TINYINT
NCLOB
NVARCHAR
CLOB
VARCHAR
BLOB
Lowest VARBINARY
Typed Constant
A constant is a symbol that represents a specific fixed data value.
Character string constant
A character string constant is enclosed in single quotation marks.
'Brian'
'100'
Unicode string has a similar format to character string but is preceded by an N identifier (N stands
for National Language in the SQL-92 standard). The N prefix must be uppercase.
N'abc'
SELECT 'Brian' "character string 1", '100' "character string 2", N'abc'
"unicode string" FROM DUMMY;
character string 1, character string 2, unicode string
Brian, 100, abc
Number constant
A number constant is represented by a string of numbers that are not enclosed in quotation marks.
Numbers may contain a decimal point or scientific notation.
123
123.4
1.234e2
A hexadecimal number constant is a string of hexadecimal numbers and has the prefix 0x.
0x0abc
SELECT 123 "integer", 123.4 "decimal1", 1.234e2 "decimal2", 0x0abc
"hexadecimal" FROM DUMMY;
integer, decimal1, decimal2, hexadecimal
123, 123.4, 123.4, 2748
Binary string constant
A binary string has the prefix X and is a string of hexadecimal numbers that are enclosed in
quotation marks.
X'00abcd'
x'dcba00'
SELECT X'00abcd' "binary string 1", x'dcba00' "binary string 2" FROM
DUMMY;
binary string 1, binary string 2
00ABCD, DCBA00
Date/Time/Timestamp constant
Date, Time and Timestamp each have the following prefixes.
date'2010-01-01'
time'11:00:00.001'
timestamp'2011-12-31 23:59:59'
SELECT date'2010-01-01' "date", time'11:00:00.001' "time",
timestamp'2011-12-31 23:59:59' "timestamp" FROM DUMMY;
date, time, timestamp
2010-01-01, 11:00:00, 2011-12-31 23:59:59.0
COPYRI GHT BY SAP SE OR AN SAP AFFI LI ATE COMPANY. ALL RI GHTS RESERVED.
PRI NTED FROM SAP HELP PORTAL. (ht t p: / / hel p. sap. com)

Вам также может понравиться