Found 4219 Articles for MySQLi

What MySQL returns if we provide value larger than 255 as argument to MySQL CHAR() function?

Alankritha Ammu
Updated on 22-Jun-2020 06:10:54

71 Views

MySQL converts the arguments of CHAR() function which is greater than 255 to multiple result bytes. For example, CHAR(260) is equivalent to CHAR(0,1,0,4). It can be more clear with the help of following statements −mysql> Select HEX(CHAR(256)),HEX(CHAR(1,0)); +----------------+----------------+ | HEX(CHAR(256)) | HEX(CHAR(1,0)) | +----------------+----------------+ | 0100           | 0100           | +----------------+----------------+ 1 row in set (0.00 sec)The above result set shows that CHAR(256) is equivalent to CHAR(1,0).

How MySQL REPEAT loop statement can be used in stored procedure?

Giri Raju
Updated on 22-Jun-2020 06:07:11

716 Views

As we know that MySQL provides us loop statements that allow us to execute a block of SQL code repeatedly based on a condition. A REPEAT loop statement is one of such kind of loop statement. Its syntax is as follows −REPEAT    statements; UNTIL expression END REPEATFirst of all, MySQL executes the statements, and then it evaluates the expression. If the expression evaluates to FALSE, MySQL executes the statements repeatedly until the expression evaluates to TRUE. The REPEAT loop checks the expression after the statements execute, that is why it is also called a post-test loop.To demonstrate the use of a ... Read More

How MySQL WHILE loop statement can be used in stored procedure?

Ankitha Reddy
Updated on 22-Jun-2020 06:08:42

2K+ Views

As we know that MySQL provides us loop statements that allow us to execute a block of SQL code repeatedly based on a condition. WHILE loop statement is one of such kind of loop statements. Its syntax is as follows −WHILE expression DO statements END WHILEActually, the WHILE loop checks the expression at the starting of every iteration. If the expression evaluates to true, MySQL will execute statements between WHILE and END WHILE until the expression evaluates to false. The WHILE loop checks the expression before the statements execute, that is why it is also called the pretest loop.To demonstrate ... Read More

What happens if we provide NULL as an argument to MySQL CHAR() function?

Paul Richard
Updated on 22-Jun-2020 06:11:23

61 Views

MySQL CHAR() function will ignore NULL if it is provided as an argument to it. To understand it, consider the following examples −mysql> Select CHAR(65,66,67,NULL); +---------------------+ | CHAR(65,66,67,NULL) | +---------------------+ | ABC                 | +---------------------+ 1 row in set (0.00 sec) mysql> Select CHAR(NULL,66,67,NULL); +-----------------------+ | CHAR(NULL,66,67,NULL) | +-----------------------+ | BC                    | +-----------------------+ 1 row in set (0.00 sec)In both the examples above, CHAR() function ignores the NULL and converts the numeric value into character value.

How Can MySQL CASE statement be used in stored procedure?

Sreemaha
Updated on 22-Jun-2020 06:10:19

1K+ Views

Actually, the CASE statement has the functionality of an IF-THEN-ELSE statement. It has the following syntax −CASE WHEN condition_1 THEN    {...statements to execute when condition_1 is TRUE...} [ WHEN condition_2 THEN    {...statements to execute when condition_2 is TRUE...} ] [ WHEN condition_n THEN    {...statements to execute when condition_n is TRUE...} ] [ ELSE    {...statements to execute when all conditions were FALSE...} ] END CASE;The CASE statement will execute the ELSE clause if none of the WHEN clauses were executed.To demonstrate the use of CASE statement within MySQL stored procedure, we are creating the following stored procedure which ... Read More

How MySQL IF ELSE statement can be used in a stored procedure?

varma
Updated on 22-Jun-2020 05:46:44

13K+ Views

MySQL IF ELSE statement implements a basic conditional construct when the expression evaluates to false. Its syntax is as follows −IF expression THEN    statements; ELSE    else-statements; END IF;The statements must end with a semicolon.To demonstrate the use of IF ELSE statement within MySQL stored procedure, we are creating the following stored procedure which is based on the values, as shown below, of the table named ‘student_info’ −mysql> Select * from student_info; +------+---------+------------+------------+ | id   | Name    | Address    | Subject    | +------+---------+------------+------------+ | 101  | YashPal | Amritsar   | History    | | 105  | ... Read More

How can MySQL IF ELSEIF ELSE statement be used in a stored procedure?

Abhinaya
Updated on 22-Jun-2020 05:45:27

10K+ Views

MySQL IF ELSEIF ELSE execute the statements based on multiple expressions Its syntax is as follows −IF expression THEN    statements; ELSEIF elseif-expression THEN    elseif-statements; … … … … ELSE   else-statements; END IF;The statements must end with a semicolon.To demonstrate the use of IF ELSEIF ELSE statement within MySQL stored procedure, we are creating the following stored procedure which is based on the values, as shown below, of the table named ‘student_info’ −mysql> Select * from student_info; +------+---------+------------+------------+ | id   | Name    | Address    | Subject    | +------+---------+------------+------------+ | 101  | YashPal | Amritsar   ... Read More

What is the use of IGNORE_SPACE SQL mode?

Arjun Thakur
Updated on 22-Jun-2020 05:48:58

465 Views

The IGNORE_SPACE SQL mode can be used to modify how the parser treats function names that are whitespace-sensitive. Following are the cases in which we can use IGNORE_SPACE SQL mode −Case-1  − When IGNORE_SPACE SQL mode is disabledAfter disabling the IGNORE_SPACE SQL mode, the parser interprets the name as a function call when there is no whitespace between the name and the following parenthesis. This also occurs when the function name is used in a non-expression context. It can be understood from the following query −mysql> Create table SUM(Id Int); ERROR 1064 (42000): You have an error in your SQL ... Read More

How can we change the default rules used by the parser for parsing names of built-in functions?

Rishi Raj
Updated on 22-Jun-2020 05:52:04

68 Views

The default rules used by the parser for parsing names of built-in-function can be changed by enabling IGNORE_SPACE SQL mode. When we enable this mode, the parser relaxes the requirement that there be no whitespace between the function name and the following parenthesis. For example, after enabling IGNORE_SPACE SQL mode both of the following function calls are legal −Select SUM(Salary) from employee; Select SUM (Salary) from employee;But, in this case, the parser treats the function name as reserved words. It means that a space following the names no longer represents as an identifier.

How MySQL IF statement can be used in a stored procedure?

Ramu Prasad
Updated on 22-Jun-2020 05:51:19

387 Views

MySQL IF statement implements a basic conditional construct within a stored procedure. Its syntax is as follows −IF expression THEN Statements; END IF;It must end with a semicolon. To demonstrate the use of IF statement within MySQL stored procedure, we are creating the following stored procedure which is based on the values, as shown below, of the table named ‘student_info’ −mysql> Select * from student_info; +------+---------+------------+------------+ | id   | Name    | Address    | Subject    | +------+---------+------------+------------+ | 101  | YashPal | Amritsar   | History    | | 105  | Gaurav  | Jaipur     | ... Read More

Advertisements