http://www.techonthenet.com/sql/index.php
One, character conversion function1, ASCII () returns the ASCII value of the leftmost character of the character expression. In the ASCII () function, a string of pure numbers is not "enclosed", but a string with other characters must be used in ' surround ', or an error will occur. 2, CHAR () converts the ASCII code to a character. If you do not enter an ASCII value between 0 and 255, CHAR () returns NULL. 3, LOWER () and UPPER () LOWER () convert all strings to lowercase, UPPER () capitalizes all strings. 4. STR () converts numeric data to character data. STR (<float_expression>[,length[, <decimal>]) length Specifies the length of the returned string, and decimal specifies the number of decimal digits to return. If the length is not specified, the default value is ten, and the decimal default is 0. Returns null when length or decimal is negative, when length is less than the number of digits to the left of the decimal point (including the sign bit), the length is followed by length, then decimal, and when the number of strings returned is less than length, the left side complements the space.
second, go to the space function1. LTRIM () Remove the space at the head of the string. 2. RTRIM () Remove the space at the trailing end of the string.
Three, take the SUBSTRING function1. Left (<CHARACTER_EXPRESSION>, <integer_expression>) return character_expression Integer_ An expression character. 2. Right (<CHARACTER_EXPRESSION>, <integer_expression>) return to character_expression Integer_ An expression character. 3, SUBSTRING () SUBSTRING (<expression>, <starting_ position>, length) returns from the left of the string starting_ position Characters character the length of a character.
Four, string comparison function1, CHARINDEX () returns the beginning of the occurrence of a specified substring in a string. CHARINDEX (< ' substring_expression ';, <expression>) where substring _expression is the character expression to look for, expressions Can be a string or a column-name expression. If no substring is found, a value of 0 is returned. This function cannot be used with text and image data types. 2, PATINDEX () returns the beginning of the occurrence of a specified substring in a string. PATINDEX (< '%substring _expression% ';, <column_ name>) where the substring expression must have a percent semicolon "%" or the return value is 0. Unlike the CHARINDEX function, wildcard characters can be used in substrings of the PATINDEX function, and this function can be used with char, VARCHAR, and text data types.
Five, string manipulation functions1, QUOTENAME () returns the string enclosed by a specific character. QUOTENAME (< ' character_expression ' >[, quote_ character]) where Quote_ character the character used to enclose the string, the default value is "[]". 2, REPLICATE () returns a string that repeats character_expression the specified number of times. REPLICATE (character_expression integer_expression) returns null if the Integer_expression value is negative. 3, REVERSE () reverses the character arrangement of the specified string. REVERSE (<character_expression>) where character_expression can be a string, a constant, or a column's value. 4, replace () returns the string that was replaced by the specified substring. REPLACE (<STRING_EXPRESSION1>, <string_expression2>, <string_expression3>) with String_expression3 Replace the substring string_expression2 in the string_expression1. 4, Space () returns a blank string with the specified length. SPACE (<integer_expression>) returns null if the Integer_expression value is negative. 5, STUFF () specifies the position, length of the substring with another substring substitution string. STUFF (<character_expression1>, <start_ Position>, <length>,<character_expression2>) A null value is returned if the starting position is negative or the length value is negative, or the starting position is greater than the length of character_expression1. If length is greater than start_ position in Character_expression1 to the right length, Character_expression1 retains only the first character.
VI. data type conversion Functions1, cast () cast (<expression> as <data_ type>[length]) 2, CONVERT () convert (<data_ type>[length], <ex pression> [, Style]) 1) data_type the data type defined for the SQL Server system, the user-defined data type cannot be used here. 2) length is used to specify how long the data is, and the default value is 30. 3) converts a char or varchar type to an integer type such as int or samllint, and the result must be a numeric value with a plus or minus sign. 4) The text type is converted to char or varchar type up to 8,000 characters, that is, the char or varchar data type is the maximum length. 5) The data stored by the image type is converted to binary or varbinary type, up to a maximum of 8,000 characters. 6) Convert integer value to Money or smallmoney type, processed in the currency unit of the defined country, such as RMB, USD, GBP, etc. 7) A bit type conversion converts a non-0 value to 1 and is still stored as a bit type. 8) attempts to convert to a different length of data type will truncate the conversion value and display "+" after the value is converted to identify the truncation occurred. 9) Use the style option of the CONVERT () function to display the date and time in a different format. The style is the conversion style number that is provided by the SQL Server system when converting Datatime and smalldatetime data to strings, and different style numbers have different output formats.
Seven, date function1, Day (date_expression) returns the Date value 2 in Date_expression, month (date_expression) returns the month value in Date_expression 3, year (Date_ expression) returns the year value in Date_expression 4, DATEADD () DATEADD (<datepart>, <number>, <date>) returns the date specified Adds a new date that is generated by the specified extra date interval number. 5, DATEDIFF () DATEDIFF (<datepart>, <date1>, <date2>) returns the difference in DatePart of two specified dates, that is, Date2 exceeds the date1 gap value, The result value is an integer value with a positive sign. 6, Datename () datename (<datepart>, <date>) returns the specified part of the date as a string in this section. specified by DatePart. 7, DATEPART () DATEPART (<datepart>, <date>) returns the specified part of the date as an integer value. This section is specified by DatePart. DATEPART (dd, date) equates to day (date) DATEPART (mm, date) equivalent to month (date) DATEPART (yy, date) equivalent to year (date) 8, GETDATE () to Dateti The default format for ME returns the current date and time of the system 9, Oracle data type change function: To_char (), To_date (), To_number (), etc., if only take the year, month, day, etc., can use To_char (sysdate, ' YYYY '), to _char (' MM '), To_char (' DD ') obtained. Only take the date trunc (sysdate), take the time division seconds To_char (sysdate, ' HH24:MI:SS ').
DB2 Data type change function: char (), varchar (), int (), date (), Time (), and so on: year, month, day, and so on (current timestamp), month (current timestamp), Timestamp, HOUR (current timestamp), MINUTE (current timestamp), SECOND (current timestamp), microsecond ( Current timestamp); only date (current timestamp) can be used to take time (current timestamp). char () is a fixed-length string (1-255), varchar () is a non-fixed-length string (1-32672) date, the time pattern becomes a character pattern: char (current date), and char (time) converts the string into a date or a temporal pattern: TIMESTAMP (' 2002-10-2012:00:00 '), date (' 2002-10-20 '), date (' 10/20/2002 '), Time (' 12:00:00 ')
Currently DB2 V8 also supports To_char and to_date
10. Judging non-empty stringsThe input parameter is a character type, and is allowed to be empty, you can use COALESCE (InputParameter, ') to convert null to ';
input type is integral type, and allowed to be empty, you can use COALESCE (inputparameter,0), the idling switch to 0;
The input parameter is a character type, and is non-empty, you can use COALESCE (InputParameter, ") to convert null to ', and then determine whether the function return value is ';
The input type is integer and is non-null and does not require the use of the COALESCE function to directly use is NULL for a nonempty judgment.
processing of ' value ', ' or ' is not NULL in the database but a space exists need to use = ' ' Authentication
DB2 Common SQL Functions (reproduced)