Perform START Transactions Inside MySQL Stored Procedure

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

466 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

512 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

214 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

148 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

MySQL Handler in a Stored Procedure for Error Messages

Nikitha N
Updated on 22-Jun-2020 06:45:04

694 Views

As we know that whenever an exception occurred in MySQL stored procedure, it is very important to handle it by throwing proper error message because if we do not handle the exception, there would be a chance to fail application with that certain exception in a stored procedure. MySQL provides a handler that throws an error message and exits the execution. To demonstrate it, we are using the following example in which we are trying to insert a duplicate value in a Primary key column.Examplemysql> Delimiter // mysql> Create Procedure Insert_Studentdetails3(S_Studentid INT, S_StudentName Varchar(20), S_Address Varchar(20))     -> BEGIN ... Read More

Write Numbers in MySQL INTERVAL Function in Ascending Order

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

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

MYSQL INTERVAL Function Returns with No Bigger Number

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

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

MySQL IN Comparison Function Explained

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

161 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

Use of MySQL IS and IS NOT Operator

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

343 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

Advertisements