- Search for "Withoutbook Practice Exam Test" in Mobile/Tablet Play Store
 Take a Tour Practice InterviewNew Search by Name or Email Play Games Questions Forum

Exams Attended

Mock Exams

Make Homepage

# MySQL Interview Questions and Answers

##### Ques 71. How To Convert Numeric Values to Character Strings?

Ans. You can convert numeric values to character strings by using the CAST(value AS CHAR) function as shown in the following examples:

SELECT CAST(4123.45700 AS CHAR) FROM DUAL;
4123.45700
-- How to get rid of the last 2 '0's?

SELECT CAST(4.12345700E+3 AS CHAR) FROM DUAL;
4123.457

SELECT CAST(1/3 AS CHAR);
0.3333
-- Very poor conversion

##### Ques 72. How To Convert Character Strings to Numeric Values?
Ans. 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
##### Ques 73. How To Use IN Conditions?
Ans. 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
##### Ques 74. How To Use LIKE Conditions?
Ans. 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 \'WithoutBook.com\' LIKE \'%center%\' FROM DUAL;
1

SELECT \'WithoutBook.com\' LIKE \'%CENTER%\' FROM DUAL;
1
-- Case insensitive by default

SELECT \'WithoutBook.com\' LIKE \'%CENTER_com\' FROM DUAL;
1
##### Ques 75. How To Use Regular Expression in Pattern Match Conditions?
Ans. 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 'WithoutBook.com' REGEXP '.*ggl.*' FROM DUAL;
1

SELECT 'WithoutBook.com' REGEXP '.*com\$' FROM DUAL;
1

SELECT 'WithoutBook.com' REGEXP '^F.*' FROM DUAL;
1