Use MySQL INTERVAL Function with a Column of a Table

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

473 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

Reverse a String in MySQL

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

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

Get All Records of a Table Using MySQL Stored Procedure

V Jyothi
Updated on 22-Jun-2020 06:52:26

360 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

Create a Stored Procedure to Get Details of a MySQL Table

Nancy Den
Updated on 22-Jun-2020 06:51:49

425 Views

Following example will create a procedure named ‘tabledetails’ which gives all the details of a particular table stored in database.Examplemysql> DELIMITER // mysql> Create Procedure tabledetails()    -> BEGIN    -> DESCRIBE Student_detail;    -> END // Query OK, 0 rows affected (0.00 sec) mysql> DELIMITER ; mysql> CALL tabledetails; +-------------+-------------+------+-----+---------+-------+ | Field       | Type        | Null | Key | Default | Extra | +-------------+-------------+------+-----+---------+-------+ | Studentid   | int(11)     | NO   | PRI | NULL    |       | | StudentName | varchar(20) | YES  |     | NULL    |       | | address     | varchar(20) | YES  |     | NULL    |       | +-------------+-------------+------+-----+---------+-------+ 3 rows in set (0.01 sec) Query OK, 0 rows affected (0.04 sec)

List Tables with Detailed Information in a Database

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

146 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

Perform START Transactions Inside MySQL Stored Procedure

Sreemaha
Updated on 22-Jun-2020 06:50:09

488 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 MySQL Stored Procedure to List Tables in Database

Sravani S
Updated on 22-Jun-2020 06:49:30

545 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

Call Another MySQL Stored Procedure Inside a Stored Procedure

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

List with a Blue Left Border Using CSS

varun
Updated on 22-Jun-2020 06:46:14

223 Views

To add a blue left border to a list in CSS, you can try to run the following code −ExampleLive Demo                    ul {             border-left: 3px solid blue;             background-color: #gray;          }                     Countries                India          US          Australia           Output

What MySQL Returns if the First Argument of INTERVAL Function is NULL

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

159 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

Advertisements