日期:2014-05-17 浏览次数:20928 次
declare
v_tmp varchar2(2);
begin
select substr('PS',1,1) into v_tmp from dual;
if v_tmp = 'P' then
dbms_output.put_line('开头是P字母');
else
dbms_output.put_line('开头不是P字母');
end id;
end;
------解决方案--------------------
使用like或者正则表达式
------解决方案--------------------
如果你是在查询的时候判断的话,那么可以这样写.
select e.ename, e.sal from emp e where e.ename like 'P%';
或者
select e.ename, e.sal from emp e where lower(substr(e.ename,1,1))=lower('P');
------解决方案--------------------
select decode(substr('pma',1,1),'p','p','不p') c1,
decode(substr('zuoma',1,1),'p','p','不p') c2
from dual
c1 c2
-------------------------
1 p 不p
------解决方案--------------------
substr 或者 like 都可以,没必要正则,复杂了。