我想要在oracle里用sql 语句实现控制where后接的条件只能是某一个具体值(条件)
例如:有学生表,表里有学号,入学日期(date,有201309,201409```)```等信息
select * from students
where date=201309
我想要限制date的日期只能填写201309,填别的值就会报错。请各位大神指点,拜谢!!!!!
例如:有学生表,表里有学号,入学日期(date,有201309,201409```)```等信息
select * from students
where date=201309
我想要限制date的日期只能填写201309,填别的值就会报错。请各位大神指点,拜谢!!!!!
如果是,那就全都页面控制住就完事了,如果想在直接操作oracle的时候控制查询,不可能,要不就不给别人这个表的查询权限,要不就把你不想给别人看的数据清空。
如果控制insert到表里的值,就用表的chech约束实现。
select * from students
where date=201309 and 201309=201309
where date=201309 and sysdate=201309
-- 这个可以实现只能输入 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>