Found 4219 Articles for MySQLi

How MySQL handles the empty and null values for enumerations?

seetha
Updated on 20-Jun-2020 08:48:00

945 Views

MySQL accepts empty values for enumeration only if SQL mode is not set as TRADITIONAL, STRICT_TRANS_TABLES or STRICT_ALL_TABLES. Otherwise, MySQL would not accept empty values and throws an error. As we know that each enumeration value is having an index value, the empty value would have 0 index value.Examplemysql> SET SQL_MODE ='Traditional'; Query OK, 0 rows affected (0.00 sec) mysql> Insert into result(id, name, grade) values(100, 'Raman', ''); ERROR 1265 (01000): Data truncated for column 'Grade' at row 1Now, after changing SQL mode we would be able to insert empty string as follows −mysql> Set SQL_MODE =''; Query OK, ... Read More

What MySQL returns if the list of strings, provided as argument in FIELD() function, are NULL?

Ankith Reddy
Updated on 20-Jun-2020 08:43:16

64 Views

In case if all the arguments (list of strings) of FIELD() function are NULL then MySQL will return 0 as output.Examplemysql> Select FIELD('Ram',NULL,NULL,NULL,NULL); +----------------------------------+ | FIELD('Ram',NULL,NULL,NULL,NULL) | +----------------------------------+ |                               0  | +----------------------------------+ 1 row in set (0.00 sec)

What MySQL returns if the search string, provided in FIELD() function, is NULL?

Vikyath Ram
Updated on 20-Jun-2020 08:42:50

73 Views

As we know that NULL fails equality comparison with any value hence if the search string, provided in FIELD() function, is NULL then MySQL returns 0 as output.Examplemysql> Select FIELD(NULL,'Ram','is','good','boy'); +-------------------------------------+ | FIELD(NULL,'Ram','is','good','boy') | +-------------------------------------+ |                                   0 | +-------------------------------------+ 1 row in set (0.00 sec)

What MySQL returns if the search string is not in the list of strings provided as argument in FIELD() function?

Anjana
Updated on 20-Jun-2020 08:42:27

61 Views

Suppose if the search string is not in the list of strings provided as the arguments in FIELD() function then MySQL will return 0 as output.Examplemysql> Select FIELD('Ram','New','Delhi'); +----------------------------+ | FIELD('Ram','New','Delhi') | +----------------------------+ |                         0  | +----------------------------+ 1 row in set (0.00 sec)

In MySQL, which function we can use to find the index position of a particular string from a list of strings?

Monica Mona
Updated on 20-Jun-2020 08:41:52

531 Views

We can use FIELD() function to find the index position of a particular string from a list of strings.SyntaxFIELD(str search,String1, String2,…StringN)Here, the str search is the string whose index number we want to search and String1, String …StringN is the list of strings from which the search would happen.Examplemysql> Select FIELD('good', 'Ram', 'is', 'a', 'good', 'boy')AS 'Index Number of good'; +----------------------+ | Index Number of good | +----------------------+ |                  4   | +----------------------+ 1 row in set (0.00 sec)

How to show that each MySQL enumeration has an index value?

Rishi Rathor
Updated on 20-Jun-2020 08:46:23

326 Views

Actually, the elements listed in the ENUM column specifications are assigned index numbers which begin with 1. Here the term “index” is indicating towards the position within the list of enumeration values and they are not related to table indexes. With the help of following examples we can show that each MySQL enumeration has an index value −By inserting index number instead of enumeration valueWe can insert the values in ENUM column with the help of their index numbers rather than writing the values. For example, in the table below we have two ENUM values ‘pass’ and ‘fail’. As ‘pass’ ... Read More

How can CONCAT_WS() function be used with MySQL WHERE clause?

Sharon Christine
Updated on 30-Jan-2020 07:26:58

312 Views

When we use CONCAT_WS() function with WHERE clause then the output would be based upon the condition provided in WHERE clause. It can be understood from the example of ‘Student’ table as followsExamplemysql> Select CONCAT_WS(' ',Name, Last_name, 'Resident of', Address, 'is studying', Subject)AS 'Student Detail' from student WHERE id = 20; +----------------------------------------------------------------+ | Student Detail                                                 | +----------------------------------------------------------------+ | Gaurav Rathore Resident of Jaipur is studying Computers        | +----------------------------------------------------------------+ 1 row in set (0.00 sec)

What MySQL returns if we use NULL, as both the arguments, as one of the argument and as a separator, in CONCAT_WS() function?

Ayyan
Updated on 20-Jun-2020 08:37:20

63 Views

NULL as both argumentsMySQL returns blank output if we will use NULL as both of the arguments in CONCAT_WS() function.Examplemysql> Select CONCAT_WS('', NULL, NULL); +-------------------------+ | CONCAT_WS('', NULL, NULL) | +-------------------------+ |                         | +-------------------------+ 1 row in set (0.00 sec)NULL as one of the argumentMySQL returns the value of the other argument as output if we will use NULL as one of the argument in CONCAT_WS() function.Examplemysql> Select CONCAT_WS('', NULL, 'Delhi'); +----------------------------+ | CONCAT_WS('', NULL, 'Delhi') | +----------------------------+ | Delhi                 ... Read More

What is the difference between CONCAT() and CONCAT_WS() functions?

Ankith Reddy
Updated on 20-Jun-2020 08:31:58

8K+ Views

Both CONCAT() and CONCAT_WS() functions are used to concatenate two or more strings but the basic difference between them is that CONCAT_WS() function can do the concatenation along with a separator between strings, whereas in CONCAT() function there is no concept of the separator. Other significance difference between them is that CONCAT()function returns NULL if any of the argument is NULL, whereas CONCAT_WS() function returns NULL if the separator is NULL.ExampleThe example below demonstrate the difference between CONCAT() and CONCAT_WS() function −mysql> Select CONCAT('Ram', 'is', 'a', 'good', 'student') AS 'Example of CONCAT()'; +---------------------+ | Example of CONCAT() | +---------------------+ ... Read More

What is the maximum length of data we can put in a TEXT column in MySQL?

mkotla
Updated on 20-Jun-2020 08:31:13

3K+ Views

As we know TEXT data objects are useful for storing long-form text strings. The different TEXT objects offer a range of storage space from 255 bytes to 4 Gb. The following table shows the storage of different kinds of TEXT data type −Type of BLOBMaximum amount of Data that can be storedOverheadTINYTEXTUp to 255 bytes1 byteTEXTUp to 64 Kb2 bytes MEDIUMTEXTUp to 16 Mb3 bytesLONGTEXTUp to 4 Gb4 bytes

Advertisements