想实现什么?
select count(a.kmdm) into v_count from js2k_mid a 
    where a.nd = '1984' and a.dqbm = '150000' 
    and exists (select count(b.kmdm)  from js2k_mid b 
    where b.nd = '1984' and b.dqbm = '150000' and
    b.kmdm = substr(a.kmdm,1,length(a.kmdm) - 2))
这样不可?

解决方案 »

  1.   

    SQL> select * from test;        N1         N2         N3
    ---------- ---------- ----------
             1        300         20
             1        200         10
             1         30         30
             2        500         30
             2        600         40SQL> select n1,n2,n3 from test a where (select count(*) from test b where b.n2=substr(a.n2,1,2))=1;        N1         N2         N3
    ---------- ---------- ----------
             1        300         20
             1         30         30SQL>
      

  2.   

    SQL> select * from test;        N1         N2         N3
    ---------- ---------- ----------
             1        300         20
             1        200         10
             1         30         30
             2        500         30
             2        600         40SQL> select n1,n2,n3 from test a where (select count(*) from test b where b.n2=substr(a.n2,1,2))=1;        N1         N2         N3
    ---------- ---------- ----------
             1        300         20
             1         30         30SQL>
      

  3.   

    to zlqs: 你的方法对我不使用;另外子查询,就是我上面写的不能用;
      

  4.   

    zlqs(啊啊啊):你写的是sql,人家是pl/sql
    好像不能用的
      

  5.   

    是可以的如下
    SQL> CREATE OR REPLACE PROCEDURE AAADADFAA
      2  IS
      3     a1 varchar2(20);
      4     a2 varchar2(20);
      5     a3 varchar2(20);
      6  BEGIN
      7   select n1,n2,n3 into a1,a2,a3 from test a where (select count(*) from test b where b.n2=substr(a.n2,1,2))=1;
      8  END;
      9  /Procedure createdSQL>