SQL能完成的逻辑都在SQL中

decode, case的用法

select t.startCity,t.endCity,t.weightPrice,t.lightPrice,to_char(t.startTime,'hh24:mi:ss') as startTime,t.timeLimit||'hr.' timeLimit,to_char(t.endLimit,'hh24:mi:ss') as endLimit,to_char(t.pupTime,'hh24:mi:ss') as pupTime,'faster' as quotationVersion,decode(t.arrival_date_type,0,'today',1,'tomorrow',2,'1 day',3,'two day') arrivalDateType,(case when 1/0.05>=250 then (case when (weightPrice*1)>30 then (weightPrice*1) else 30 end) else (case when (lightPrice*0.05)>30 then (lightPrice*0.05) else 30 end) end) price from tms.quotation_a t where t.startCity='peka' and t.endCity='shaa'
union
select t.startCity,t.endCity,t.weightPrice,t.lightPrice,'' startTime,t.timeLimit/24||'Day' as timeLimit,'' endLimit,to_char(t.pupTime,'hh24:mi:ss') as pupTime,'standard' as quotationVersion,'' arrivalDataType,(case when 1/0.05>=250 then (case when (weightPrice*1)>20 then (weightPrice*1) else 20 end) else (case when (lightPrice*0.05)>20 then (lightPrice*0.05) else 20 end) end) price from tms.quotation_b t where t.startCity='peka' and t.endCity='shaa';


新行插入,既可以从旧行中取值又可以传参数。

insert into message(select sid.nextval id, ? as no,b.subject, ? as content, ? as customer,b.order,b.station,sysdate time_stampt,'提问' type from message b where b.id= ?


导入部分数据到新表

declare
v_license_no varchar(50);
v_station_code varchar(50);
v_cnt1 number;
v_cnt number;

TYPE T_CURTYPE IS REF CURSOR;
C_CUR T_CURTYPE;

begin
v_cnt := 0;
OPEN C_CUR FOR
select ta.license_no,ta.station_code from truck_archives ta;
loop
FETCH C_CUR INTO v_license_no,v_station_code;
EXIT WHEN C_CUR%NOTFOUND;
insert into truck_station(ttsn_id,license_no,station_code,validation_date)values(s_ttsn_id.nextval,v_license_no,v_station_code,sysdate);
v_cnt := v_cnt+1;
end loop;
dbms_output.put_line('v_cnt:'|| v_cnt);

CLOSE C_CUR;
--commit;
null;

end;



select substr(tr.name,0,length(tr.name)-2) name,tr.name,tr.dizhi,tr.canshu,tr.xiangmu,tr.xuhao from (select rank() over(PARTITION BY t.dizhi order by t.xuhao asc) rk,t.name,t.dizhi,t.canshu,t.xiangmu,t.xuhao from t_test t where t.xuhao>='1030' ) tr where tr.rk=1;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值