Insert query error: Column count doesn't match value count at row 1
Insert query error: Column count doesn't match value count at row 1
我有一个 cfquery,我正在遍历这些值以将多行插入到数据库中。我必须这样做,而不是在循环中生成多个 INSERT 查询,因为我需要在 INSERT 之后的 generatedKeys
列表。但是我的查询现在抛出了下面的错误。我知道错误的含义,但根据我的查询它没有意义。
查询:
<cfquery datasource="#OLMSdatasourceWrite#" result="myResult">
INSERT INTO OLMS_Data_RatioScenarios
(
OLMS_Account_ID,
OLMS_RatioScenario_Name
)
VALUES
(
<cfset numItems = ListLen(AccountListWithSettings)>
<cfset i = 1>
<cfloop list="#AccountListWithSettings#" index="CurrentAccount">
(<cfqueryparam cfsqltype="cf_sql_numeric" value="#CurrentAccount#" maxlength="255">
, <cfqueryparam cfsqltype="cf_sql_clob" value="#requestBody.value#" maxlength="255">
)
<cfif i lt numItems>
,
</cfif>
<cfset i++>
</cfloop>
)
</cfquery>
<cfoutput>Inserted ID is: #myResult.generatedkey#</cfoutput>
错误:
Root Cause:java.sql.SQLException: Column count doesn't match value count at row 1
SQL: INSERT INTO OLMS_Data_RatioScenarios ( OLMS_Account_ID, OLMS_RatioScenario_Name )
VALUES ( ( (param 1) , (param 2) ) , ( (param 3) , (param 4) ) , ( (param 5) , (param 6) ) )
更正后的代码:
<cfquery datasource="#OLMSdatasourceWrite#" result="myResult">
INSERT INTO OLMS_Data_RatioScenarios
(
OLMS_Account_ID,
OLMS_RatioScenario_Name
)
VALUES
<cfset numItems = ListLen(AccountListWithSettings)>
<cfset i = 1>
<cfloop list="#AccountListWithSettings#" index="CurrentAccount">
(
<cfqueryparam cfsqltype="cf_sql_numeric" value="#CurrentAccount#" maxlength="255">
, <cfqueryparam cfsqltype="cf_sql_clob" value="#requestBody.value#" maxlength="255">
)
<cfif i lt numItems>
,
</cfif>
<cfset i++>
</cfloop>
</cfquery>
我有一个 cfquery,我正在遍历这些值以将多行插入到数据库中。我必须这样做,而不是在循环中生成多个 INSERT 查询,因为我需要在 INSERT 之后的 generatedKeys
列表。但是我的查询现在抛出了下面的错误。我知道错误的含义,但根据我的查询它没有意义。
查询:
<cfquery datasource="#OLMSdatasourceWrite#" result="myResult">
INSERT INTO OLMS_Data_RatioScenarios
(
OLMS_Account_ID,
OLMS_RatioScenario_Name
)
VALUES
(
<cfset numItems = ListLen(AccountListWithSettings)>
<cfset i = 1>
<cfloop list="#AccountListWithSettings#" index="CurrentAccount">
(<cfqueryparam cfsqltype="cf_sql_numeric" value="#CurrentAccount#" maxlength="255">
, <cfqueryparam cfsqltype="cf_sql_clob" value="#requestBody.value#" maxlength="255">
)
<cfif i lt numItems>
,
</cfif>
<cfset i++>
</cfloop>
)
</cfquery>
<cfoutput>Inserted ID is: #myResult.generatedkey#</cfoutput>
错误:
Root Cause:java.sql.SQLException: Column count doesn't match value count at row 1
SQL: INSERT INTO OLMS_Data_RatioScenarios ( OLMS_Account_ID, OLMS_RatioScenario_Name )
VALUES ( ( (param 1) , (param 2) ) , ( (param 3) , (param 4) ) , ( (param 5) , (param 6) ) )
更正后的代码:
<cfquery datasource="#OLMSdatasourceWrite#" result="myResult">
INSERT INTO OLMS_Data_RatioScenarios
(
OLMS_Account_ID,
OLMS_RatioScenario_Name
)
VALUES
<cfset numItems = ListLen(AccountListWithSettings)>
<cfset i = 1>
<cfloop list="#AccountListWithSettings#" index="CurrentAccount">
(
<cfqueryparam cfsqltype="cf_sql_numeric" value="#CurrentAccount#" maxlength="255">
, <cfqueryparam cfsqltype="cf_sql_clob" value="#requestBody.value#" maxlength="255">
)
<cfif i lt numItems>
,
</cfif>
<cfset i++>
</cfloop>
</cfquery>