1.第一个错:oracle的to_date()函数第一个参数传入time.Now()得到的结果,报错ORA-00984,百度说是字符串应该用单引号,可time.Now()得到的就是字符串,用reflect.TypeOf查看也是string类型的.请知道的高手帮忙解答一下,谢谢了.
2017-06-18 18:49:54 <LL_ERROR> ORA-00984: column not allowed here
1.1 代码:
timeNow := time.Now().Format("20060102150405")
fmt.Println(timeNow) //打印20170618184954
fmt.Println(reflect.TypeOf(timeNow)) //打印string
timeNow = string(timeNow)
_, err = db.Exec("insert into AUTH_FAIL values(:1,0,'',to_date(timeNow,'yyyyMMddHH24miss'))", lineList[0])
1.2 在1.1代码的lineList[0]是一个字符串,这个字符串没问题,执行过下面的测试,可以查到插入成功结果(如下)
insert into AUTH_FAIL values('test',0,'',to_date('20060102150405','yyyyMMddHH24miss'))
SQL> select * from AUTH_FAIL;
LOGIN STATUS
-------------------------------------------------------------------------------------------------------------------------------- ----------
RESULT_DESC
--------------------------------------------------------------------------------------------------------------------------------------------
STATUS_TIME
------------
test 0
02-JAN-06
2 第二个错误是我在直接把'20060102150405'作为to_date()参数时执行sql语句不报ora00984的错,但得不到yyyymmddhhmiss的时间格式,执行下面的插入语句查询得到的时间格式不是yyyymmddhhmiss
_, err = db.Exec("insert into AUTH_FAIL values(:1,0,'',to_date('20060102150405','yyyyMMddHH24miss'))", lineList[0])
SQL查询AUTH_FAIL表和1.2显示的结果一样:
SQL> select * from AUTH_FAIL;
LOGIN STATUS
-------------------------------------------------------------------------------------------------------------------------------- ----------
RESULT_DESC
--------------------------------------------------------------------------------------------------------------------------------------------
STATUS_TIME
------------
test 0
02-JAN-06
2.2 用SQL直接在plsql窗口执行select to_char(to_date('20060102150405','yyyyMMddHH24miss')) from dual; 和 select to_date('20060102150405','yyyyMMddHH24miss') from dual; 显示时间格式也不对,是我系统设置有问题吗?请知道的高手帮忙解答一下,谢谢了
SQL> select to_char(to_date('20060102150405','yyyyMMddHH24miss')) from dual;
TO_CHAR(T
---------
02-JAN-06
SQL> select to_date('20060102150405','yyyyMMddHH24miss') from dual;
TO_DATE('200
------------
02-JAN-06
有疑问加站长微信联系(非本文作者)