Found 4219 Articles for MySQLi

What is the use of MySQL NULLIF() control flow function?

Sai Nath
Updated on 22-Jun-2020 06:58:05

132 Views

MySQL NULLIF() control flow function will return NULL if both the arguments are the same, otherwise, it returns the first argument.SyntaxNULLIF(expression1, expression2)Here if expression1 = expression2, NULL will be returned by NULLIF() otherwise expression1 will be returned. Following example will exhibit this −mysql> Select NULLIF('Ram','Ram'); +---------------------+ | NULLIF('Ram','Ram') | +---------------------+ | NULL                | +---------------------+ 1 row in set (0.00 sec) mysql> Select NULLIF('Ram','Shyam'); +-----------------------+ | NULLIF('Ram','Shyam') | +-----------------------+ | Ram                   | +-----------------------+ 1 row in set (0.00 sec)

What do you mean by Scope of variables inside MySQL stored procedure?

Jennifer Nicholas
Updated on 22-Jun-2020 07:38:09

149 Views

Suppose if we declare a variable inside a BEGIN/END block then the scope of this variable would be in this particular block. We can also declare a variable with the same name inside another BEGIN/END block which will be totally legal but its scope would be inside its BEGIN/END block. It can be understood with the help of the following example in which we are creating a procedure to show the scope of the variables −Examplemysql> Create Procedure Scope_variables()     -> BEGIN     -> DECLARE A Varchar(5) Default 'outer';     -> BEGIN     -> DECLARE A ... Read More

Does MySQL preserve the environment at the time the stored procedure created?

seetha
Updated on 22-Jun-2020 07:37:13

46 Views

Actually, MySQL preserves the environment at the time the stored procedure is created. It can be understood with the help of following the example in which we are using two bars for concatenating strings. This is only legal while SQL mode is ansi. But if we change the SQL mode to non-ansi, the procedure still works as if the original setting is still true.Examplemysql> Set sql_mode = 'ansi'// Query OK, 0 rows affected, 1 warning (0.14 sec) mysql> Create Procedure Con_string()     -> SELECT 'a'||'b'// Query OK, 0 rows affected (0.12 sec) mysql> Call Con_string (); +----------+ | ... Read More

What is the use of MySQL IFNULL() control flow function?

Jai Janardhan
Updated on 22-Jun-2020 06:59:50

117 Views

MySQL IFNULL() control flow function will return the first argument if it is not NULL otherwise it returns the second argument.SyntaxIFNULL(expression1, expression2)Here if expression1 is not NULL then IFNULL() will return expression1 otherwise expression2. It will return NULL if both of the arguments are NULL. Following example will exhibit this −mysql> Select IFNULL(NULL, 'Ram'); +--------------------+ | IFNULL(NULL, 'Ram') | +--------------------+ | Ram                | +--------------------+ 1 row in set (0.00 sec) mysql> Select IFNULL('Shyam', 'Ram'); +-----------------------+ | IFNULL('Shyam', 'Ram') | +-----------------------+ | Shyam                 | +-----------------------+ ... Read More

How can REPLACE() be used with UPDATE clause to make permanent changes to a table?

Manikanth Mani
Updated on 22-Jun-2020 07:01:25

143 Views

As we know that REPLACE () function is used to replace the occurrences of a substring with another substring within a string. We can also use the REPLACE function with the UPDATE statement to update the table. Following example will demonstrate it −Examplemysql> Update Student set Father_Name = REPLACE(Father_Name, 'Mr.', 'Shri '); Query OK, 5 rows affected (0.06 sec) Rows matched: 5 Changed: 5 Warnings: 0 mysql> Select Name, Father_Name from Student; +---------+-----------------+ | Name    | Father_Name     | +---------+-----------------+ | Gaurav  | Shri Ramesh     | | Aarav   | Shri Sanjay     | ... Read More

How can we create MySQL stored procedures without ‘BEGIN’ and ‘END’?

Vrundesha Joshi
Updated on 22-Jun-2020 07:20:52

370 Views

We can create MySQL stored procedures without ‘BEGIN’ and ‘END’ just in the same way created with both of them only thing is to omit to BEGIN and END. In the following example, we are creating a stored procedure without ‘BEGIN’ and ‘END’ to get all the rows from a table −Examplemysql> Delimiter // mysql> CREATE PROCEDURE Hello()     -> SELECT * from Student_info; // Query OK, 0 rows affected (0.08 sec)We can see MySQL created stored procedures without BEGIN and END. Now invoke this by CALL statement −mysql> Delimiter ; mysql> CALL Hello(); +-----+---------+------------+------------+ | id  | ... Read More

What would be the default return type of MySQL IFNULL() control flow operator?

Ankith Reddy
Updated on 22-Jun-2020 07:00:29

66 Views

Actually, the default return type of IFNULL(expression1, expression2) is more general of the two expressions, in the order STRING, REAL or INTEGER. It can be understood from the following example −Examplemysql> Create table testing Select IFNULL(100, 'testing123'); Query OK, 1 row affected (0.18 sec) Records: 1 Duplicates: 0 Warnings: 0 mysql> Select * from testing568; +-----------------------+ | IFNULL(100, 'testing') | +-----------------------+ | 100                   | +-----------------------+ 1 row in set (0.00 sec) mysql> Describe testing568; +-----------------------+------------+------+-----+---------+-------+ | Field                 | Type     ... Read More

What is the difference between = and: = assignment operators?

karthikeya Boyini
Updated on 22-Jun-2020 06:58:55

642 Views

Actually, they both are assignment operator and used to assign values but the significant difference between them is as follows −= operator assigns a value either as a part of the SET statement or as a part of the SET clause in an UPDATE statement, in any other case = operator is interpreted as a comparison operator. On the other hand, := operator assigns a value and it is never interpreted as a comparison operator.mysql> Update estimated_cost1 SET Tender_value = '8570.000' where id = 2; Query OK, 1 row affected (0.06 sec) Rows matched: 1 Changed: 1 Warnings: 0 ... Read More

Create a procedure to find out the factorial of a number?

vanithasree
Updated on 22-Jun-2020 07:21:33

3K+ Views

It can be created with the help of the following query −mysql> Delimiter // mysql> CREATE PROCEDURE fact(IN x INT)     -> BEGIN     -> DECLARE result INT;     -> DECLARE i INT;     -> SET result = 1;     -> SET i = 1;     -> WHILE i SET result = result * i;     -> SET i = i + 1;     -> END WHILE;     -> SELECT x AS Number, result as Factorial;     -> END// Query OK, 0 rows affected (0.17 sec)Now when invoking this ... Read More

What are the limitations for replicating stored procedure and functions?

Rishi Rathor
Updated on 22-Jun-2020 07:24:53

162 Views

Followings are the limitations for replicating stored procedure and functions −Type of Action − Actually the replication of stored procedure and functions depends upon the type of action. If the action, embedded in stored procedures, is nondeterministic (random) or time-based then it may not replicate properly. By their very nature, randomly produced results are not predictable and cannot be exactly reproduced, and therefore, random actions replicated to a slave will not mirror those performed on a master.Type of transaction − non-transactional tables for which errors occur during large DML actions (such as bulk inserts) may experience replication issues in that ... Read More

Advertisements