• <bdo id='gc1tP'></bdo><ul id='gc1tP'></ul>
    <tfoot id='gc1tP'></tfoot>
      <legend id='gc1tP'><style id='gc1tP'><dir id='gc1tP'><q id='gc1tP'></q></dir></style></legend>

    1. <small id='gc1tP'></small><noframes id='gc1tP'>

      <i id='gc1tP'><tr id='gc1tP'><dt id='gc1tP'><q id='gc1tP'><span id='gc1tP'><b id='gc1tP'><form id='gc1tP'><ins id='gc1tP'></ins><ul id='gc1tP'></ul><sub id='gc1tP'></sub></form><legend id='gc1tP'></legend><bdo id='gc1tP'><pre id='gc1tP'><center id='gc1tP'></center></pre></bdo></b><th id='gc1tP'></th></span></q></dt></tr></i><div id='gc1tP'><tfoot id='gc1tP'></tfoot><dl id='gc1tP'><fieldset id='gc1tP'></fieldset></dl></div>

        如何使用变量在动态查询中指定 IN 子句?

        How do you specify IN clause in a dynamic query using a variable?(如何使用变量在动态查询中指定 IN 子句?)
        <tfoot id='j3LGN'></tfoot>

            <legend id='j3LGN'><style id='j3LGN'><dir id='j3LGN'><q id='j3LGN'></q></dir></style></legend>

                <small id='j3LGN'></small><noframes id='j3LGN'>

                  <tbody id='j3LGN'></tbody>
                  <bdo id='j3LGN'></bdo><ul id='j3LGN'></ul>
                  <i id='j3LGN'><tr id='j3LGN'><dt id='j3LGN'><q id='j3LGN'><span id='j3LGN'><b id='j3LGN'><form id='j3LGN'><ins id='j3LGN'></ins><ul id='j3LGN'></ul><sub id='j3LGN'></sub></form><legend id='j3LGN'></legend><bdo id='j3LGN'><pre id='j3LGN'><center id='j3LGN'></center></pre></bdo></b><th id='j3LGN'></th></span></q></dt></tr></i><div id='j3LGN'><tfoot id='j3LGN'></tfoot><dl id='j3LGN'><fieldset id='j3LGN'></fieldset></dl></div>
                • 本文介绍了如何使用变量在动态查询中指定 IN 子句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在 PL/SQL 中,您可以使用连接指定 IN 运算符的值:

                  In PL/SQL, you can specify the values for the IN operator using concatenation:

                  v_sql := 'select field1
                  from table1
                  where field2 in (' || v_list || ')';
                  

                  是否可以使用变量来做同样的事情?

                  Is it possible to do the same using a variable?

                  v_sql := 'select field1
                  from table1
                  where field2 in (:v_list)'; 
                  

                  如果是,怎么做?

                  参考 Marcin 的回答,我如何从结果表中进行选择?

                  With reference to Marcin's answer, how do I select from the resultant table?

                  declare
                  
                  cursor c_get_csv_as_tables is
                  select in_list(food_list) food_list
                  from emp_food
                  where emp_type = 'PERM';
                  
                  cursor c_get_food_list (v_food_table varchar2Table)is
                  select *
                  from v_food_table;
                  
                  begin
                      for i in c_get_csv_as_tables loop
                          for j in c_get_food_list(i.food_list) loop
                              dbms_output.put_line(j.element);
                          end loop;
                      end loop;
                  end;
                  

                  我收到以下错误:

                  ORA-06550: line 10, column 6:
                  PL/SQL: ORA-00942: table or view does not exist
                  ORA-06550: line 9, column 1:
                  PL/SQL: SQL Statement ignored
                  ORA-06550: line 15, column 34:
                  PLS-00364: loop index variable 'J' use is invalid
                  ORA-06550: line 15, column 13:
                  PL/SQL: Statement ignored
                  

                  推荐答案

                  就像在@Sathya 链接中一样,您可以绑定 varray(我以@Codo 为例):

                  Like in @Sathya link, you can bind the varray (I took @Codo example):

                  CREATE OR REPLACE TYPE str_tab_type IS VARRAY(10) OF VARCHAR2(200);
                  /
                  DECLARE
                    l_str_tab str_tab_type;
                    l_count NUMBER;
                    v_sql varchar2(3000);
                  BEGIN
                    l_str_tab := str_tab_type();
                    l_str_tab.extend(2);
                    l_str_tab(1) := 'TABLE';
                    l_str_tab(2) := 'INDEX';
                  
                    v_sql := 'SELECT COUNT(*) FROM all_objects WHERE object_type IN (SELECT COLUMN_VALUE FROM TABLE(:v_list))';
                  
                    execute immediate v_sql into l_count using l_str_tab;
                  
                    dbms_output.put_line(l_count);
                  END;
                  /
                  

                  UPDATE:第一个命令可以替换为:

                  UPDATE: the first command can be replaced with:

                  CREATE OR REPLACE TYPE str_tab_type IS TABLE OF VARCHAR2(200);
                      /
                  

                  然后调用:

                  l_str_tab.extend(1);
                  

                  当你添加一个值时

                  这篇关于如何使用变量在动态查询中指定 IN 子句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                  SQL query to group by day(按天分组的 SQL 查询)
                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Include missing months in Group By query(在 Group By 查询中包含缺失的月份)

                    <small id='Uornb'></small><noframes id='Uornb'>

                    <i id='Uornb'><tr id='Uornb'><dt id='Uornb'><q id='Uornb'><span id='Uornb'><b id='Uornb'><form id='Uornb'><ins id='Uornb'></ins><ul id='Uornb'></ul><sub id='Uornb'></sub></form><legend id='Uornb'></legend><bdo id='Uornb'><pre id='Uornb'><center id='Uornb'></center></pre></bdo></b><th id='Uornb'></th></span></q></dt></tr></i><div id='Uornb'><tfoot id='Uornb'></tfoot><dl id='Uornb'><fieldset id='Uornb'></fieldset></dl></div>
                      <bdo id='Uornb'></bdo><ul id='Uornb'></ul>
                        <legend id='Uornb'><style id='Uornb'><dir id='Uornb'><q id='Uornb'></q></dir></style></legend>
                          <tfoot id='Uornb'></tfoot>

                              <tbody id='Uornb'></tbody>