Database Articles

Page 163 of 546

How can I create MySQL stored procedure with IN parameter?

Smita Kapse
Smita Kapse
Updated on 22-Jun-2020 500 Views

To make it understand we are using the table named ‘student_info’ which have the following values −mysql> Select * from student_info; +-----+---------+------------+------------+ | id  | Name    | Address    | Subject    | +-----+---------+------------+------------+ | 101 | YashPal | Amritsar   | History    | | 105 | Gaurav  | Jaipur     | Literature | | 110 | Rahul   | Chandigarh | History    | | 125 | Raman   | Shimla     | Computers  | +------+--------+------------+------------+ 4 rows in set (0.00 sec)Now, with the help of the following query, we will create a stored procedure ...

Read More

How can I create MySQL stored procedure with INOUT parameter?

Nishtha Thakur
Nishtha Thakur
Updated on 22-Jun-2020 1K+ Views

Following example will demonstrate MySQL stored procedure with INOUT parameter −mysql> DELIMITER // ; mysql> Create PROCEDURE counter(INOUT count INT, IN increment INT)     -> BEGIN     -> SET count = count + increment;     -> END // Query OK, 0 rows affected (0.03 sec)Here, ‘count’ is the INOUT parameter, which can store and return values and ‘increment’ is the IN parameter, which accepts the values from user.mysql> DELIMITER ; mysql> SET @counter = 0; Query OK, 0 rows affected (0.00 sec) mysql> CALL counter(@Counter, 1); Query OK, 0 rows affected (0.00 sec) mysql> Select @Counter; ...

Read More

How can we see the list of stored procedures and stored functions in a particular MySQL database?

Sreemaha
Sreemaha
Updated on 22-Jun-2020 306 Views

We can see the list of the stored procedure and stored functions in a particular database by using the following query on INFORMATION_SCHEMA.ROUTINES as follows −mysql> SELECT ROUTINE_TYPE, ROUTINE_NAME FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'query'; +--------------+--------------+ | ROUTINE_TYPE | ROUTINE_NAME | +--------------+--------------+ | PROCEDURE    | allrecords   | | FUNCTION     | Hello        | +--------------+--------------+ 2 rows in set (0.04 sec)The above query returns the procedure named ‘allrecords’, and function named ‘Hello’ which are stored in the database named ‘query’.

Read More

How can we get some starting number of characters from the data stored in a MySQL table’s column?

Moumita
Moumita
Updated on 22-Jun-2020 175 Views

To get some starting number of characters from the data stored in the MySQL table’s column, we can use MySQL LEFT() function. It will return the number of characters specified as its argument. We need to provide the name of the column, having the particular record from which we want to get starting characters, as its first argument. To demonstrate it we are taking the example of a table named ‘examination_btech’ having the following examination details of students −mysql> Select * from examination_btech; +-----------+----------+--------+ | RollNo    | Name     | Course | +-----------+----------+--------+ | 201712001 | Rahul   ...

Read More

How can I customize the output of MySQL SUM() function to 0 instead of NULL when there are no matching rows?

Arjun Thakur
Arjun Thakur
Updated on 22-Jun-2020 380 Views

As we know that the SUM() function returns NULL if there is no matching row but sometimes we want it to return zero instead of NULL. For this purpose, we can use the MySQL COALESCE() function which accepts two arguments and returns the second argument if the first argument is NULL, otherwise, it returns the first argument. To understand the above concept, consider an ‘employee_tbl’ table, which is having the following records −mysql> SELECT * FROM employee_tbl; +------+------+------------+--------------------+ | id   | name | work_date  | daily_typing_pages | +------+------+------------+--------------------+ | 1    | John | 2007-01-24 |       ...

Read More

What are the advantages and disadvantages of using MySQL stored procedures?

Nitya Raut
Nitya Raut
Updated on 22-Jun-2020 3K+ Views

There are numerous advantages and disadvantages of using MySQL stored procedures which are as follows −MySQL Stored Procedure AdvantagesFollowings are the advantages of using MySQL Stored Procedures −Increasing the performance of applications − As we know that after creating the stored procedure it is compiled and stored in the database. But MySQL implements stored procedures slightly different which helps in increasing the performance of the applications. MySQL stored procedures are compiled on demand. After compiling a stored procedure, MySQL puts it into a cache. And MySQL maintains its own stored procedure cache for every single connection. If an application uses ...

Read More

How can we see only name and types of the stored routines in a particular MySQL database?

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

We can write the following query to see only the name and types of procedures in a particular MySQL database. To make it understand we are using the database named ‘query’ −mysql> Select Name, Type from mysql.proc where db = 'query'; +------------+-----------+ | Name       | Type      | +------------+-----------+ | allrecords | PROCEDURE | | Hello      | FUNCTION  | +------------+-----------+ 2 rows in set (0.18 sec)

Read More

How can we get some last number of characters from the data stored in a MySQL table’s column?

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 22-Jun-2020 206 Views

To get some last number of characters from the data stored in MySQL table’s column, we can use MySQL RIGHT() function. It will return the number of characters specified as it argument. We need to provide the name of the column, having the particular record from which we want to get last characters, as its first argument. To demonstrate it we are taking the example of a table named ‘examination_btech’ having the following examination details of students −mysql> Select * from examination_btech; +-----------+----------+--------+ | RollNo    | Name     | Course | +-----------+----------+--------+ | 201712001 | Rahul    | ...

Read More

How can we get only the name having no other details about the tables in MySQL database?

Sreemaha
Sreemaha
Updated on 22-Jun-2020 195 Views

With the help of SHOW TABLES command, we can get only the name having no other information about the tables. For example, we can see the list of tables in a database named tutorial as follows −mysql> show tables; +--------------------+ | Tables_in_tutorial | +--------------------+ | student            | +--------------------+ 1 row in set (0.00 sec)

Read More

How can we use MySQL SUM() function to calculate the sum of only dissimilar values of the column?

Manikanth Mani
Manikanth Mani
Updated on 22-Jun-2020 204 Views

For calculating the sum of only dissimilar values of the column we can use ‘DISTINCT’ keyword along with the name of the column. To understand SUM() function for dissimilar values, consider an ‘employee_tbl’ table, which is having the following records −mysql> SELECT * FROM employee_tbl; +------+------+------------+--------------------+ | id   | name | work_date  | daily_typing_pages | +------+------+------------+--------------------+ | 1    | John | 2007-01-24 | 250                | | 2    | Ram  | 2007-05-27 | 220                | | 3    | Jack | 2007-05-06 | 170 ...

Read More
Showing 1621–1630 of 5,457 articles
« Prev 1 161 162 163 164 165 546 Next »
Advertisements