在网上没搜到插入多字段的示例,就照库的例子用:1和:2做占位符,查询正常,插入常量ok(如下),用变量插入就报错了,请知道的高手帮忙回答一下,谢谢了。(oci8有像mysql库的prepare函数没)
_, err = db.Exec("insert into AUTH_SUCESS_201706_FZ values('a','b','c','d',1,2,3,'e',4,5,6,'f',7,8,'g','h','i')")
SQL> select count(*) from AUTH_SUCESS_201706_FZ;
COUNT(*)
----------
1
报错信息:
2017-06-17 04:57:11 <LL_ERROR> ORA-01722: invalid number
使用oerr ora 1722 看解释没看懂说的哪个number无效,是占位符吗?
[root@bogon ~]# oerr ora 1722
01722, 00000, "invalid number"
// *Cause: The specified number was invalid.
// *Action: Specify a valid number.
插入用的代码(下面2种插入方式都报错17222):
_, err = db.Exec("insert into AUTH_SUCESS_201706_FZ values(:1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13,:14,:15,:16,:17)", lineList[0],lineList[1],lineList[2],lineList[3],lineList[4],lineList[5],lineList[6],lineList[7],lineList[8],lineList[9],lineList[10],lineList[11],lineList[12],lineList[13],lineList[14],lineList[15],lineList[16])
_, err = db.Exec("insert into AUTH_SUCESS_201706_FZ values(:1,:1,:1,:1,:1,:1,:1,:1,:1,:1,:1,:1,:1,:1,:1,:1,:1)", lineList[0],lineList[1],lineList[2],lineList[3],lineList[4],lineList[5],lineList[6],lineList[7],lineList[8],lineList[9],lineList[10],lineList[11],lineList[12],lineList[13],lineList[14],lineList[15],lineList[16])
使用fmt.Println打印lineList[]内容如下,插入的表是按照字段个数和类型建的:
22675029@879150 A4-5D-36-18-59-45 20170106112643 20170106122730 3647 8192 1 192.168.1.1 100 200 1 202.101.99.163 1905 FZ-JA-1020000000002028f20b826979 591 atm 3/1/1:2454.1900 0/0/0/0/0/0 liantong
SQL> desc AUTH_SUCESS_201706_FZ; 表结构:
Name Null? Type
----------------------------------------------------------------------------------- -------- --------------------------------------------------------
LOGIN VARCHAR2(128)
ANI VARCHAR2(26)
START_TIME VARCHAR2(20)
END_TIME VARCHAR2(20)
DURATION NUMBER(8)
KB_IN NUMBER(8)
KB_OUT NUMBER(8)
IPADDR VARCHAR2(16)
PACKETS_IN NUMBER(8)
PACKETS_OUT NUMBER(8)
TERM_CAUSE NUMBER(4)
TERMSERV_ID VARCHAR2(16)
TERMSERV_PORT NUMBER(8)
TRANS_ID NUMBER(8)
AREA_ID VARCHAR2(4)
NAS_PORT_ID VARCHAR2(256)
V_OPERATOR VARCHAR2(256)
【求助】mattn oci8插入Oracle表多个字段报错:ORA-01722: invalid number,再请问oci8库有db.Prepare()函数能准备语句吗?
jimyokl · · 1233 次点击更多评论