写了个函数,如下:
create or replace function Get_JS_FROM_PKT(PPKT_STRING in VARCHAR2) return INTEGER is
--根据PKT字符串得到件数
  QT_JS INTEGER;begin
  select count(*) into QT_JS from carton_hdr 
    where pkt_ctrl_nbr in (PPKT_STRING) and carton_creation_code!='1';  return(QT_JS);
end Get_JS_FROM_PKT;如果不写函数,  应该是这样的效果,select count(*) from carton_hdr 
    where pkt_ctrl_nbr in ('11','22','33') and carton_creation_code!='1';
应该怎样传入参数才能达到这样的效果?

解决方案 »

  1.   


    --参照下面的试下吧
    select ('''1'''||','||'''3'''||','||'''4''') PPKT_STRING from dual;
        PPKT_STRING
    1  '1','3','4'
      

  2.   

    in 的参数不能这么传递。
    可以采用拼接sql,然后动态执行,或者通过oracle的type来实现,参见
    http://hi.baidu.com/jdsnhan/blog/item/7c21ebaf4ee400cd7cd92a36.html
      

  3.   

    你这用动态SQL不就行了吗
    否则要用SQL拆分字符串
    v_sql='select count(*)  from carton_hdr 
        where pkt_ctrl_nbr in ('||PPKT_STRING||') and carton_creation_code!=''1'''; 
    execute immediate v_sql into QT_JS;
      

  4.   

    引号里面两个引号表示一个引号:
    SQL> select '''11'',''22'',''33''' from dual;'''11'',''22''
    --------------
    '11','22','33'
      

  5.   

    select ('''1'''||','||'''3'''||','||'''4''') PPKT_STRING from dual;
           PPKT_STRING
    1     '1','3','4'
      

  6.   

    可以使用q'XstringX'方式来表示一个字符串,其中X可以是字符串中不出现的任何字符,string可以是任意的字符,a包括单引号,如q'|'adf'fasd'gasdf'ga'adf'af|'表示:'adf'fasd'gasdf'ga'adf'af
      

  7.   

    select '''11'',''22'',''33''' from dual; 
      

  8.   

    我记得以前好像试过的,oracle中不能把参数连接起来放进去。
    select count(*)  from carton_hdr where pkt_ctrl_nbr  in('1'||',2')这种连接的好像不行的,oracle会把括号里当作一整个字符串去匹配,结果当然是匹配不到记录。
    可以写一个解析参数的函数,将传入的参数解析成一个数组,然后循环读取数组,将查询语句写在循环里,每匹配到一条记录就加1。