Found 4219 Articles for MySQLi

How can we MySQL LOAD DATA INFILE statement with ‘ENCLOSED BY’ option to import data from text file into MySQL table?

seetha
Updated on 20-Jun-2020 09:15:29

715 Views

Sometimes the input text files have the text fields enclosed by double quotes and to import data from such kind of files we need to use the ‘ENCLOSED BY’ option with LOAD DATA INFILE statement. We are considering the following example to make it understand −ExampleFollowings are the comma-separated values in A.txt file −100, ”Ram”, ”INDIA”, 25000 101, ”Mohan”, ”INDIA”, 28000We want to import this data into the following file named employee2_tbl −mysql> Create table employee2_tbl(Id Int, Name Varchar(20), Country Varchar(20), Salary Int); Query OK, 0 rows affected (0.1 sec)Now, the transfer of data from a file to a ... Read More

Do we have any lower and upper limit of base in MySQL CONV() function? What happens if out of limit base is provided in CONV() function?

Ankith Reddy
Updated on 04-Feb-2020 05:56:40

59 Views

The base must be greater than 2 and less than 36 i.e. the lower limit of a base is 2 and the upper limit is 36. It is applied to both from_base and to_base values. If in case we provide out of limit values of the base then MySQL returns NULL as the output. Following example will demonstrate it −Examplemysql> Select CONV(10,10,38); +----------------+ | CONV(10,10,38) | +----------------+ | NULL           | +----------------+ 1 row in set (0.00 sec) mysql> Select CONV(10,72,2); +---------------+ | CONV(10,72,2) | +---------------+ | NULL          | +---------------+ 1 row in set (0.00 sec) mysql> Select CONV(10,10,1); +---------------+ | CONV(10,10,1) | +---------------+ | NULL          | +---------------+ 1 row in set (0.00 sec)

What happens if the value of number ‘N’ in CONV() function is not as per accordance with its base?

Paul Richard
Updated on 04-Feb-2020 05:57:20

58 Views

MySQL returns 0 as output if the number given in CONV() function is not as per accordance with its base. Suppose, if we want to convert decimal number 9 into the number in binary number system then in this case the value of from_base must be 10 but if we provide 8 as the value of from_base then MySQL returns 0 as output.Examplemysql> Select CONV(9,8,2); +-------------+ | CONV(9,8,2) | +-------------+ | 0           | +-------------+ 1 row in set (0.00 sec)As we know that the values of octal number system must be between 0 to 7, hence the number system for number 9 must be decimal i.e. 10.

How can we import data from .txt file into MySQL table?

radhakrishna
Updated on 04-Feb-2020 05:58:37

3K+ Views

It can be done with the help of LOAD DATA INFILE statement. To illustrate the concept we are having the following data, separated by tab, in ‘A.txt’ whose path is d:/A.txt −100 John  USA 10000 101 Paul  UK  12000 102 Henry NZ  11000 103 Rick  USA 17000 104 Corey USA 15000We want to load the data of A.txt into the following table named employee_tbl −mysql> Create table employee_tbl(Id Int, Name varchar(20), Country Varchar(20), Salary Int); Query OK, 0 rows affected (0.91 sec)Now, the transfer of data from a file to a database table can be done with the help ... Read More

How can we transfer information between MySQL and data files?

mkotla
Updated on 20-Jun-2020 09:14:18

80 Views

Transferring the information between MySQL and data files mean importing data from data files into our database or exporting data from our database into files. MySQL is having two statements that can be used to import or export data between MySQL and data files −LOAD DATA INFILEThis statement is used for importing the data from data files into our database. It reads data records directly from a file and inserts them into a table. Its syntax would be as follows −SyntaxLOAD DATA LOCAL INFILE '[path/][file_name]' INTO TABLE [table_name ];Here, the path is the address of the file.file_name is the name ... Read More

What happens if a NULL argument is provided in MySQL CONV() function?

Sai Subramanyam
Updated on 30-Jul-2019 22:30:21

78 Views

MySQL will return NULL as the output if any of the argument of CONV() function is NULL or if the value provided for the base is out of limit(i.e. not between minimum 2 and maximum 36). Following examples would demonstrate it. Example mysql> Select CONV(10,NULL,2); +-----------------+ | CONV(10, NULL,2)| +-----------------+ | NULL | +-----------------+ 1 row in set (0.00 sec) mysql> Select CONV(10,10, NULL); +------------------+ | CONV(10,10, NULL)| +------------------+ | NULL | +------------------+ 1 row in set (0.00 sec) mysql> Select CONV(NULL,10,2); +-----------------+ | CONV(null,10,2) | +-----------------+ | NULL | +-----------------+ 1 row in set (0.00 sec)

In MySQL, how can we convert a value from one number system to the value in another number system?

Moumita
Updated on 03-Feb-2020 06:11:19

59 Views

With the help of MySQL CONV() function, a value from one number system can be converted to the other number system.SyntaxCONV(N, from_base, to_base)Here, ‘N’ is the number which is to be converted, ‘from_base’ is the current base of that number and ‘to_base’ is the base in which that number has to be converted. ‘N’ is interpreted as an integer but it may be specified as integer or a string.Examplemysql> Select CONV('10', 10, 2) AS 'DECIMAL TO BINARY'; +-------------------+ | DECIMAL TO BINARY | +-------------------+ | 1010              | +-------------------+ 1 row in set (0.00 sec)In ... Read More

When MySQL LOCATE() function returns NULL as the output?

Kumar Varma
Updated on 03-Feb-2020 06:11:55

218 Views

It will return NULL as the output when the value of either first argument i.e. substring or the value of second argument i.e. substring is NULL. Example below will demonstrate it −Examplemysql> Select LOCATE(NULL,'Ram is a good boy')As Result; +--------+ | Result | +--------+ | NULL   | +--------+ 1 row in set (0.00 sec) mysql> Select LOCATE('Ram',NULL)As Result; +--------+ | Result | +--------+ | NULL   | +--------+ 1 row in set (0.00 sec)

How can I manage the start position of searching in MySQL LOCATE() function?

Chandu yadav
Updated on 03-Feb-2020 06:12:45

87 Views

As we know that by default searching in LOCATE() function starts from beginning. We can manage the start position by giving an argument to specify the position from which we want to start the search in string. Following example will demonstrate it −Examplemysql> Select LOCATE('good','Ram is a good boy. Is Ram a good boy?',11)As Result; +--------+ | Result | +--------+ |     29 | +--------+ 1 row in set (0.00 sec)In the above example, we have given the value 11 as the argument for position. It means that MySQL will start searching from 11th position.

What is the difference between MySQL LOCATE() and FIND_IN_SET() functions?

Monica Mona
Updated on 03-Feb-2020 06:14:05

387 Views

As we know, both the functions are used to search a string from the arguments provided in them but there are some significant differences between them as followsFIND_IN_SET() function uses the string list that is itself a string containing the substring separated by commas. Whereas, LOCATE() function contains a string from which it will find the position of the first occurrence of the substring if present. In LOCATE() function we can manage the starting point of the search by providing an optional argument for a position. Whereas, for FIND_IN_SET() function MySQL do not provide such kind of flexibility and the search ... Read More

Advertisements