MySQLi Articles

Page 102 of 341

While connecting to one MySQL database, how can I see the list of tables of other MySQL database?

seetha
seetha
Updated on 13-Feb-2020 231 Views

With the help of SHOW TABLES From Database_name query, we can see the tables of another database. Here Database_name is the name of the database which we are not using currently. Consider the following example in which we run the query for getting the list of tables in database name ‘tutorial’.mysql> show tables from tutorial; +--------------------+ | Tables_in_tutorial | +--------------------+ | employee           | | showzerofill       | | student            | +--------------------+ 3 rows in set (0.00 sec)

Read More

How do we count the total duplicate records in a column of MySQL table?

Abhinaya
Abhinaya
Updated on 13-Feb-2020 2K+ Views

Suppose we have the following table named stock_item in which the column quantity is having duplicate values i.e. for item name ‘Notebooks’ and ‘Pencil’, the column ‘Quantity’ is having duplicate values ‘40’ and for items ‘Shirts’, ‘Shoes’ and ‘Trousers’ triplicate value 29 is hold by column ‘quantity’ as shown in the table.mysql> Select * from stock_item; +------------+----------+ | item_name  |quantity  | +------------+----------+ | Calculator |       89 | | Notebooks  |       40 | | Pencil     |       40 | | Pens       |       32 | | ...

Read More

How MySQL stored function evaluates if it got NULL value while using the dynamic values from a table?

Ramu Prasad
Ramu Prasad
Updated on 13-Feb-2020 295 Views

In such kind of cases when a stored function got NULL values then it will return NULL as the result. It can be understood from the example below in which we have a NULL value in the records of student ‘Mohit’. Now, when we will apply the stored function ‘avg_marks’ on this data, it will return NULL as result.mysql> Select * from Student_marks; +-------+------+---------+---------+---------+ | Name  | Math | English | Science | History | +-------+------+---------+---------+---------+ | Raman |   95 |      89 |      85 |      81 | | Rahul |   90 | ...

Read More

How can we create a MySQL stored function that uses the dynamic data from a table?

Sravani S
Sravani S
Updated on 13-Feb-2020 541 Views

MySQL Stored functions can reference tables but they cannot make use of statements that return a result set. Hence we can say that there is no SELECT query that returns result set. But we can have SELECT INTO to get rid of that. For example, we are creating a function ‘Avg_marks’ that uses the dynamic data from table named ‘Student_marks’, having following records, to calculate the average of marks.mysql> Select * from Student_marks; +-------+------+---------+---------+---------+ | Name  | Math | English | Science | History | +-------+------+---------+---------+---------+ | Raman |   95 |      89 |      85 | ...

Read More

How to write a MySQL stored function that inserts values in a table?

Giri Raju
Giri Raju
Updated on 13-Feb-2020 2K+ Views

As we know that function is best used when we want to return a result. Hence, when we will create stored functions for manipulating tables like to Insert or Update values then it would be more or less like stored procedures.ExampleIn the following example we are creating a stored function named ‘tbl_insert’ which will insert the values in a table named ‘student_marks’.mysql> Create Function tbl_insert(S_name Varchar(50), M1 INT, M2 INT, M3 INT, M4 INT)     -> RETURNS INT     -> DETERMINISTIC     -> BEGIN     -> INSERT INTO student_marks values(S_name, M1, M2, M3, M4);     ...

Read More

How can we create MySQL stored procedure to calculate the factorial?

Srinivas Gorla
Srinivas Gorla
Updated on 13-Feb-2020 498 Views

mysql> DELIMITER // mysql> CREATE PROCEDURE get_factorial(IN N INT)     -> BEGIN     ->    SET @@GLOBAL.max_sp_recursion_depth = 255;     ->    SET @@session.max_sp_recursion_depth = 255;     ->     ->    CALL factorial_recursive (N, @factorial);     ->     ->    SELECT @factorial;     -> END // Query OK, 0 rows affected (0.00 sec) mysql> DELIMITER // mysql> CREATE PROCEDURE factorial_recursive(IN N INT, OUT factorial INT)     -> BEGIN     ->    IF N = 1 THEN     ->       SET factorial := 1;     -> ...

Read More

How can we write MySQL handler, in a stored procedure, that throws an error message and continues the execution?

vanithasree
vanithasree
Updated on 12-Feb-2020 924 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 continues 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_Studentdetails(S_Studentid INT, S_StudentName Varchar(20), S_Address Varchar(20))    -> BEGIN   ...

Read More

How can we write MySQL stored procedure to select all the data from a table?

Priya Pallavi
Priya Pallavi
Updated on 12-Feb-2020 1K+ Views

To demonstrate it we are creating a procedure named ‘selectdetails()’ which will fetch all the records from table ‘student_detail’.mysql> Delimiter // mysql> Create Procedure selectdetails()    -> BEGIN    -> Select * from student_detail;    -> END// Query OK, 0 rows affected (0.00 sec)Now, after invoking this procedure, we will get all the records from ‘student_detail’ table.mysql> Delimiter ; mysql> CALL selectdetails(); +-----------+-------------+------------+ | Studentid | StudentName | address    | +-----------+-------------+------------+ |       100 | Gaurav      | Delhi      | |       101 | Raman       | Shimla     | |       103 | Rahul       | Jaipur     | |       104 | Ram         | Chandigarh | |       105 | Mohan       | Chandigarh | +-----------+-------------+------------+ 5 rows in set (0.00 sec) Query OK, 0 rows affected (0.01 sec)

Read More

What is the default type of a hexadecimal value in MySQL?

Jai Janardhan
Jai Janardhan
Updated on 11-Feb-2020 285 Views

As we know that in numeric contexts the hexadecimal values act like integers and in string contexts they act like binary string. It can be understood with the help of the following example,mysql> Select X'5455544F5249414C53504F494E54'; +---------------------------------+ | X'5455544F5249414C53504F494E54' | +---------------------------------+ | TUTORIALSPOINT                  | +---------------------------------+ 1 row in set (0.07 sec)But, if we are talking about default type of hexadecimal value in MySQL, then it is a string.

Read More

While running MySQL statements in batch mode, how can we print, along with output, which statements are getting executed?

Srinivas Gorla
Srinivas Gorla
Updated on 11-Feb-2020 352 Views

By using –v option in batch mode, the MySQL statements can be printed along with output. For example, after running the same query in batch mode with –v option we will get the statement printed along with output.C:\Program Files\MySQL\bin>mysql -u root -p gaurav < hh.sql -v Enter password: ***** -------------- select * from hh -------------- id 1 2It is showing the statement select * from hh which is written in the file hh.sql.

Read More
Showing 1011–1020 of 3,404 articles
« Prev 1 100 101 102 103 104 341 Next »
Advertisements