我想要在oracle里用sql 语句实现控制where后接的条件只能是某一个具体值(条件)
例如:有学生表,表里有学号,入学日期(date,有201309,201409```)```等信息
    select * from students
       where date=201309
 我想要限制date的日期只能填写201309,填别的值就会报错。请各位大神指点,拜谢!!!!!

解决方案 »

  1.   

    填别的值是啥意思, 这个值是在前端页面录入然后传过来的?
    如果是,那就全都页面控制住就完事了,如果想在直接操作oracle的时候控制查询,不可能,要不就不给别人这个表的查询权限,要不就把你不想给别人看的数据清空。
      

  2.   

    sql只能报ora错误,不能实现自定义,只有语句块可以
      

  3.   

    如果控制sql的where子句的条件值,就在应用端实现。
    如果控制insert到表里的值,就用表的chech约束实现。
      

  4.   

    完全看不懂,这样?
     select * from students
           where date=201309 and 201309=201309
      

  5.   

    select * from students
           where date=201309 and sysdate=201309
      

  6.   

    你是要固定死这个 201309 ,还是这种格式的,比如只人符合 yyyymm 的就算合法?
      

  7.   


    -- 这个可以实现只能输入 201309 这个固定值 ;
     
    SQL> 
    SQL> create table test(id int) ;
     
    Table created
    SQL> insert into test values(100);
     
    1 row inserted
    SQL> select * from test
      2  where id = decode('201309','201309',1,'a');
     
                                         ID
    ---------------------------------------
    SQL> select * from test
      2  where id = decode('201309','201302',1,'a');
     
    select * from test
    where id = decode('201309','201302',1,'a')
     
    ORA-01722: 无效数字
    SQL> drop table test purge ;
     
    Table dropped
     
    SQL>