Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
参数中有多个值-SQL(Oracle)_Sql_Oracle_Parameters - Fatal编程技术网

参数中有多个值-SQL(Oracle)

参数中有多个值-SQL(Oracle),sql,oracle,parameters,Sql,Oracle,Parameters,我想通过一个参数传递多个值 请仅建议SQL建议,而不是PL/SQL,因为我将在报告中使用它。我假设您正在将值绑定到查询,因为它在有一个值时工作,但在有两个值时失败。这就是how-do-I-bind-a-variable-in-list问题。有几种解决方案,但我喜欢的一种不涉及PLSQL的解决方案是: with id_generator as ( SELECT regexp_substr(:txt, '[^,]+', 1, LEVEL) token FROM

我想通过一个参数传递多个值


请仅建议SQL建议,而不是PL/SQL,因为我将在报告中使用它。

我假设您正在将值绑定到查询,因为它在有一个值时工作,但在有两个值时失败。这就是how-do-I-bind-a-variable-in-list问题。有几种解决方案,但我喜欢的一种不涉及PLSQL的解决方案是:

with id_generator
    as
    (
      SELECT regexp_substr(:txt, '[^,]+', 1, LEVEL) token
      FROM dual
      CONNECT BY LEVEL <= length(:txt) - length(REPLACE(:txt, ',', '')) + 1
    )
    select u.id, u.username
    from users u, id_generator g
    where u.id = g.token;
将逗号分隔的字符串绑定为:txt的值,然后将查询构造为联接


完整解释-

这可能有助于-pas任何有效的deptnos lk 10,20列表…:

Select * From scott.emp 
 Where deptno IN (&deptno)
/
如果传递字符串,则在“&ename”中使用引号 谢谢。

也许这篇文章会有所帮助
Select * From scott.emp 
 Where deptno IN (&deptno)
/