How can we use SET statement to assign a SELECT result to a MySQL user variable?

radhakrishna
Published on 20-Feb-2018 15:17:48
For using the SET statement to assign a SELECT result to a user variable we need to write the SELECT statement as a subquery within parentheses. The condition is that the SELECT statement must have to return a single value. To make it understand we are using the data from ... Read More

What happens if I will assign a value to a MySQL user variable using a statement that returns multiple rows?

Srinivas Gorla
Published on 20-Feb-2018 15:16:56
In case, if we will assign a value to a user variable using a statement that returns multiple rows then the value from the last row would be saved in that user variable because user variables can save the only single value. Following the example, in which we are using ... Read More

What MySQL would return if we refer a user variable which is not assigned any value explicitly?

mkotla
Published on 20-Feb-2018 15:14:56
In case, when we refer a user variable which is not assigned any value explicitly, MySQL would return NULL. In other words, its value would be NULL. Following example would illustrate it −mysql> Select @X, @Y, @Z, @S, @G; +------+-------+----------+------+------+ | @X   | @Y    | @Z     ... Read More

What is the use of MySQL TRUNCATE() function?

Anjana
Published on 20-Feb-2018 15:13:50
MySQL TRUNCATE() function is used to return the value of X truncated to D number of decimal places. If D is 0, then the decimal point is removed. If D is negative, then D number of values in the integer part of the value is truncated. Its syntax can be ... Read More

What do you mean MySQL user variables and how can we assign values to them?

Giri Raju
Published on 20-Feb-2018 15:13:35
MySQL user variables are written as @variable and it may be set to an integer, real, string or NULL value. With the help of SET statement, we can assign a value to the user variable. We can use either = or := as the assignment operator while assigning the values ... Read More

What MySQL returns if the argument of QUOTE() function is NULL?

Ankith Reddy
Published on 20-Feb-2018 15:13:18
MySQL returns NULL if the argument of QUOTE() function is NULL.Examplemysql> Select QUOTE(NULL); +-------------+ | QUOTE(NULL) | +-------------+ | NULL         +-------------+ 1 row in set (0.00 sec) mysql> Select Name, QUOTE(NULL) from student where id = 1; +--------+-------------+ | Name   | ... Read More

How to replicate a string for a specified number of times in MySQL?

Swarali Sree
Published on 20-Feb-2018 15:11:58
With the help of MySQL REPEAT() function, we can replicate a string for a specified number of times.SyntaxREPEAT(Str, No.)Here Str is the string which is to be replicated for a specified number of times.No. is the numerical value which indicates that how many times the string would be repeated.Examplemysql> Select REPEAT('#*', ... Read More

How does MySQL QUOTE() function work with comparison values?

Arjun Thakur
Published on 20-Feb-2018 15:07:15
When QUOTE() function used with WHERE clause then the output depends upon the comparison values returned by WHERE clause. Following example will exhibit it −Examplemysql> Select Name, ID, QUOTE(Subject)AS Subject from Student WHERE Subject = 'History'; +-------+------+-----------+ | Name  | ID   | Subject   | +-------+------+-----------+ | Aarav ... Read More

Which MySQL function can be used to append values of a column with single quotes?

Sai Subramanyam
Published on 20-Feb-2018 15:05:16
MySQL QUOTE() function can be used to append values of a column with single quotes. For this, we must have to pass column name as the argument of QUOTE() function. Data from ‘Student’ table is used to demonstrate it as follows Example mysql> Select Name, ID, QUOTE(Subject)AS Subject from ... Read More

How MySQL LOCATE() function is different from its synonym functions i.e. POSITION() and INSTR() functions?

Rama Giri
Published on 20-Feb-2018 15:02:33
As all of these functions are used to return the position of a substring within a string but LOCATE() function is a bit different from POSITION() and INSTR() function. In both POSITION() AND INSTR() functions, we cannot manage the starting position of search with the help of argument as position ... Read More
Advertisements