Today, a development brother to find me, said that there is a strange phenomenon, in the stored procedure to assign a date type of value, time, minutes, seconds are lost, the following to do an experiment:
sql> drop table test purge;
sql> CREATE TABLE test
(
Fill_date Date
);
sql> INSERT into test values (sysdate);
Sql> commit;
Sql> Select To_char (fill_date, ' Yyyy-mm-dd HH24:mi:ss ') from test;
To_char (Fill_date, '
-------------------
2014-07-18 17:47:22
sql> CREATE OR REPLACE PROCEDURE test_p
Is
S_sql VARCHAR2 (500);
S_date date;
Begin
s_date:= to_date (' 2014-07-18 17:24:32 ', ' yyyy-mm-dd HH24:mi:ss ');
S_sql: = ' UPDATE test SET fill_date = ' ' | | S_date | | ";
Execute immediate s_sql;
Commit
End
/
Sql> call Test_p ();
Sql> Select To_char (fill_date, ' Yyyy-mm-dd HH24:mi:ss ') from test;
To_char (Fill_date, '
-------------------
2014-07-18 00:00:00 --you can see that the real time, minute, and second have been lost, the suspicion is that the implicit conversion caused
--Adjust the stored procedure to see what is printed out.
sql> CREATE OR REPLACE PROCEDURE test_p
Is
S_sql VARCHAR2 (500);
S_date date;
Begin
s_date:= to_date (' 2014-07-18 17:24:32 ', ' yyyy-mm-dd HH24:mi:ss ');
S_sql: = ' UPDATE test SET fill_date = ' ' | | S_date | | ";
Dbms_output.put_line (S_sql);
Execute immediate s_sql;
Commit
End
/
Sql> set Serveroutput on
Sql> call Test_p ();
UPDATE Test SET fill_date = ' 1 August-July-14 '
The call is complete.
--to confirm that an implicit conversion has occurred, the binding variable is used
sql> CREATE OR REPLACE PROCEDURE test_p
Is
S_sql VARCHAR2 (500);
S_date date;
Begin
s_date:= to_date (' 2014-07-18 17:24:32 ', ' yyyy-mm-dd HH24:mi:ss ');
S_sql: = ' UPDATE test SET fill_date =: 1 ';
Execute immediate s_sql using S_date;
Commit
End
/
Sql> call Test_p ();
The call is complete.
Sql> Select To_char (fill_date, ' Yyyy-mm-dd HH24:mi:ss ') from test;
To_char (Fill_date, '
-------------------
2014-07-18 17:24:32