用SQL,输入C J Y,想查出:CXXJXXYY 的内容。并未知道X是哪种类型。
如何解决呢?

解决方案 »

  1.   

    输入C J Y什么意思,三个参数还是一个参数?CXXJXXYY的内容,不知道X是哪种类型,那你的CXXJXXYY是什么意思,从哪里取出来的?表结构,测试数据,结果数据???
      

  2.   

    不知道是不是这个意思SQL> select * from a01;COL1
    --------------------
    A01B01CC
    A02B02CC
    A03B03CC
    A02D02CCSQL> accept A char prompt "input the A:"
    input the A:A
    SQL> accept B char prompt "input the B:"
    input the B:B
    SQL> accept C char prompt "input the C:"
    input the C:C
    SQL> select * from a01 where col1 like  '&A'||'__'||'&B'||'__'||'&C'||'%';
    old   1: select * from a01 where col1 like  '&A'||'__'||'&B'||'__'||'&C'||'%'
    new   1: select * from a01 where col1 like  'A'||'__'||'B'||'__'||'C'||'%'COL1
    --------------------
    A01B01CC
    A02B02CC
    A03B03CCSQL> accept B char prompt "input the B:"
    input the B:D
    SQL> select * from a01 where col1 like  '&A'||'__'||'&B'||'__'||'&C'||'%';
    old   1: select * from a01 where col1 like  '&A'||'__'||'&B'||'__'||'&C'||'%'
    new   1: select * from a01 where col1 like  'A'||'__'||'D'||'__'||'C'||'%'COL1
    --------------------
    A02D02CCSQL>
      

  3.   

    是要这样子的吗?with t as (
    select 'C123abcJ456defYY' as fname from dual
    union all
    select 'C45efJ12bcYX' from dual
    union all
    select 'CC456def123abcY' from dual
    )
    select * from t
    where regexp_like(fname,'C[0-9a-zA-z]+J[0-9a-zA-z]+Y[A-Z]+')FNAME            
    ---------------- 
    C123abcJ456defYY 
    C45efJ12bcYX