select instr('xtr','x') from dual t --instr,函式,返回某字元出現的位置
select instr('syran ma','a',1,2) from dual;
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual
select to_date('2010-12-29 17:53:38','yyyy-mm-dd hh24:mi:ss') from dual
select upper('wmch') from dual
select lower('wmch') from dual
-- create table wmc_cust_info
create table wmc_cust_info
(active_id varchar2(100) not null,
batch_id varchar2(32),
flag_id varchar2(2),
cust_source varchar2(200),
product_name varchar2(100),
cust_num number
)tablespace tps_user1
pctfree 10
initrans 1
maxtrans 255
storage
(initial 64k
next 1m
minextents 1
maxextents unlimited
);create table wmc_cust_info2 as
select * from tb_sv_cust_info
select * from wmc_cust_info
select * from wmc_cust_info2
--儲存過程例子1
create or replace procedure wmc_proa
(activeid in wmc_cust_info.active_id%type)
isvar_active_id wmc_cust_info.active_id%type;
var_batch_id wmc_cust_info.batch_id%type;
begin
var_active_id := activeid;
var_batch_id := '1';
insert into wmc_cust_info(active_id,batch_id,flag_id,cust_source,product_name,cust_num)
select var_active_id,var_batch_id,'1','2023年王明超搶票活動','彩信',1300 from dual;
commit;
dbms_output.put_line(var_active_id||'測試');
end;
call wmc_proa('王明超搶票活動2')
--儲存過程例子2
create or replace procedure wmc_prob
isbegin
update wmc_cust_info t set t.batch_id='3' where t.active_id='s0145-簡訊搶票活動';
if sql%found then
dbms_output.put_line('update successfully');
commit;
else
dbms_output.put_line('update failure');
end if;
end;
call wmc_prob()
--儲存過程例子3
create or replace procedure wmc_proc
iscursor curone is --定義游標
select *
from wmc_cust_info t
where t.active_id='王明超搶票活動';
varcurinfo wmc_cust_info%rowtype; --定義游標變數
begin
open curone;
loop
fetch curone into varcurinfo;
exit when curone%notfound;
dbms_output.put_line(varcurinfo.active_id||'>>'||varcurinfo.batch_id||'>>'||varcurinfo.cust_source);
end loop;
exception
when others then
close curone;
dbms_output.put_line('failure');
if curone%isopen then
close curone;
end if;
end;
--儲存過程例子4
create or replace procedure wmc_prod
iscursor curone is --定義游標
select t.active_id,t.cust_source
from wmc_cust_info t
where t.active_id='王明超搶票活動';
varactiveinfo wmc_cust_info.active_id%type; --定義游標變數
varcustsource wmc_cust_info.cust_source%type;
begin
open curone;
loop
fetch curone into varactiveinfo,varcustsource;
exit when curone%notfound;
dbms_output.put_line(varactiveinfo||'>>'||varcustsource);
end loop;
exception
when others then
close curone;
dbms_output.put_line('failure');
if curone%isopen then
close curone;
end if;
end;
--儲存過程例子5
create or replace procedure wmc_proe
iscursor curone is --定義游標
select *
from wmc_cust_info t
where t.active_id='王明超搶票活動';
begin
open curone;
for curinfo in curone loop
exit when curone%notfound;
dbms_output.put_line(curinfo.active_id||'>>'||curinfo.cust_source);
end loop;
exception
when others then
close curone;
dbms_output.put_line('failure');
if curone%isopen then
close curone;
end if;
end;
--儲存過程例子6
create or replace procedure wmc_prof
istype curtype is ref cursor;
curone curtype;
sqlstr varchar2(500);
curinfo wmc_cust_info%rowtype;
begin
--定義動態sql
sqlstr := 'select t.* from wmc_cust_info t where t.active_id=''王明超搶票活動''';
open curone for sqlstr;
loop
fetch curone into curinfo;
exit when curone%notfound;
dbms_output.put_line(curinfo.active_id||'*'||curinfo.cust_source);
end loop;
close curone;
end;
call wmc_prof()
SQL語句練習
建立一張表,記錄 呼叫員的工作流水,記錄呼叫員編號,對方號碼,通話開始時間,結束時間。建表,插資料等都自己寫出sql 要求 輸出所有資料中通話時間最長的5條記錄。輸出所有資料中撥打長途號碼 對方號碼以0開頭 的總時長 輸出本月通話時長最多的前三個呼叫員的編號 輸出本月撥打 次數最多的前三個呼叫員的編...
SQL 語句練習
mysql select from persons limit 5 oracle select from persons where rownum 5 select from persons where name like l select from persons where name not l...
SQL語句練習
1 把兩張 的資料抽取出來放到另外一張 中 1 pt表 role id int pt int 2 season score表 role id int season score int 3 player表 role id int pt int season score int count int 4 ...