可用instr函數(shù)。
創(chuàng)新互聯(lián)建站專業(yè)為企業(yè)提供羅山網(wǎng)站建設(shè)、羅山做網(wǎng)站、羅山網(wǎng)站設(shè)計(jì)、羅山網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)與制作、羅山企業(yè)網(wǎng)站模板建站服務(wù),十多年羅山做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
如:
select?instr('sdfcontain234','contain')?from?dual;
結(jié)果:
如果返回值大于0,則表示字符串中包含contain。
再如:
select?instr('sdfcontn234','contain')?from?dual;
結(jié)果:
如果返回值為0,則代表字符串中不包含contain。
前閉后開(30 = xxx 50)只能用 = xxx 來連接
WHERE xxx = 30 AND xxx 50
如果是前后都閉合(30= xxx = 50)那么可以用BETWEEN XX AND xxx
WHERE XXX BETWEEN 30 AND 50
select sum(case when flag1+falg2=11 then 1 else 0 end) as 既含有國(guó)產(chǎn)又有自制的,
sum(case when flag1+falg2=1 then 1 else 0 end) as 只有國(guó)產(chǎn)的,
sum(case when flag1+falg2=10 then 1 else 0 end) as 只有自制的
from (
select (case when instr(藥品來源,'國(guó)產(chǎn)')0 then 1 else 0 end ) as flag1,
(case when instr(藥品來源,'自制')0 then 10 else 0 end ) as flag2
from table_name
) t
直接寫就可以
create or replace trigger checkmodulecount
before insert on registration
for each row
declare
moduleCount number;
ex exception;
begin
select count(moduleid) into moduleCount
from registration r,student s
where r.studentid=:new.studentid
and r.studentid=s.studentid
and (r.semester='2' or r.semester='1');
select lastname into tname from students where studentid=:new.studentid;
if moduleCount 4 then
dbms_output.put_line('Module registered successful');
else
raise ex;
end if;
exception
when ex then
raise_application_error(-20000, 'Student '|| s.lastname|| ' ID '||studentid || ' has register 4 modules already, the number of module for a particular semester should not exceed 4');
end;
plsql developer中 有個(gè)“小望遠(yuǎn)鏡圖標(biāo)的”搜索功能
select TABLE_NAME from user_tab_columns where column_name Like '%K%'
select?*?from?a?where?instr(a,b)0;
這個(gè)只能實(shí)現(xiàn)B字段是A字段中的某一部分的時(shí)候,
如果想要不論順序或者不相鄰的字符時(shí),定義函數(shù)可以實(shí)現(xiàn)
create?or?replace?function?checks(v_a?varchar2,v_b?varchar)
return?number
as
num?number;
cou?number;
begin
num?:=?-1;
cou:=0;
for?i?in?1..length(v_b)?loop
if?instr(v_a,substr(v_b,i,1))0?then
cou:=cou+1;
end?if;
end?loop;
if?cou=length(v_b)?then
return?cou;
end?if;
dbms_output.put_line(cou||'????'||length(v_b));
return?num;
end;
結(jié)果:
SQL?select?*?from?a;
A??????????B
----------?----------
asdf???????sd
asdf???????ad
asdf???????df
asdf???????asdf
SQL?select?*?from?a?where?checks(a,b)0;
A??????????B
----------?----------
asdf???????sd
asdf???????ad
asdf???????df
asdf???????asdf