我先定义了俩varchar2类型变量。m和n
在函数里,这样写的。
if m like ‘%n%’ then return true;
else return false;
提示说我定义了变量n而没有使用,请问
要看m是否与n相匹配到底那个n该咋写捏?
在函数里,这样写的。
if m like ‘%n%’ then return true;
else return false;
提示说我定义了变量n而没有使用,请问
要看m是否与n相匹配到底那个n该咋写捏?
应该写成m like ’%‘ || n || ’%’。另外if语句,需要有END if结尾,估计LZ忘了写了。
要写成 ‘%' || n || '%’原因, ‘%n%’ 写法,会被认为是字符 n ,而不是变量
else return false;-- v_m 是你定义的变量!
else return false;-- v_m 是你定义的变量!
-- 解释:如果 v_m 变量中,含有'n'字符,则返回 true,否则返回 false
2 return varchar2
3 is
4 begin
5 if instr(v_m,'n')>0 then
6 return 'true';
7 else
8 return 'false';
9 end if;
10 exception when others then
11 return 'false';
12 end;
13 /函数已创建。scott@TBWORA> select fun_n('luoyoumou') from dual;FUN_N('LUOYOUMOU')
------------------------------------------------------------------------------------------------------------------------
falsescott@TBWORA> select fun_n('luoyonumou') from dual;FUN_N('LUOYONUMOU')
------------------------------------------------------------------------------------------------------------------------
truescott@TBWORA> create or replace function fun_n(v_m varchar2)
2 return varchar2
3 is
4 begin
5 if v_m like '%n%' then
6 return 'true';
7 else
8 return 'false';
9 end if;
10 exception when others then
11 return 'false';
12 end;
13 /函数已创建。scott@TBWORA> select fun_n('luoyoumou') from dual;FUN_N('LUOYOUMOU')
------------------------------------------------------------------------------------------------------------------------
falsescott@TBWORA> select fun_n('luoyonumou') from dual;FUN_N('LUOYONUMOU')
------------------------------------------------------------------------------------------------------------------------
true