MySQL IF ELSE Statement in Stored Procedure

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

17K+ 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

Using MySQL IF-ELSEIF-ELSE Statement in Stored Procedures

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

12K+ 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

Create MySQL Stored Procedure with OUT Parameter

vanithasree
Updated on 22-Jun-2020 05:43:29

5K+ Views

To make it understand we are using the table named ‘student_info’ which have the following values −mysql> Select * from student_info; +------+---------+------------+------------+ | id   | Name    | Address    | Subject    | +------+---------+------------+------------+ | 101  | YashPal | Amritsar   | History    | | 105  | Gaurav  | Jaipur     | Literature | | 110  | Rahul   | Chandigarh | History    | | 125  | Raman   | Shimla     | Computers  | +------+---------+------------+------------+ 4 rows in set (0.00 sec)Now, with the help of the following query, we will create a stored ... Read More

Create Stored Procedure to Select Values from MySQL Table

seetha
Updated on 22-Jun-2020 05:42:36

409 Views

We can create a stored procedure with IN and OUT operators to SELECT records, based on some conditions, from MySQL table. To make it understand we are taking an example of a table named ‘student_info’ having the following data −mysql> Select * from student_info; +------+---------+------------+------------+ | id   | Name    | Address    | Subject    | +------+---------+------------+------------+ | 101  | YashPal | Amritsar   | History    | | 105  | Gaurav  | Jaipur     | Literature | | 110  | Rahul   | Chandigarh | History    | | 125  | Raman   | Bangalore  | ... Read More

Bit Field Notation in MySQL

Sharon Christine
Updated on 22-Jun-2020 05:41:38

499 Views

Bit-field notation is the notation with the help of which we can write bit-field values. The syntax of Bit-field notation is as follows −Syntaxb’value’   OR 0bvalueHere, the value is a binary value written by using zeros and ones.The mainly Bit-filed notation is convenient for specifying values to be assigned to BIT columns of MySQL table. Following example will demonstrate it −mysql> Create table bit_testing (bittest BIT(8)); Query OK, 0 rows affected (1.09 sec) mysql> INSERT INTO bit_testing SET bittest = b'10101010'; Query OK, 1 row affected (0.07 sec) mysql> INSERT INTO bit_testing SET bittest = b'0101'; Query ... Read More

Default Type of Bit Value Assigned to User Variables

Arushi
Updated on 22-Jun-2020 05:39:42

196 Views

By default, the bit values assigned to the user variables are binary strings. It can be illustrated by assigning the bit value to a user variable and then by retrieving them as follows −mysql> SET @abc = 0b1000011; Query OK, 0 rows affected (0.00 sec) mysql> Select @abc; +------+ | @abc | +------+ | C    | +------+ 1 row in set (0.00 sec)The above result set shows that the default type of a bit value assigned to user variables are binary strings.

Display MySQL BIT Values in Printable Form

Anjana
Updated on 22-Jun-2020 05:39:10

116 Views

Actually, Bit values are returned as binary values but we can also display them in the printable form with the help of following −By adding 0We can display Bit values in printable form by adding 0 to them. Following the example from the bit_testing table can be used to understand it −mysql> Select bittest+0 from bit_testing; +-----------+ | bittest+0 | +-----------+ |       170 | |         5 | |         5 | +-----------+ 3 rows in set (0.00 sec)By using conversion function BIN(), OCT(), HEX()We can also display Bit values in ... Read More

Create Stored Procedure to Delete Values from a MySQL Table

Govinda Sai
Updated on 22-Jun-2020 05:38:01

3K+ Views

We can create a stored procedure with IN operator to delete values from a MySQL table. To make it understand we are taking an example of a table named ‘student_info’ having the following data −mysql> Select * from student_info; +------+---------+------------+------------+ | id   | Name    | Address    | Subject    | +------+---------+------------+------------+ | 100  | Aarav   | Delhi      | Computers  | | 101  | YashPal | Amritsar   | History    | | 105  | Gaurav  | Jaipur     | Literature | | 110  | Rahul   | Chandigarh | History    | +------+---------+------------+------------+ ... Read More

Create Stored Procedure to Update Values in a MySQL Table

Prabhas
Updated on 22-Jun-2020 05:37:02

9K+ Views

We can create a stored procedure with IN operator to update values in a MySQL table. To make it understand we are taking an example of a table named ‘student_info’ having the following data −mysql> Select * from student_info; +------+---------+------------+------------+ | id   | Name    | Address    | Subject    | +------+---------+------------+------------+ | 101  | YashPal | Amritsar   | History    | | 105  | Gaurav  | Jaipur     | Literature | | 110  | Rahul   | Chandigarh | History    | | 125  | Raman   | Bangalore  | Computers  | +------+---------+------------+------------+ 4 rows ... Read More

Assign Bit Value as Number to User Variable

Chandu yadav
Updated on 22-Jun-2020 05:35:55

434 Views

As we know that the default type of a bit values assigned to user variables is binary strings but we can also assign a bit value to a number by using the following two methods −By using CAST() functionWith the help of CAST(… AS UNSIGNED) the bit value can be assigned a number. The following example will illustrate it −mysql> SET @abc = CAST(0b1000011 AS UNSIGNED); Query OK, 0 rows affected (0.00 sec) mysql> Select @abc; +------+ | @abc | +------+ | 67   | +------+ 1 row in set (0.00 sec)By adding 0(+0)The bit value can be assigned ... Read More

Advertisements