MySQLi Articles

Page 108 of 341

What MySQL returns on running the INSERT INTO statement without giving the column name and values both?

Chandu yadav
Chandu yadav
Updated on 05-Feb-2020 272 Views

When we run the INSERT INTO statement without giving the columns name/s and values both then MySQL will store NULL as the value of the column/s of table. Consider the example given below in which we have created a table ‘Student’ with the following query −mysql> Create table Student(RollNO INT, Name Varchar(20), Class Varchar(15)); Query OK, 0 rows affected (0.17 sec)Now, we can run INSERT INTO statement without giving the columns name/s and values both as follows −mysql> Insert into Student() Values(); Query OK, 1 row affected (0.02 sec)We can see from the query below MySQL stores NULL as the ...

Read More

How can we change the default MySQL database to the given database?

Jai Janardhan
Jai Janardhan
Updated on 05-Feb-2020 576 Views

Suppose currently we are using a tutorial database so it would be the default MySQL database for subsequent queries. Now, with the help of USE db_name statement, we can change the default database to other given database subsequent queries.mysql> USE Sample Database changedThe database has been changed to Sample from the tutorial. To verify this we can run the following command −mysql> select database(); +------------+ | database() | +------------+ | sample     | +------------+ 1 row in set (0.00 sec)

Read More

What is the use of escape character () in text file while importing the data from text file to MySQL table?

Prabhas
Prabhas
Updated on 04-Feb-2020 424 Views

Use of escape character (\) would become very essential when we want to insert a comma or any other character between the values of a filed. It can be understood with the help of an example. Suppose we want to import the data from a text file named A.txt, having the following data, into a MySQL table −id,   Name,    Country,       Salary 105,  Chum,    Marsh, USA,     11000 106,  Danny,   Harrison, AUS,  12000Here, we can see that the filed name has two values first name, last name separated by a comma. Now, the ...

Read More

How can we use MySQL INSTR() function with WHERE clause?

Chandu yadav
Chandu yadav
Updated on 04-Feb-2020 1K+ Views

When we use INSTR() function with MySQL WHERE clause, we need to provide column name of the table as the first argument and the substring as second argument along with a comparison operator. Following is an example using ‘Student’ table to demonstrate it −ExampleSuppose we have the following values in ‘Student’ table −mysql> Select * from Student; +------+---------+---------+-----------+ | Id   | Name    | Address | Subject   | +------+---------+---------+-----------+ | 1    | Gaurav  | Delhi   | Computers | | 2    | Aarav   | Mumbai  | History   | | 15   | Harshit | ...

Read More

How can we import the text file, having data on the same line with a separator, into MySQL table?

varun
varun
Updated on 04-Feb-2020 333 Views

Actually, we can write the data on the same line in the text file by using a separator. In this case, while importing this text file into MySQL table then we must have to use ‘LINES TERMINATED BY’ option. It can be understood with the help of the following example −Suppose we are using ‘|’ as the LINE TERMINATOR symbol in a text file as follows −id, Name, Country, Salary|105, Chum*, Marsh, USA, 11000|106, Danny*, Harrison, AUS, 12000Now while importing this text file into MySQL table then we need to mention ‘LINE TERMINATED BY’ option also in the query as ...

Read More

How can we import only specific columns from the text file, into MySQL table?

Sravani S
Sravani S
Updated on 04-Feb-2020 1K+ Views

Suppose if we have the values for some specific columns in the text file and MySQL table, in which we want to import the data, is having an extra column(s) then by mentioning the names of the columns in the query we can upload the values of those specific columns only. It can be understood with the help of the following example −ExampleSuppose we are having the values of columns ‘id’, ‘Name’ and ‘Salary’ only in the text file as follows −105, Chum, 11000 106, Danny, 12000Now while importing this text file into MySQL table then we need to mention ...

Read More

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

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 04-Feb-2020 594 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, INSTR() function contains a string from which it will find the position of the first occurrence of the substring if present. In case of integers, FIND_IN_SET() is much more suitable than INSTR() function. It can be understood by the following exampleExamplemysql> Select IF(INSTR('10, 11, 12, 13', 2) > 0, 1, 0) As Result; +--------+ | Result ...

Read More

How it is possible in MySQL to find a string of specified pattern within another string?

Ankith Reddy
Ankith Reddy
Updated on 04-Feb-2020 147 Views

We can find a string of specified pattern within another string by using LIKE operator along with WILDCARDS.SyntaxLIKE specific_patternSpecific_pattern is the pattern of string we want to find out within another string.ExampleSuppose we have a table named ‘student’ having names of the students and we want to get the details of all those students which are having the pattern of string ‘av’ within their names. It can be done with the help of following MySQL query −mysql> Select * from Student Where Name LIKE '%av%'; +------+--------+---------+-----------+ | Id   | Name   | Address | Subject   | +------+--------+---------+-----------+ ...

Read More

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

radhakrishna
radhakrishna
Updated on 04-Feb-2020 4K+ 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

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

Paul Richard
Paul Richard
Updated on 04-Feb-2020 184 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.

Read More
Showing 1071–1080 of 3,404 articles
« Prev 1 106 107 108 109 110 341 Next »
Advertisements