Found 4219 Articles for MySQLi

In MySQL, how we can get the corresponding string representation of the binary value of a number?

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

262 Views

In MySQL, BIN() function is used to get the corresponding string representation of the binary value of a number. It considers the number as a DECIMAL number. Syntax BIN(value) Here value, a BIGINT number, is the number whose binary value is to be retrieved. Example mysql> Select BIN(15); +---------+ | BIN(15) | +---------+ | 1111 | +---------+ 1 row in set (0.00 sec)

How does MySQL handle overflow during numeric expression assessment?

Govinda Sai
Updated on 20-Jun-2020 07:50:48

174 Views

As we know that MySQL will produce an error if overflow occurs during the assessment of numeric expressions. For example, the largest signed BIGNT is 9223372036854775807, so the following expression will produce an error −mysql> Select 9223372036854775807 + 1; ERROR 1690 (22003): BIGINT value is out of range in '(9223372036854775807+1)'MySQL can handle such kind of overflows in following ways:BY CONVERTING VALUE TO UNSIGNEDMySQL enables such kind of operations by converting the values to unsigned as follows −mysql> Select CAST(9223372036854775807 AS UNSIGNED) +1; +------------------------------------------+ | CAST(9223372036854775807 AS UNSIGNED) +1 | +------------------------------------------+ |                   ... Read More

How does MySQL handle out of range numeric values?

usharani
Updated on 30-Jan-2020 06:59:14

540 Views

Handling of MySQL numeric value that is out of allowed range of column data type depends upon the SQL mode in following ways −(A) Enabled SQL strict mode - When strict SQL mode is enabled, MySQL returns the error on entering the put-of-range value. In this case, the insertion of some or all the values got failed.For example, we have created a table with two columns having TINYINT and UNSIGNED TINYINT as their data types on columns.mysql> Create table counting(Range1 Tinyint, Range2 Tinyint Unsigned); Query OK, 0 rows affected (0.14 sec)Now with the help of the following command, we enabled the ... Read More

How can we say that in MySQL, AUTO_INCREMENT is taking precedence over PRIMARY KEY?

varun
Updated on 30-Jan-2020 07:00:20

97 Views

This can be understood with the help of an example in which NULL value has been inserted in an AUTO_INCREMENT column and MySQL deliver a new sequence number.mysql> Create table employeeinfo(id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, Name Varchar(10)); Query OK, 0 rows affected (0.16 sec) mysql> Insert into employeeinfo(id, Name) values(NULL, 'Saurabh'); Query OK, 1 row affected (0.07 sec) mysql> Select * from employeeinfo; +----+---------+ | id | Name    | +----+---------+ | 1  | Saurabh | +----+---------+ 1 row in set (0.00 sec)As we can observe from the above example that the column ‘id’ has been ... Read More

What happens when I insert the value ‘NULL’ in an AUTO_INCREMENT MySQL column?

Prabhas
Updated on 20-Jun-2020 07:50:04

891 Views

When we insert NULL value to AUTO_INCREMENT column, MySQL will return sequence number.Examplemysql> Create table employee(id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, Name Varchar(10)); Query OK, 0 rows affected (0.16 sec) mysql> Insert into employee(id, Name) values(NULL, 'Gaurav'); Query OK, 1 row affected (0.07 sec) mysql> Select * from employee; +----+---------+ | id | Name    | +----+---------+ | 1  | Gaurav  | +----+---------+ 1 row in set (0.00 sec)

What MySQL CHAR_LENGTH() function returns if no parameter is provided to it?

Monica Mona
Updated on 20-Jun-2020 07:48:07

123 Views

In this case, it means we are providing an empty string as an argument to the CHAR_LENGTH() function. It will return 0 on providing empty string because there are no characters to be counted by CHAR_LENGTH() function.Examplemysql> Select CHAR_LENGTH(''); +-----------------+ | CHAR_LENGTH('') | +-----------------+ | 0               | +-----------------+ 1 row in set (0.00 sec)

What MySQL returns when we alter AUTO_INCREMENT value which is less than current sequence number?

Nitya Raut
Updated on 20-Jun-2020 07:49:38

56 Views

When we use AUTO_INCREMENT on a MySQL column, the sequence number always increases in ascending order starting from the default value 1 or from the value we specify.That is the reason, MySQL does not allow changing the AUTO_INCREMENT value to a value which is less than the current sequence number. It can be understood with the help of the following example −ExampleIn this example suppose we have a table named ‘emp1’ and while creating the table we specify the AUTO_INCREMENT VALUE to 100. Hence after inserting the values in table, the sequence would start from 100 onwards as can be ... Read More

How can we retrieve the length of a specified string in MySQL?

Alankritha Ammu
Updated on 20-Jun-2020 07:47:20

59 Views

CHAR_LENGTH() or CHARACTER_LENGTH() string functions in MySQL are used to retrieve the length of a specified string. This function will simply count the number of characters and ignores whether the characters are of single-byte or multi-byte.Examplemysql> Select CHAR_LENGTH('New Delhi'); +--------------------------+ | CHAR_LENGTH('New Delhi') | +--------------------------+ | 9                        | +--------------------------+ 1 row in set (0.00 sec) mysql> Select CHAR_LENGTH('NewDelhi'); +-------------------------+ | CHAR_LENGTH('NewDelhi') | +-------------------------+ | 8                       | +-------------------------+ 1 row in set (0.00 sec) mysql> Select CHARACTER_LENGTH('NewDelhi'); ... Read More

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

Paul Richard
Updated on 30-Jan-2020 06:39:59

325 Views

When CHAR_LENGTH() or CHARACTER_LENGTH() string function is used with WHERE clause, the output returns by it will depend upon the condition given in WHERE clause. For example, suppose we have a table named ‘Student’ and we want to get only those names having number of characters less than 6, then we can write following query −mysql> Select * from Student; +------+---------+---------+-----------+ | Id   | Name    | Address | Subject   | +------+---------+---------+-----------+ | 1    | Gaurav  | Delhi   | Computers | | 2    | Aarav   | Mumbai  | History   | | 15 ... Read More

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

Sharon Christine
Updated on 30-Jan-2020 06:41:04

266 Views

While using the ASCII() function with WHERE clause, the output returns by it will depend upon the condition given in WHERE clause. For example, suppose we have a table named ‘Student’ and we want to get the number code, higher than 65, of the first characters of the names of the students. The query for this can be written as follows −mysql> Select * from student; +------+---------+---------+-----------+ | Id   | Name    | Address | Subject   | +------+---------+---------+-----------+ | 1    | Gaurav  | Delhi   | Computers | | 2    | Aarav   | Mumbai  | ... Read More

Advertisements