在数据库中,style_id列定义为CHAR(14)。 我需要能够使用空格将列表中的值填充到14。 我该怎么办? 谢谢,
<cfset style_list = replace(#FORM.style_id#," ","","all")>
select *
from T
where
<cfif IsDefined("form.style_id") and form.style_id is not "">
style_id in
(
<cfqueryparam
value="#UCASE(style_list)#"
cfsqltype="cf_sql_varchar"
list="yes" />
)
</cfif>
答案 0 :(得分:1)
相反。修剪SQL语句中TASK [code_upgrade : Upgrade Juniper devices] ***********************************************************
task path: /etc/ansible/new_test/.git/dev/code_upgrade/roles/code_upgrade/tasks/main2.yml:13
fatal: [lab-3]: FAILED! => {
"changed": false,
"module_stderr": "No handlers could be found for logger \"ncclient.transport.session\"\nTraceback (most recent call last):\n File \"/tmp/ansible_0fR5rt/ansible_module_juniper_junos_software.py\", line 747, in <module>\n main()\n File \"/tmp/ansible_0fR5rt/ansible_module_juniper_junos_software.py\", line 743, in main\n junos_module.exit_json(**results)\n File \"/tmp/ansible_0fR5rt/ansible_modlib.zip/ansible/module_utils/juniper_junos_common.py\", line 792, in exit_json\n File \"/tmp/ansible_0fR5rt/ansible_modlib.zip/ansible/module_utils/juniper_junos_common.py\", line 1327, in close\n File \"/usr/lib/python2.7/site-packages/jnpr/junos/device.py\", line 1317, in close\n self._conn.close_session()\n File \"/usr/lib/python2.7/site-packages/ncclient/manager.py\", line 162, in wrapper\n return self.execute(op_cls, *args, **kwds)\n File \"/usr/lib/python2.7/site-packages/ncclient/manager.py\", line 232, in execute\n raise_mode=self._raise_mode).request(*args, **kwds)\n File \"/usr/lib/python2.7/site-packages/ncclient/operations/session.py\", line 28, in request\n return self._request(new_ele(\"close-session\"))\n File \"/usr/lib/python2.7/site-packages/ncclient/operations/rpc.py\", line 343, in _request\n raise TimeoutExpiredError('ncclient timed out while waiting for an rpc reply.')\nncclient.operations.errors.TimeoutExpiredError: ncclient timed out while waiting for an rpc reply.\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 1
列的内容,以便可以使style_id
的内容与之匹配。
答案 1 :(得分:1)
您可以使用循环对列表进行预处理:
<cfset padded_list=""/>
<cfloop list="#style_list#" item="style">
<cfset padded_list=listappend(padded_list, rjustify(style, 14))/>
</cfloop>
如果您使用的是ColdFusion的最新版本或填充程序,则您可能还拥有listmap,这并不那么难看:
<cfset style_list=listmap(style_list, function(style) { return rjustify(style, 14); })/>
答案 2 :(得分:1)
您为什么认为需要填充这些值?使用cfsqltype CF_SQL_ CHAR ,它应该可以正常工作而无需任何填充。也许是因为left side of the comparison (column) is type CHAR while the right (cfqueryparam) is type VARCHAR不能正常工作?
我测试了您的查询,它在CF 9,0,2,282541和SQL Server上运行良好。它也可以与CF 9.0.2和Oracle 12G一起正常使用。 CFQueryparam似乎可以自动处理。
DDL:
CREATE TABLE someTable(style_id char(14))
INSERT INTO someTable VALUES ('abc'),('efg ')
CF:
<!--- worked with both CF_SQL_VARCHAR and CF_SQL_CHAR --->
<cfset style_list = "abc,efg">
<cfquery name="qTest" datasource="YourDSN">
SELECT *
FROM SomeTable
WHERE style_id in
( <cfqueryparam
value="#UCASE(style_list)#"
cfsqltype="cf_sql_char"
list="yes" />
)
</cfquery>
<cfdump var="#qTest#">
结果:
RESULTSET
query
STYLE_ID
1 abc
2 efg