Found 4381 Articles for MySQL

How can we access tables through MySQL stored procedures?

Krantik Chavan
Updated on 22-Jun-2020 07:02:44

378 Views

We can access one or all the tables from the MySQL stored procedure. Following is an example in which we created a stored procedure that will accept the name of the table as a parameter and after invoking it, will produce the result set with all the details from the table.Examplemysql> Delimiter // mysql> Create procedure access(tablename varchar(30))    -> BEGIN    -> SET @X := CONCAT('Select * from', ' ', tablename);    -> Prepare statement from @X;    -> Execute statement;    -> END// Query OK, 0 rows affected (0.16 sec)Now invoke the procedure with the table name, we ... Read More

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

Vrundesha Joshi
Updated on 22-Jun-2020 06:48:26

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

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
Updated on 22-Jun-2020 06:49:30

496 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

Create a procedure to list the tables with detailed information in a particular database.

Rishi Rathor
Updated on 22-Jun-2020 06:51:19

122 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 give us the list of tables with detailed information −mysql> DELIMITER// mysql> CREATE procedure tablelist()    -> BEGIN    -> Select * from Information_schema.tables WHERE table_schema = 'query';    -> END // Query OK, 0 rows affected (0.06 sec) mysql> DELIMITER; mysql> CALL tablelist()\G *************************** 1. row ***************************   ... Read More

Which function in MySQL is used to reverse a particular string?

Fendadis John
Updated on 22-Jun-2020 06:53:08

126 Views

MySQL REVERSE() function can be used to reverse a string. Following example will demonstrate it −mysql> Select REVERSE('Tutorialspoint'); +---------------------------+ | REVERSE('Tutorialspoint') | +---------------------------+ | tniopslairotuT            | +---------------------------+ 1 row in set (0.00 sec) mysql> Select Reverse('10-11-12'); +---------------------+ | Reverse('10-11-12') | +---------------------+ | 21-11-01            | +---------------------+ 1 row in set (0.00 sec)

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

Swarali Sree
Updated on 22-Jun-2020 06:53:46

437 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

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

Akshaya Akki
Updated on 22-Jun-2020 06:43:37

112 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)

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

Chandu yadav
Updated on 22-Jun-2020 06:44:25

112 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);

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

Kumar Varma
Updated on 22-Jun-2020 06:46:02

141 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

What is MySQL INTERVAL() function?

Sai Subramanyam
Updated on 30-Jul-2019 22:30:21

508 Views

MySQL INTERVAL() function returns the index value of the argument which is greater than the first argument. Syntax INTERVAL(N,N1,N2,N3,…) Here, this function will compare 1st argument i.e. N with the other arguments i.e. N1, N2, N3 and so on. All the arguments are treated as integers. It returns the output as follows − If N

Advertisements