Found 4219 Articles for MySQLi

In MySQL, how can we declare a handler while handling errors?

Nishtha Thakur
Updated on 22-Jun-2020 06:33:33

427 Views

It is very important to handle the errors by throwing a proper error message. MySQL provides a handler to handle the error. We can declare a handler with the help of the following syntax −Syntax of handlerDECLARE handler_action FOR condition_value statement;The above syntax shows that we need to use DECLARE HANDLER statement to declare a handler. If a condition whose value matches the condition_value then MySQL will execute the statement and continue or exit the current code block based on the action. Followings are the three major things in the above syntax −Handler_action is of two types and can accept one ... Read More

How can we handle a result set inside MySQL stored procedure?

Smita Kapse
Updated on 22-Jun-2020 06:37:40

1K+ Views

We can use a cursor to handle a result set inside a stored procedure. Basically a cursor allows us to iterate a set of rows returned by a query and process each row accordingly.To demonstrate the use of CURSOR 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   | Literature ... Read More

How Can MySQL LOOP statement be used in a stored procedure?

Abhinanda Shri
Updated on 22-Jun-2020 06:39:54

394 Views

MySQL provides us a LOOP statement that executes a block of code repeatedly along with an added flexibility of using a loop label. We have the following two statements that allow us to control the loop −LEAVE statementIt allows us to exit the loop immediately without waiting for checking the condition.Iterate statementIt allows us to skip the entire code under it and start a new iteration.To demonstrate the use of LOOP statement with stored procedures, the following is a stored procedure which constructs a string with even numbers like 2, 4, 6, 8 etc. −mysql> Delimiter // mysql> CREATE PROCEDURE LOOP_loop() ... Read More

In MySQL, how IN() comparison function works?

Rama Giri
Updated on 22-Jun-2020 06:42:32

90 Views

Basically, IN() comparison function checks whether a value is within a set of values or not. If the value is within a set of values then it returns 1 otherwise 0. Its syntax can be as follows;Expression IN (val1, val2, …, valN)Here, The expression is the value that is to be searched within the set of N values within IN list.Val1, val2, …, valN is the set of N values, forms the IN list, from which the search happens.Examplemysql> Select 100 IN (50, 100, 200, 400, 2000); +------------------------------+ | 100 IN (50, 100, 200, 400, 2000) | +------------------------------+ |   ... Read More

What is the use of MySQL IS and IS NOT operator?

Ankith Reddy
Updated on 22-Jun-2020 06:41:52

121 Views

In MySQL, both IS and IS NOT operators are used to test a value against a Boolean value.The syntax of IS operator can be as follows −Val IS Boolean_valHere Val is the value that we want to test against Boolean value.Boolean_val is the Boolean value against which the value would be tested and it can be TRUE, FALSE or UNKNOWN.The syntax of IS NOT operator can be as follows −Val IS NOT Boolean_valHere Val is the value that we want to test against Boolean value.Boolean_val is the Boolean value against which the val would be tested and it can be TRUE, FALSE or UNKNOWN.Following MySQL statements will demonstrate ... Read More

How MySQL NULL-safe equal operator performs when used with row comparisons?

Fendadis John
Updated on 22-Jun-2020 06:20:25

74 Views

When we use NULL-safe operator with row comparisons like (A, B) (C, D) then its performance is equivalent to (A C) AND (B D). Following example will demonstrate it −mysql> Select (100,50) (50,100); +-----------------------+ | (100,50) (50,100) | +-----------------------+ |                     0 | +-----------------------+ 1 row in set (0.00 sec) mysql> Select (100,50) (100,50); +-----------------------+ | (100,50) (100,50) | +-----------------------+ |                     1 | +-----------------------+ 1 row in set (0.00 sec)The above result sets show how NULL-safe operators can be used with row comparison.

What is MySQL NULL-safe equal operator and how it is different from comparison operator?

Sharon Christine
Updated on 22-Jun-2020 06:21:17

271 Views

MySQL NULL-safe equal operator, equivalent to standard SQL IS NOT DISTINCT FROM operator, performs an equality comparison like = operator. Its symbol is . It performs differently from the comparison operators in the case when we have NULL as both the operands. Consider the following examples to understand NULL-safe operator along with its difference with comparison operator −mysql> Select 50 50, NULL NULL, 100 NULL; +-----------+---------------+--------------+ | 50 50 | NULL NULL | 100 NULL | +-----------+---------------+--------------+ |         1 |             1 |            0 | +-----------+---------------+--------------+ 1 row in set (0.00 sec) mysql> Select 50 = 50, NULL = NULL, 100 = NULL; +---------+-------------+------------+ | 50 = 50 | NULL = NULL | 100 = NULL | +---------+-------------+------------+ |       1 |        NULL |       NULL | +---------+-------------+------------+ 1 row in set (0.00 sec)

In MySQL, how does the precedence of ! operator in comparison with NOT operator depends upon HIGH_NOT_PRECEDENCE SQL mode?

Vikyath Ram
Updated on 22-Jun-2020 06:22:38

72 Views

In MySQL, basically the precedence of ! operator in comparison with NOT operator depends upon the enabling or disabling of HIGH_NOT_PRECEDENCE SQL mode as follows −Disabled HIGH_NOT_PRECEDENCE SQL − In this case,! the operator has higher precedence than NOT operator.Enabled HIGH_NOT_PRECEDENCE SQL − In this case,! the operator has the same precedence as NOT operator.

How can we combine values of two or more columns of MySQL table and get that value in a single column?

Chandu yadav
Updated on 22-Jun-2020 06:21:50

119 Views

For combining values of two or more columns, we can use MySQL CONCAT() function. In this case, the arguments of the CONCAT() functions would be the name of the columns. For example, suppose we have a table named ‘Student’ and we want the name and address of the student collectively in one column then the following query can be written −mysql> Select Id, Name, Address, CONCAT(ID, ', ', Name, ', ', Address)AS 'ID, Name, Address' from Student; +------+---------+---------+--------------------+ | Id   | Name    | Address | ID, Name, Address  | +------+---------+---------+--------------------+ | 1    | Gaurav  | Delhi   ... Read More

How does the precedence of || operator depend on PIPES_AS_CONCAT SQL mode?

Samual Sam
Updated on 22-Jun-2020 06:23:31

132 Views

As we know that in MySQL by default || operator is a logical OR operator but it depends upon PIPES_AS_CONCAT SQL mode. If PIPES_AS_CONCAT SQL mode is enabled, then || operator works as string concatenation. At that time its precedence would be between ^ and the unary operator. Following example will make it understand −mysql> Set @C='tutorials'; Query OK, 0 rows affected (0.00 sec) mysql> Set @D='point'; Query OK, 0 rows affected (0.00 sec) mysql> Select @C||@D; +--------+ | @C||@D | +--------+ |      1 | +--------+ 1 row in set (0.00 sec)The result set of the ... Read More

Advertisements