0.kattle由四个工具,都可以看一看
1.数据库连接:
2.数据转换:
--1.先读到数据
select * from scott.gzesf@orcl2;
--2.设计清洗后的表
create table gzesf as
select '广东省' "省",
'广州市' "市",
area,
street,
community,
introduction,
room_type,
acreage,
price,
unit_price,
toward,
decoration,
elevator,
floor,
year,
'指定房屋类型' "type",
follow,
visit,
release_time,
url from gzesf@orcl2 e
where 1=2;
select * from gzesf@orcl2 old_g where old_g.room_type = '独栋别墅';
--3.实现部分,外部测试,做对应的查询
insert into gzesf
select
'广东省' 省, --设置对应的省
'广州市' 市, --设置对应的市
area, --无需修改
street, --无需修改
community, --无需修改
case room_type when '独栋别墅' then introduction||room_type--需要将 room_type为 独栋别墅 列的错误信息 装入此列
else introduction end
as introduction,
-- case room_type when '独栋别墅' then acreage--修改独栋别墅错列
-- else room_type end as room_type,
room_type,
--case room_type when '独栋别墅' then to_char(trunc(price*10000/unit_price))--修改独栋别墅错列
case room_type when '独栋别墅' then regexp_replace(toward,'[^0-9]')--修改独栋别墅错列
else to_char(nvl(regexp_replace(acreage, '[^0-9.]',''),0)) end as acreage,--to_char
price,
unit_price,
case room_type when '独栋别墅' then decoration --修改独栋别墅的错列
else toward end as toward,
case room_type when '独栋别墅' then '其他' --修改独栋别墅的错列
else decoration end as decoration,
nvl(elevator,'无电梯') as elevator,--去除空值
regexp_replace(floor,'[^0-9]','') as floor,
nvl(regexp_replace(year,'[^0-9]',''),
(select median(to_number(regexp_replace(year,'[^0-9]',''))) from scott.gzesf@orcl2)) as year,--year的去空以及中位数
replace(regexp_replace(year,'[0-9]'),'年建','') as type, --对year拆分的第二行
regexp_replace(follow,'[^0-9]','') as follow,
regexp_replace(visit,'[^0-9]','') as visit,
release_time,
url from scott.gzesf@orcl2
--where room_type = '独栋别墅';
where price in (350,1500);
--4.设计包和实现
CREATE OR REPLACE PACKAGE p_gzesf --包头
is
procedure clear_and_update_gezsf;
end p_gzesf;
-------包体,实现--------------------------------------------------------------------------
CREATE OR REPLACE PACKAGE body p_gzesf--包体,实现
is
procedure clear_and_update_gezsf
is
no_date exception;
v_num number;
begin
select count(*) into v_num from gzesf where rownum = 1;
if v_num > 0 then --查询,若表内有数据则先清空
delete from gzesf;
end if;
select count(*) into v_num from gzesf where rownum = 1;
if v_num = 0 then
select count(*) into v_num from scott.gzesf@orcl2 where rownum = 1;
if v_num = 0 then
raise no_date;
else --符合条件,开始插入数据
insert into gzesf
select
'广东省' 省, --设置对应的省
'广州市' 市, --设置对应的市
area, --无需修改
street, --无需修改
community, --无需修改
case room_type when '独栋别墅' then introduction||room_type--需要将 room_type为 独栋别墅 列的错误信息 装入此列
else introduction end as introduction,
case room_type when '独栋别墅' then acreage--修改独栋别墅错列
else room_type end as room_type,
case room_type when '独栋别墅' then regexp_replace(toward,'[^0-9]')--修改独栋别墅错列
else to_char(nvl(regexp_replace(acreage, '[^0-9.]',''),0)) end as acreage,--to_char
price,
unit_price,
case room_type when '独栋别墅' then decoration --修改独栋别墅的错列
else toward end as toward,
case room_type when '独栋别墅' then '其他' --修改独栋别墅的错列
else decoration end as decoration,
nvl(elevator,'无电梯') as elevator,--去除空值
regexp_replace(floor,'[^0-9]','') as floor,
nvl(regexp_replace(year,'[^0-9]',''),
(select median(to_number(regexp_replace(year,'[^0-9]',''))) from scott.gzesf@orcl2)) as year,--year的去空以及中位数
replace(regexp_replace(year,'[0-9]'),'年建','') as type, --对year拆分的第二行
regexp_replace(follow,'[^0-9]','') as follow,
regexp_replace(visit,'[^0-9]','') as visit,
release_time,
url from scott.gzesf@orcl2;
--插入结束,请查看
end if;
end if;
exception
when no_date then
dbms_output.put_line('源表gzesf没有数据,请查看!');
when others then
dbms_output.put_line(sqlcode||'-------'||sqlerrm);
end clear_and_update_gezsf;
begin
null;
end p_gzesf;
--5.测试
begin
p_gzesf.clear_and_update_gezsf;
end;
select count(*) from gzesf;
delete from gzesf;
--6.定时
declare
v_jobID number;
begin
dbms_job.submit ( job=>v_jobID ,
what=>'p_gzesf.clear_and_update_gezsf;',
next_date=> sysdate + 1/(24*60) ,
interval=>'trunc(sysdate,''mi'')+1/(24)');--这个提取分钟的mi 是由四个单引号包围的
commit;
end;
--也可以直接调用一次job
dbms_job.run(23);
select * from user_jobs;