Hướng dẫn ifnull mysql
Trong bài này mình sẽ hướng dẫn cách sử dụng hàm Show
Bài viết này được đăng tại freetuts.net, không được copy dưới mọi hình thức. 1. Mô tảHàm 2. Cú phápCú pháp của hàm IFNULL( expression, value_if_null ) Trong đó: Bài viết này được đăng tại [free tuts .net]
Lưu ý:
3. VersionHàm
4. Ví dụmysql> SELECT IFNULL('freetuts.net', 'myfreetuts.net'); Ket qua: 'freetuts.net' mysql> SELECT IFNULL(NULL, 'myfreetuts.net'); Ket qua: 'myfreetuts.net' mysql> SELECT IFNULL(DATE('2019-04-03'), '2019-04-15'); Ket qua: '2019-04-03' mysql> SELECT IFNULL(DATE(NULL), '2019-04-15'); Ket qua: '2019-04-15' mysql> SELECT IFNULL(2, 5); Ket qua: 2 mysql> SELECT IFNULL(10/0, 'tra ve gia tri NULL'); Ket qua: 'tra ve gia tri NULL' Trong bài này mình sẽ hướng dẫn cách sử dụng hàm IFNULL trong MySQL thông qua cú pháp và ví dụ thực tế. 1. Mô tả Hàm IFNULL trả về một giá trị thay thế nếu một biểu thức là NULL. 2. Cú pháp Cú pháp của hàm IFNULL trong MySQL là: ...Trong bài này mình sẽ hướng dẫn cách sử dụng hàm 1. Mô tảHàm 2. Cú phápCú
pháp của hàm IFNULL( expression, value_if_null ) Trong đó:
Lưu ý:
3. VersionHàm
4. Ví dụmysql> SELECT IFNULL('Zaidap.com.net', 'myZaidap.com.net'); Ket qua: 'Zaidap.com.net' mysql> SELECT IFNULL(NULL, 'myZaidap.com.net'); Ket qua: 'myZaidap.com.net' mysql> SELECT IFNULL(DATE('2019-04-03'), '2019-04-15'); Ket qua: '2019-04-03' mysql> SELECT IFNULL(DATE(NULL), '2019-04-15'); Ket qua: '2019-04-15' mysql> SELECT IFNULL(2, 5); Ket qua: 2 mysql> SELECT IFNULL(10/0, 'tra ve gia tri NULL'); Ket qua: 'tra ve gia tri NULL' Nguồn: Zaidap.com.net ExampleReturn the specified value IF the expression is NULL, otherwise return the expression: SELECT IFNULL(NULL, "W3Schools.com"); Try it Yourself » Definition and UsageThe IFNULL() function returns a specified value if the expression is NULL. If the expression is NOT NULL, this function returns the expression. SyntaxIFNULL(expression, alt_value) Parameter Values
Technical Details
More ExamplesExampleReturn the specified value IF the expression is NULL, otherwise return the expression: SELECT IFNULL("Hello", "W3Schools.com"); Try it Yourself » ExampleReturn the specified value IF the expression is NULL, otherwise return the expression: SELECT IFNULL(NULL, 500); Try it Yourself » Hàm NULL trong SQLNhìn vào bảng “Sản phẩm” sau:
Giả sử rằng cột “UnitsOnOrder” là tùy chọn và có thể chứa giá trị NULL. Nhìn vào câu lệnh SELECT sau: SELECT ProductName, UnitPrice * (UnitsInStock + UnitsOnOrder) Trong ví dụ trên, nếu bất kỳ giá trị “UnitsOnOrder” nào là NULL, kết quả sẽ là NULL. Các giải phápMySQL Hàm MySQL SELECT ProductName, UnitPrice * (UnitsInStock + IFNULL(UnitsOnOrder, 0)) hoặc chúng ta có thể sử dụng hàm SELECT ProductName, UnitPrice * (UnitsInStock + COALESCE(UnitsOnOrder, 0)) Máy chủ SQL Hàm SQL Server SELECT ProductName, UnitPrice * (UnitsInStock +
ISNULL(UnitsOnOrder, 0)) Truy cập MS Hàm MS Access SELECT ProductName, UnitPrice * (UnitsInStock + IIF(IsNull(UnitsOnOrder), 0, UnitsOnOrder)) Oracle Hàm Oracle SELECT ProductName, UnitPrice * (UnitsInStock + NVL(UnitsOnOrder, 0)) botvietbai.com BCK là giải pháp tích hợp thanh toán MOMO, ViettelPay, VNPay, Vietcombank, Vietinbank, Techcombank, MB.. dành cho cá nhân ! |