Từ version Informix 11.10 một số build-in function được thêm vào trong đó có 1 function mà mình đang cần là NULLIF, mình đang sử dụng version nhỏ hơn 11.10 và khi truy vấn với NULLIF(field, 0) mình nhận được một error code là 674. Sau khi tìm thì mình biết nó được mô tả như sau tại IBM Knowledge Center:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
-674 Routine cannot be resolved. You called a routine that does not exist in the database, you do not have permission to execute the routine, or you called the routine with too few or too many arguments. If a prepared statement invokes a user-defined routine and your application or another application drops the routine before the prepared statement is executed, you will receive this error. You might also see this error message if you write an expression that calls an SPL routine (stored procedure) that returns no values. For an SPL routine to be usable in an expression, the routine must return a value. Check that the name of the routine is correct, that you have execute permission, that you specified the correct number of arguments to execute a routine, and that the data types for the arguments are appropriate. For a prepared statement that refers to the routine, make sure that the routine still exists when you execute the statement. |
Vì vậy mình phải viết 1 function NULLIF để sử dụng, thay vì update Informix hiện tại lên 11.10 (cơ bản là không biết update lên sao luôn).
Mô tả function tại IBM Knowledge Center:
Mình viết rất đơn giản(do không biết nhiều mấy cái này), mình cần nhận vào 2 decimal để so sánh, nếu nó bằng nhau thì return về null, khác nhau thì return về number1. HẾT
1 2 3 4 5 6 7 8 9 10 |
create function hau_nullif(number1 decimal(22,2), number2 decimal(22,2)) returning decimal(22,2); define result decimal(22,2); if number1 = number2 then let result = null; else let result = number1; end if; return result; end function; |
Sau khi thực thi xong thì có thể sử dụng nó trong câu select tương tự như NULLIF(exp1, exp2).
Do không biết nhiều, nên khi sử dụng có thể xảy ra exception nào đó, hoặc có ai thấy nó thiếu cái gì góp ý giúp mình qua email: haulpd@linux-group.com. Thanks!