- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 4378 Articles for MySQL
80 Views
In this case, MySQL will not pad anything and truncate the characters from the original string up to the value of length provided as the argument in LPAD() or RPAD() functions.Examplemysql> Select LPAD('ABCD',3,'*'); +--------------------+ | LPAD('ABCD',3,'*') | +--------------------+ | ABC | +--------------------+ 1 row in set (0.00 sec) mysql> Select RPAD('ABCD',3,'*'); +--------------------+ | RPAD('ABCD',3,'*') | +--------------------+ | ABC | +--------------------+ 1 row in set (0.00 sec)We can observe from the above example that both the functions do not pad ‘*’ and truncate the original string up to the length specified i.e. 3 as the argument.
59 Views
Suppose if we want to make the output of REPEAT() function more readable then we can use another function/s with it. For example, if we want to add space or some other character between the repeated values then we can use CONCAT() function.Examplemysql> Select REPEAT(CONCAT(' *', Subject, '* '), 3)AS Subject_repetition from student; +-----------------------------------------+ | Subject_repetition | +-----------------------------------------+ | *Computers* *Computers* *Computers* | | *History* *History* *History* | | *Commerce* *Commerce* *Commerce* | | *Computers* *Computers* *Computers* | ... Read More
142 Views
For repeating the values stored in a data column of MySQL table, the name of the column must be passed as the first argument of REPEAT() function. The data from ‘Student’ table is used to demonstrate it:Examplemysql> Select REPEAT(Name,3)AS Name from student; +-----------------------+ | Name | +-----------------------+ | GauravGauravGaurav | | AaravAaravAarav | | HarshitHarshitHarshit | | GauravGauravGaurav | | YashrajYashrajYashraj | +-----------------------+ 5 rows in set (0.00 sec)
377 Views
MySQL server supports prepared statements, which are useful when we want to run many queries that differ only in very small details. We can prepare a statement and then execute it multiple times and each time with different data values. Basically, prepared statements in MySQL take advantage of client/server binary protocol. Prepared statements provide enhanced performance because the complete statement is parsed only one by the server.Followings are the steps for using prepared statements in MySQL −Prepare the statement It is the first step in which we will prepare a statement by using PREPARE statement. For example, following is a statement ... Read More
456 Views
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 ‘Tender’ table which is as follows −mysql> select * from Tender; +----+---------------+--------------+ | Sr | CompanyName | Tender_value | +----+---------------+--------------+ | 1 | Abc Corp. | 250.369003 | | 2 | Khaitan Corp. | 265.588989 | | 3 | Singla group. | 220.255997 | ... Read More
110 Views
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 data from table ‘Tender’, will exhibit it −Examplemysql> select * from Tender; +----+---------------+--------------+ | Sr | CompanyName | Tender_value | +----+---------------+--------------+ | 1 | Abc Corp. | 250.369003 | | 2 | Khaitan Corp. | 265.588989 | | 3 | Singla group. | 220.255997 ... Read More
69 Views
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 | @S | @G | +------+-------+----------+------+------+ | Ram | Shyam | Students | 5000 | NULL | +------+-------+----------+------+------+ 1 row in set (0.00 sec)We can see from the above result set that @X, @Y, @Z and @S has been assigned values explicitly and they returned the values ... Read More
142 Views
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('#*',5); +----------------+ | REPEAT('#*',5) | +----------------+ | #*#*#*#*#* | +----------------+ 1 row in set (0.00 sec)
74 Views
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 | QUOTE(NULL) | +--------+-------------+ | Gaurav | NULL | +--------+-------------+ 1 row in set (0.08 sec)
86 Views
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 | 2 | 'History' | +-------+------+-----------+ 1 row in set (0.00 sec)