|
Home >> FAQs/Tutorials >> MySQL Tutorials >> Index
MySQL FAQs - Introduction to SQL Basics
By: FYIcenter.com
Part:
1
2
3
4
5
6
7
(Continued from previous part...)
How To Convert Character Strings to Numeric Values?
You can convert character strings to numeric values by using the
CAST(string AS DECIMAL) or CAST(string AS SIGNED INTEGER) function
as shown in the following examples:
SELECT CAST('4123.45700' AS DECIMAL) FROM DUAL;
4123.46
-- Very poor conversion
SELECT CAST('4.12345700e+3' AS DECIMAL) FROM DUAL;
4123.46
-- Very poor conversion
SELECT CAST('4123.45700' AS SIGNED INTEGER) FROM DUAL;
4123
SELECT CAST('4.12345700e+3' AS SIGNED INTEGER) FROM DUAL;
4
-- Very poor conversion
How To Use IN Conditions?
An IN condition is single value again a list of values. It returns
TRUE, if the specified value is in the list. Otherwise, it returns FALSE.
Some examples are given in the tutorial exercise below:
SELECT 3 IN (1,2,3,4,5) FROM DUAL;
1
SELECT 3 NOT IN (1,2,3,4,5) FROM DUAL;
0
SELECT 'Y' IN ('F','Y','I') FROM DUAL;
1
How To Use LIKE Conditions?
A LIKE condition is also called pattern patch. There are 3 main rules
on using LIKE condition:
- '_' is used in the pattern to match any one character.
- '%' is used in the pattern to match any zero or more characters.
- ESCAPE clause is used to provide the escape character in the pattern.
The following tutorial exercise provides you some good pattern matching examples:
SELECT 'FYIcenter.com' LIKE '%center%' FROM DUAL;
1
SELECT 'FYIcenter.com' LIKE '%CENTER%' FROM DUAL;
1
-- Case insensitive by default
SELECT 'FYIcenter.com' LIKE '%CENTER_com' FROM DUAL;
1
How To Use Regular Expression in Pattern Match Conditions?
If you have a pattern that is too complex for LIKE to handle, you can use the
regular expression pattern condition: REGEXP.
The following tutorial exercise provides you some good examples:
SELECT 'FYICenter.com' REGEXP '.*fyi.*' FROM DUAL;
1
SELECT 'FYICenter.com' REGEXP '.*com$' FROM DUAL;
1
SELECT 'FYICenter.com' REGEXP '^F.*' FROM DUAL;
1
(Continued on next part...)
Part:
1
2
3
4
5
6
7
|