|
|
|
A m Z o n e
Explicit and implict convertion of datatypes
Oracle implicitly converts datatypes during assignment if not explicitly specified. Which in your opinion should we adhere to when coding, implicit conversion done by oracle or explicitly specified by the developer?
eg: declare l_chr varchar2(10); l_num number(10); begin l_num := 100; l_chr := l_num; -- implicit conversion (or) l_chr := to_char(l_num); -- explicit conversion dbms_output.put_line(l_chr); ..... end;
Oracle's conversion methodology may change over the releases. For example the following is the result of different behaviour in Oracle versions. White space assigned to a number was acceptable in Oracle 7.3, but not so in Oracle 8i.
Oracle recommendeds to carry out explicit conversion. Tell your code what it has to do, be explicit.eg: declare l_num number; begin l_num := ' '; end; In oracle 7.3.4, the above code returns: PL/SQL procedure successfully completed.
In Oracle 8.1.7, the above code returns: ERROR at line 1: ORA-06502: PL/SQL: numeric or value error: character to number conversion error ORA-06512: at line 4
Press the Back button of you Browser to go to previous page
Home