string functions in sql code example

Example 1: sql value of string

-- Specifically for Oracle

-- EXAMPLE
CAST('732.98' AS INT)

/* SYNTAX
CAST(<value_to_cast> AS <data_type_to_cast_to>)
*/

Example 2: sql string functions

ASCII Returns the equivalent ASCII value for a specific character.
CHAR_LENGTH Returns the character length of a string.
CHARACTER_
LENGTH Same as CHAR_LENGTH.
CONCAT Adds expressions together, with a minimum of 2.
CONCAT_WS Adds expressions together, but with a separator between each value.
FIELD Returns an index value relative to the position of a value within a list of
values.
FIND IN SET Returns the position of a string in a list of strings.
FORMAT When passed a number, returns that number formatted to include
commas (eg 3,400,000).
INSERT Allows you to insert one string into another at a certain point, for a
certain number of characters.
INSTR Returns the position of the first time one string appears within another.
LCASE Convert a string to lowercase.
LEFT Starting from the left, extract the given number of characters from a
string and return them as another.
LENGTH Returns the length of a string, but in bytes.
LOCATE Returns the first occurrence of one string within another,
LOWER Same as LCASE.
LPAD Left pads one string with another, to a specific length.
LTRIM Remove any leading spaces from the given string.
MID Extracts one string from another, starting from any position.
POSITION Returns the position of the first time one substring appears within
another.
REPEAT Allows you to repeat a string
REPLACE Allows you to replace any instances of a substring within a string, with
a new substring.
REVERSE Reverses the string.
RIGHT Starting from the right, extract the given number of characters from a
string and return them as another.
RPAD Right pads one string with another, to a specific length.
RTRIM Removes any trailing spaces from the given string.
SPACE Returns a string full of spaces equal to the amount you pass it.
STRCMP Compares 2 strings for differences
SUBSTR Extracts one substring from another, starting from any position.
SUBSTRING Same as SUBSTR
SUBSTRING_
INDEX
Returns a substring from a string before the passed substring is found
the number of times equals to the passed number.
TRIM Removes trailing and leading spaces from the given string. Same as if
you were to run LTRIM and RTRIM together.
UCASE Convert a string to uppercase.
UPPER Same as UCASE

Tags:

Sql Example