Database Articles

Page 159 of 546

In MySQL, how can we insert a substring at the specified position in a string?

Swarali Sree
Swarali Sree
Updated on 22-Jun-2020 701 Views

We can use a MySQL INSERT() function to insert a substring at the specified position in a string.SyntaxINSERT(original_string, @pos, @len, new_string)Here, original_string is the string in which we want to insert a new string at the place of some specific number of characters.@pos is the position at which the insertion of the new string should start.@len is the number of characters that should delete from the original string. The starting point of the deletion of characters is the value of @pos.New_string is the string we want to insert into the original string.Examplemysql> Select INSERT('MySQL Tutorial', 7, 8, '@Tutorialspoint'); +------------------------------------------------+ | ...

Read More

How can I create a MySQL stored procedure that returns multiple values from a MySQL table?

Nikitha N
Nikitha N
Updated on 22-Jun-2020 2K+ Views

We can create a stored procedure with both IN and OUT parameters to get multiple values from a MySQL table. To make it understand we are taking an example of a table named ‘student_info’ having the following data −mysql> Select * from student_info; +------+---------+------------+------------+ | id   | Name    | Address    | Subject    | +------+---------+------------+------------+ | 101  | YashPal | Amritsar   | History    | | 105  | Gaurav  | Jaipur     | Literature | | 110  | Rahul   | Chandigarh | History    | | 125  | Raman   | Bangalore  | Computers  | ...

Read More

How can user variables be used in MySQL stored procedure?

usharani
usharani
Updated on 22-Jun-2020 291 Views

In MySQL stored procedure, user variables are referenced with an ampersand i.e. @, prefixed to the user variable names. For example, @A, @B, etc. are user variables. To demonstrate it, we are creating the following procedure −mysql> DELIMITER // ; mysql> CREATE PROCEDURE Proc_Uservariables()    -> BEGIN    -> SET @A = 100;    -> SET @B = 500;    -> SELECT @A,@B,@A+@B;    -> END // Query OK, 0 rows affected (0.00 sec) mysql> Delimiter ; // mysql> CALL Proc_Uservariables(); +------+------+-------+ | @A   | @B   | @A+@B | +------+------+-------+ |  100 |  500 |   600 | +------+------+-------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.01 sec)

Read More

What happens if the argument ‘count’ in MySQL SUBSTRING_INDEX() function has the value greater than the total number of occurrences of delimiter?

Ayyan
Ayyan
Updated on 22-Jun-2020 223 Views

MySQL SUBSTRING_INDEX() function will return the same string as output if the argument ‘count’ has the value greater than the total number of occurrences of delimiter. It can be demonstrated with the following example −mysql> Select SUBSTRING_INDEX('My Name is Ram','a',3); +-----------------------------------------+ | SUBSTRING_INDEX('My Name is Ram','a',3) | +-----------------------------------------+ | My Name is Ram                          | +-----------------------------------------+ 1 row in set (0.00 sec)The above query returns the same string because 3 is greater than the total number of occurrences of delimiter provided as argument i.e. ‘a’. There are only two ‘a’ in the string.

Read More

What are the default rules used by the parser for parsing names of built-in functions?

Monica Mona
Monica Mona
Updated on 22-Jun-2020 195 Views

Actually, when a parser encounters a word that is the name of a built-in function, it must determine whether the name represents a function call or is instead a non-expression reference to an identifier such as a table or column name. consider the following queries −1. Select sum(salary) from employee; 2. Create table sum (i int);In the first query SUM is a reference to a function call and in the second query, it is referencing to table name.Parser follows the following rules to distinguish whether their names are being used as function calls or as identifiers in non-reference context −Rule1 ...

Read More

What is the use of IGNORE_SPACE SQL mode?

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

The IGNORE_SPACE SQL mode can be used to modify how the parser treats function names that are whitespace-sensitive. Following are the cases in which we can use IGNORE_SPACE SQL mode −Case-1  − When IGNORE_SPACE SQL mode is disabledAfter disabling the IGNORE_SPACE SQL mode, the parser interprets the name as a function call when there is no whitespace between the name and the following parenthesis. This also occurs when the function name is used in a non-expression context. It can be understood from the following query −mysql> Create table SUM(Id Int); ERROR 1064 (42000): You have an error in your SQL ...

Read More

How MySQL IF ELSE statement can be used in a stored procedure?

varma
varma
Updated on 22-Jun-2020 17K+ Views

MySQL IF ELSE statement implements a basic conditional construct when the expression evaluates to false. Its syntax is as follows −IF expression THEN    statements; ELSE    else-statements; END IF;The statements must end with a semicolon.To demonstrate the use of IF ELSE statement within MySQL stored procedure, we are creating the following stored procedure which is based on the values, as shown below, of the table named ‘student_info’ −mysql> Select * from student_info; +------+---------+------------+------------+ | id   | Name    | Address    | Subject    | +------+---------+------------+------------+ | 101  | YashPal | Amritsar   | History    | | 105  | ...

Read More

How can I create a stored procedure to select values on the basis of some conditions from a MySQL table?

seetha
seetha
Updated on 22-Jun-2020 422 Views

We can create a stored procedure with IN and OUT operators to SELECT records, based on some conditions, from MySQL table. To make it understand we are taking an example of a table named ‘student_info’ having the following data −mysql> Select * from student_info; +------+---------+------------+------------+ | id   | Name    | Address    | Subject    | +------+---------+------------+------------+ | 101  | YashPal | Amritsar   | History    | | 105  | Gaurav  | Jaipur     | Literature | | 110  | Rahul   | Chandigarh | History    | | 125  | Raman   | Bangalore  | ...

Read More

In MySQL, what is Bit-field notation and how it can be used to write bit-field value?

Sharon Christine
Sharon Christine
Updated on 22-Jun-2020 526 Views

Bit-field notation is the notation with the help of which we can write bit-field values. The syntax of Bit-field notation is as follows −Syntaxb’value’   OR 0bvalueHere, the value is a binary value written by using zeros and ones.The mainly Bit-filed notation is convenient for specifying values to be assigned to BIT columns of MySQL table. Following example will demonstrate it −mysql> Create table bit_testing (bittest BIT(8)); Query OK, 0 rows affected (1.09 sec) mysql> INSERT INTO bit_testing SET bittest = b'10101010'; Query OK, 1 row affected (0.07 sec) mysql> INSERT INTO bit_testing SET bittest = b'0101'; Query ...

Read More

What is the default type of a bit value assigned to user variables?

Arushi
Arushi
Updated on 22-Jun-2020 209 Views

By default, the bit values assigned to the user variables are binary strings. It can be illustrated by assigning the bit value to a user variable and then by retrieving them as follows −mysql> SET @abc = 0b1000011; Query OK, 0 rows affected (0.00 sec) mysql> Select @abc; +------+ | @abc | +------+ | C    | +------+ 1 row in set (0.00 sec)The above result set shows that the default type of a bit value assigned to user variables are binary strings.

Read More
Showing 1581–1590 of 5,456 articles
« Prev 1 157 158 159 160 161 546 Next »
Advertisements