日期:2014-05-17 浏览次数:20955 次
with t1 as ( select '421022199911113425' c1 from dual union all select '242244555222114' from dual union all select '24224455522211124x' from dual ) select decode(length(c1),15,1,18,2) c1 from t1 ; c1 ------------- 1 2 2 1 3 2 select case when (select count(c1) from t1) <= 1 then 1 else 2 end c1 from dual; c1 ------------- 1 2
------解决方案--------------------
小写一个,可以参考一下
CREATE TABLE message(id NUMBER(10),mid VARCHAR2(18),NAME VARCHAR2(20)); INSERT INTO message VALUES (1,'450902198711302756','xiao de'); CREATE OR REPLACE FUNCTION F_TEST_SFZHAO(p_mid VARCHAR2) RETURN NUMBER IS v_id NUMBER; BEGIN SELECT Length(mid) INTO v_id FROM message WHERE mid=p_mid AND ROWNUM=1; IF v_id=15 THEN RETURN 1; ELSIF v_id=18 THEN RETURN 2; END IF; EXCEPTION WHEN No_Data_Found THEN RETURN 9; END; DECLARE v_return NUMBER; BEGIN v_return:=F_TEST_SFZHAO('45090219871130275'); Dbms_Output.put_line(v_return); END;
------解决方案--------------------
把第二个函数写了你看一下,不知道能否帮到你,我也是刚刚的学
create or replace function F_test_count(aac002 varchar2) return varchar2 is
v_count varchar2(2);
v_number number(8);
begin
select count(aac002) into v_number from eaa8 ;
if v_number = 1 then
v_count:=1;
else
v_count:=2;
end if;
return v_count;
end;
------解决方案--------------------