Nishtha Thakur

Nishtha Thakur

398 Articles Published

Articles by Nishtha Thakur

Page 21 of 40

How can I combine built-in-commands (g and G), used for executing a MySQL statement, with termination symbol semicolon (;) to get output without any error?

Nishtha Thakur
Nishtha Thakur
Updated on 22-Jun-2020 164 Views

As we know that built-in-commands (\G and \g) send the command to MySQL server for execution and with the help of Semicolon (;) MySQL determines the end of the statement. It is also known that both of them have different format of the result set. For combining them and getting the result without error, we need to write two queries, one query with either \G or \g and other with a semicolon (;) at the end, in a single statement.ExampleCombining \G and Semicolon (;) −mysql> Select * from student\G select * from ratelist; *************************** 1. row ***************************   Name: Gaurav ...

Read More

What are the most significant differences between MySQL functions and procedures?

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

The most significant difference between procedures and functions is that they are invoked differently and for different purposes. Other than that following are the differences between procedure and functions −A procedure does not return a value. Instead, it is invoked with a CALL statement to perform an operation such as modifying a table or processing retrieved records.On the other hand, a function is invoked within an expression and returns a single value directly to the caller to be used in the expression. That is, a function is used in expressions the same way as a constant, a built-in function, or ...

Read More

In MySQL, how can we declare a handler while handling errors?

Nishtha Thakur
Nishtha Thakur
Updated on 22-Jun-2020 728 Views

It is very important to handle the errors by throwing a proper error message. MySQL provides a handler to handle the error. We can declare a handler with the help of the following syntax −Syntax of handlerDECLARE handler_action FOR condition_value statement;The above syntax shows that we need to use DECLARE HANDLER statement to declare a handler. If a condition whose value matches the condition_value then MySQL will execute the statement and continue or exit the current code block based on the action. Followings are the three major things in the above syntax −Handler_action is of two types and can accept one ...

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 ...

Read More

How can we export data to a CSV file whose filename name contains timestamp at which the file is created?

Nishtha Thakur
Nishtha Thakur
Updated on 07-Feb-2020 601 Views

Sometimes we need to export data into a CSV file whose name has a timestamp at which that file is created. It can be done with the help of MySQL prepared statement. To illustrate it we are using the following example −ExampleThe queries in the following example will export the data from table ‘student_info’ to the CSV file having a timestamp in its name.mysql> SET @time_stamp = DATE_FORMAT(NOW(), '_%Y_%m_%d_%H_%i_%s'); Query OK, 0 rows affected (0.00 sec) mysql> SET @FOLDER = 'C:/mysql/bin/mysql-files'; Query OK, 0 rows affected (0.00 sec) mysql> SET @FOLDER = 'C:/mysql/bin/mysql-files/'; Query OK, 0 rows affected ...

Read More

How can we force MySQL out of TRADITIONAL mode?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jan-2020 161 Views

With the help of the following command we can force MySQL out of TRADITIONAL mode −mysql> Set SQL_MODE =''; Query OK, 0 rows affected (0.00 sec)

Read More

What MySQL returns if specified format string is not as per accordance with the date string passed as arguments to STR_TO_DATE() function?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jan-2020 595 Views

If the specified format string and date string did not match then MySQL will return NULL value as output along with a warning. Following is an example to understand the same −mysql> Select STR_TO_DATE('20172810', '%Y, %d%m'); +------------------------------------+ | STR_TO_DATE('20172810', '%Y, %d%m') | +------------------------------------+ | NULL                               | +------------------------------------+ 1 row in set, 1 warning (0.00 sec)The query above returns NULL as output because the format string is having a comma (, ) after %Y but date string is not having any comma after 2017.mysql> Show Warnings\G ...

Read More

How can it be possible to add 3 months interval in a MySQL date without using the word 'Months' with interval?

Nishtha Thakur
Nishtha Thakur
Updated on 29-Jan-2020 459 Views

It is possible with the help of keyword Quarter as follows −mysql> Select '2017-06-20' + INTERVAL 1 Quarter AS 'After 3 Months Interval'; +-------------------------+ | After 3 Months Interval | +-------------------------+ | 2017-09-20 | +-------------------------+ 1 row in set (0.00 sec)

Read More

Preserve select order within MySQL UNION?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 354 Views

It’s a good choice to use CASE statement. Do not use UNION. Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    ShippingDate datetime    ); Query OK, 0 rows affected (0.63 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(ShippingDate) values('2019-04-21'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(ShippingDate) values('2019-01-01'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(ShippingDate) values('2019-05-11'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(ShippingDate) values('2018-12-31'); Query OK, 1 row ...

Read More

C++ Program to Perform integer Partition for a Specific Case

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 210 Views

This is a C++ program to perform integer partition for a specific case. In this program, a positive integer n is given, and shall have to generate all possible unique ways to represent n as sum of positive integers.AlgorithmBegin    function displayAllUniqueParts(int m):    1) Set Index of last element k in a partition to 0    2) Initialize first partition as number itself, p[k]=m    3) Create a while loop which first prints current partition, then generates next partition. The loop stops    when the current partition has all 1s.    4) Display current partition as displayArray(p, k + ...

Read More
Showing 201–210 of 398 articles
« Prev 1 19 20 21 22 23 40 Next »
Advertisements