Found 4219 Articles for MySQLi

How can we use MySQL LPAD() and RPAD() functions in the same query for padding the string to both sides, left and right, of the original string?

Lakshmi Srinivas
Updated on 06-Feb-2020 06:15:59

672 Views

For achieving this, we must have to use one of the functions as the 1st argument of the other function. In other words, either RPAD() function would be the 1st argument of LPAD() function or LPAD() function would be the 1st argument of RPAD() function. It can be understood with the help of the following exampleExamplemysql> Select RPAD(LPAD(' My name is Ram ', 23, '* '), 30, '* '); +------------------------------------------------+ | RPAD(LPAD(' My name is Ram ', 23, '* '), 30, '* ') | +------------------------------------------------+ | * * * * My name is Ram * * * *     ... Read More

In MySQL, how can we pad a string with another string?

karthikeya Boyini
Updated on 06-Feb-2020 06:19:15

96 Views

MySQL has two functions namely LPAD() and RPAD() with the help of which we can pad a string with another string.LPAD() function, as the name suggests, left pads a string with another string. Following is the syntax for using it in MySQLSyntaxLPAD(original_string, @length, pad_string)Here,  original_string is the string in which we pad another string.@length is the total length of the string returned after padding.Pad_string is the string which is to be padded with original_string.Examplemysql> Select LPAD('My name is Ram', 22, '* '); +--------------------------------+ | LPAD('My name is Ram', 22, '* ') | +--------------------------------+ | * * * * My name ... Read More

What MySQL INSERT() function returns if the number of characters to be removed exceeds the number of characters available in original string?

Chandu yadav
Updated on 06-Feb-2020 06:20:16

48 Views

In case if the number of characters to be removed exceeds the number of characters available in original string then MySQL INSERT() function will continue to remove the characters until the end of the original string.Examplemysql> Select INSERT('myteststring',3,15,'original'); +----------------------------------------+ | INSERT('myteststring',3,15,'original') | +----------------------------------------+ | myoriginal                             | +----------------------------------------+ 1 row in set (0.00 sec)

How can we use INSERT() function to insert a new string into the value of a column of MySQL table?

Rishi Raj
Updated on 06-Feb-2020 06:31:51

118 Views

For this purpose, We need to use the name of the column as the first parameter i.e. at the place of an original string, of the INSERT() function. Following example will exhibit it −ExampleSuppose we want to add ‘/Old’ with the values of ‘year_of_admission’ column of ‘Student’ table then we need to write following query −mysql> Select INSERT(year_of_admission, 5, 0, '/Old')As 'Old Admissions' From Student; +-----------------+ | Old Admissions  | +-----------------+ | 2001/Old        | | 2010/Old        | | 2009/Old        | | 2017/Old        | | 2000/Old     ... Read More

How can I export values based on some conditions from MySQL table into a file?

Srinivas Gorla
Updated on 06-Feb-2020 06:36:45

361 Views

We can use the conditions in WHERE clause while exporting the data from MySQL table to a file. It can be understood with the help of an example −ExampleSuppose we are having following data from table ‘Student_info’ −mysql> Select * from Student_info; +------+---------+------------+------------+ | id   | Name    | Address    | Subject    | +------+---------+------------+------------+ | 101  | YashPal | Amritsar   | History    | | 105  | Gaurav  | Chandigarh | Literature | | 125  | Raman   | Shimla     | Computers  | | 130  | Ram     | Jhansi     | ... Read More

What happens if the position of insertion, in MySQL INSERT() function, is out of range?

Swarali Sree
Updated on 06-Feb-2020 06:37:37

61 Views

MySQL INSERT() function performs no insertion if the position of insertion is out of range. The position of insertion can be out of range in the case when we pass a negative or 0(zero) value or the value goes beyond the value of a total number of characters in an original string by 2. It can be understood with the help of the following example −ExampleThe query below will perform no insertion because the position of insertion is out of range i.e. a negative value.mysql> Select INSERT('Virat', -1, 5, 'Kohli'); +-------------------------------+ | INSERT('Virat', -1, 5, 'Kohli') | +-------------------------------+ | Virat ... Read More

What kind of settings can we do to a text file by query while exporting the values from MySQL table into a text file?

vanithasree
Updated on 20-Jun-2020 09:26:54

76 Views

While exporting the data from MySQL table to a text file we can use ‘FIELDS TERMINATED BY’, ‘ENCLOSED BY’, ‘LINES TERMINATED BY’ and other options too to put the values of fields in different settings of the text file. It can be illustrated with the help of the following example −ExampleSuppose we are having following data from table ‘Student_info’ −mysql> Select * from Student_info; +------+---------+------------+------------+ | id   | Name    | Address    | Subject    | +------+---------+------------+------------+ | 101  | YashPal | Amritsar   | History    | | 105  | Gaurav  | Chandigarh | Literature | | ... Read More

Why we cannot use comparison operator(=) for getting the rows with NULL from a table?

Ankith Reddy
Updated on 06-Feb-2020 06:41:12

42 Views

We cannot use = (comparison operator) because we know that NULL is not a value. If we want to get the rows with NULL from a table then we need to use IS NULL operator in MySQL query. Following example using the data from ‘employee’ table will exhibit it −Examplemysql> Select * from Employee WHERE Salary IS NULL; +----+-------+--------+ | ID | Name  | Salary | +----+-------+--------+ | 7  | Aryan | NULL   | | 8  | Vinay | NULL   | +----+-------+--------+ 2 rows in set (0.00 sec)The query above use IS NULL operator and produces ... Read More

How can we export some field(s) from MySQL table into a text file?

Abhinanda Shri
Updated on 20-Jun-2020 09:23:46

646 Views

It can be done by providing the column(s) names in the SELECT … INTO OUTFILE statement while exporting the data from MySQL table into a file. We are illustrating it with the help of the following example −ExampleSuppose we are having following data from table ‘Student_info’ −mysql> Select * from Student_info; +------+---------+------------+------------+ | id   | Name    | Address    | Subject    | +------+---------+------------+------------+ | 101  | YashPal | Amritsar   | History    | | 105  | Gaurav  | Chandigarh | Literature | | 125  | Raman   | Shimla     | Computers  | | 130 ... Read More

How can we export all the data from MySQL table into a text file?

Ankitha Reddy
Updated on 30-Jul-2019 22:30:21

573 Views

It can be done with the help of SELECT … INTO OUTFILE statement. We are illustrating it with the help of the following example − Example Suppose we are having following data from table ‘Student_info’: mysql> Select * from Student_info; +------+---------+------------+------------+ | id | Name | Address | Subject | +------+---------+------------+------------+ | 101 | YashPal | Amritsar | History | | 105 | Gaurav | Chandigarh | Literature | | 125 | Raman | Shimla ... Read More

Advertisements