sql - Getting ORA-01861 - Literal does not match format string on SQLPlus Only -
i have pl/sql procedure takes following arguments/parameters
procedure create_test(mode_in in number, value1_in in number, value2_in in number, value3_in in varchar2);
i using following pl/sql block call , execute procedure
declare lv_mode number; lv_value1_in number; lv_value2_in number; lv_value3 varchar2(3); begin lv_mode := 1; lv_value1_in := 1; lv_value2_in := 1; lv_value3_in := 'es'; create_test( mode_in => lv_mode , value1_in => lv_value1_in, value2_in => lv_value2_in, value3_in => lv_value3_in ); --rollback; end; /
if paste above sql block sqldeveloper , execute it, runs no problems. if put in file , execute through sql plus, following error (same problem if run directly in sqlplus):
ora-01861: literal not match format string
usually when error, issue related dates. not sure wrong above there no dates involved - given fact same sql block works in ide not sqlplus. sqlplus handling literals differently ide?
my guess parameter in sqlplus handling differently - one?
funny mistake: to_date(sysdate, 'dd-mon-yyyy hh:mi:ss')
replace expression sysdate in procedure..
the returned datatype of sysdate
function date
:
https://docs.oracle.com/cd/b19306_01/server.102/b14200/functions172.htm
to_date
function expects either char
, varchar2
, nchar
, or nvarchar2
type it's first parameter:
http://docs.oracle.com/cd/b19306_01/server.102/b14200/functions183.htm
the procedure passes sysdate (of type date) first parameter, expected string (varchar, char etc.). in case oracle performs implicit conversion of date chhar/varchar2, using to_char function internally.
1 can above expression converted internally to:
to_date( to_char( sysdate ) , 'dd-mon-yyyy hh:mi:ss' )
more on imlicit conversion rules can found here (scroll section: "data conversion - implicit , explicit data conversion):
https://docs.oracle.com/cd/b19306_01/server.102/b14200/sql_elements002.htm
an essential fragment above link:
implicit conversion depends on context in occurs , may not work same way in every case. example, implicit conversion datetime value varchar2 value may return unexpected year depending on value of nls_date_format parameter.
in other words - to_char( some-date )
without second parameter (format) uses value of nls_date_fomrat variable taken session.
if check parameter on sql-developer, probably: 'dd-mon-yyyy hh:mi:ss' (in sql-developer value of parameter configured in option: tools/preferences/database/nls
if check nls_date_format value in sql-plus, differ 'dd-mon-yyyy hh:mi:ss'. sql-plus determines value of nls setting language settings of environment (windows, linux etc.) , nls_lang enironment varable (if present).
can change parameter in session using:
alter session set nls_date_format = 'dd-mon-yyyy hh:mi:ss';
, (old) procedure work.
Comments
Post a Comment