MySQLi Articles

Page 71 of 341

How can I use MySQL INTERVAL() function with a column of a table?

Swarali Sree
Swarali Sree
Updated on 22-Jun-2020 493 Views

We can use INTERVAL() function with a column of a table by providing the first argument as the name of the column. In this case, al the values in that column would be compared with the values given as the other arguments of INTERVAL() function and on that basis of comparison, the result set is provided. To understand it, the data from the employee table is used which is as follows −mysql> Select* from employee568; +----+--------+--------+ | ID | Name   | Salary | +----+--------+--------+ | 1  | Gaurav | 50000  | | 2  | Rahul  | 20000  | | ...

Read More

How can I get all the records of a table by passing its name as the parameter of MySQL stored procedure?

V Jyothi
V Jyothi
Updated on 22-Jun-2020 376 Views

Suppose if we want to see all the records of a table by passing its name as the parameter of a stored procedure then following example will create a procedure named ‘details’ which accepts the name of the table as its parameter −mysql> DELIMITER // mysql> Create procedure details(tab_name Varchar(40))    -> BEGIN    -> SET @t:= CONCAT('Select * from', ' ', tab_name);    -> Prepare stmt FROM @t;    -> EXECUTE stmt;    -> END // Query OK, 0 rows affected (0.00 sec)Now invoke this procedure by giving the name of the table as its parameter and it will ...

Read More

How can we perform START transactions inside MySQL stored procedure?

Sreemaha
Sreemaha
Updated on 22-Jun-2020 505 Views

As we know the START transaction will start the transaction and set the auto-commit mode to off. In the following example, we have created a stored procedure with a START transaction which will insert a new record in table employee.tbl having the following data −mysql> Select * from employee.tbl; +----+---------+ | Id | Name    | +----+---------+ | 1  | Mohan   | | 2  | Gaurav  | | 3  | Rahul   | +----+---------+ 3 rows in set (0.00 sec)Examplemysql> Delimiter // mysql> Create Procedure st_transaction()    -> BEGIN    -> START TRANSACTION;    -> INSERT INTO employee.tbl(name) values ...

Read More

Create a MySQL stored procedure, which takes the name of the database as its parameter, to list the tables with detailed information in a particular database.

Sravani S
Sravani S
Updated on 22-Jun-2020 572 Views

Suppose currently we are using a database named ‘query’ and it is having the following tables in it −mysql> Show tables in query; +-----------------+ | Tables_in_query | +-----------------+ | student_detail  | | student_info    | +-----------------+ 2 rows in set (0.00 sec)Now, following is a stored procedure, which will accept the name of the database as its parameter and give us the list of tables with detailed information −mysql> DELIMITER// mysql> CREATE procedure tb_list(db_name varchar(40))    -> BEGIN    -> SET @z := CONCAT('Select * from information_schema.tables WHERE table_schema = ', '\'', db_name, '\'');    -> Prepare stmt from @z; ...

Read More

How can a MySQL stored procedure call another MySQL stored procedure inside it?

Vrundesha Joshi
Vrundesha Joshi
Updated on 22-Jun-2020 4K+ Views

It is quite possible that a MySQL stored procedure can call another MySQL stored procedure inside it. To demonstrate it, we are taking an example in which a stored procedure will call another stored procedure to find out the last_insert_id.Examplemysql> Create table employee.tbl(Id INT NOT NULL AUTO_INCREMENT, Name Varchar(30) NOT NULL, PRIMARY KEY(id))// Query OK, 0 rows affected (3.87 sec) mysql> Create Procedure insert1()    -> BEGIN insert into employee.tbl(name) values ('Ram');    -> END// Query OK, 0 rows affected (0.10 sec)Now, in the next procedure insert2() we will call the 1st stored procedure i.e. insert1().mysql> Create Procedure insert2() ...

Read More

What MySQL returns if the first argument of INTERVAL() function is NULL?

Kumar Varma
Kumar Varma
Updated on 22-Jun-2020 172 Views

MySQL returns -1 as output if the first argument of INTERVAL() function is NULL. Following example will demonstrate it −mysql> Select INTERVAL(NULL, 20, 32, 38, 40, 50, 55); +--------------------------------------+ | INTERVAL(NULL, 20, 32, 38, 40, 50, 55)     | +--------------------------------------+ | -1                                   | +--------------------------------------+ 1 row in set (0.00 sec)It will return -1 even if any of the other arguments is NULL along with the first argument.mysql> Select INTERVAL(NULL, 20, 32, NULL, 40, 50, NULL); +--------------------------------------+ | INTERVAL(NULL, 20, 32, NULL, 40, 50, NULL) ...

Read More

Why is it good to write the numbers in MySQL INTERVAL() function in ascending order?

Chandu yadav
Chandu yadav
Updated on 22-Jun-2020 140 Views

Actually, INTERVAL() function uses the binary search for searching the bigger number than the number at first argument. So, that is why if we want INTERVAL() function to work efficiently the list of numbers would be in ascending order. Following is a good way to use INTERVAL() function −mysql> Select INTERVAL(50,20,32,38,40,50,55);

Read More

What MYSQL INTERVAL() function returns if there is no bigger number in the list of arguments than the number at first argument?

Akshaya Akki
Akshaya Akki
Updated on 22-Jun-2020 150 Views

In this case, MySQL INTERVAL() function returns the index number of the last number in argument list plus 1. In other words, the last index number in the list plus 1 would be returned by this function. Following example will demonstrate it −mysql> Select INTERVAL(50,20,32,38,40); +--------------------------+ | INTERVAL(50,20,32,38,40) | +--------------------------+ | 4                        | +--------------------------+ 1 row in set (0.00 sec)

Read More

In MySQL, how IN() comparison function works?

Rama Giri
Rama Giri
Updated on 22-Jun-2020 187 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
Ankith Reddy
Updated on 22-Jun-2020 408 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
Showing 701–710 of 3,404 articles
« Prev 1 69 70 71 72 73 341 Next »
Advertisements