存储过程,视图

记录以前公司写的几个视图和存储过程

1、自动发送短信提醒create or replace procedure Proc_auto_remind_sms is --定义变量 vs_template_content varchar2(400); --格式化后的短信内容 --定义游标(获得符合发送条件的记录) cursor result_cur is select a.detail_id,a.customer_id,a.customer_mobile,a.plan_arr_time,a.product_id from( --获得邀约时间为明天的客户 select r.detail_id,r.customer_id,r.customer_mobile,r.plan_arr_time,r.product_id from DMS_APP_TMS_RESULT r,DMS_APP_TASK t where r.task_id = t.task_id and t.autosms = 1 --对应的任务设置了自动短信提醒 and r.sms_remind_status = 0 --未发送提醒短信的 and INVITE_TODAY = 2 and PLAN_ARR_TIME is not null and trunc(PLAN_ARR_TIME - 1) = trunc(sysdate) union --获得追拨邀约时间为明天的客户 select r.detail_id,r.customer_id,r.customer_mobile,r.CHASE_PLAN_ARR_TIME as plan_arr_time,r.product_id from DMS_APP_TMS_RESULT r,DMS_APP_TASK t where r.task_id = t.task_id and t.autosms = 1 and r.sms_remind_status = 0 and INVITE_TODAY = 2 and CHASE_PLAN_ARR_TIME is not null and trunc(CHASE_PLAN_ARR_TIME - 1) = trunc(sysdate) )a; begin --遍历 for customer in result_cur loop --格式化发送的短信内容,首先获得模板 select template_content into vs_template_content from dms_sms_template t where t.product_id = customer.product_id and t.big_type = 2 --提醒类型 and t.template_type = 1;--模板类型为短信; --替换模板里面的占位符 select replace(vs_template_content,'$1</p>,customer.customer_id) into vs_template_content from dual; select replace(vs_template_content,'$2</p>,to_char(customer.PLAN_ARR_TIME, 'mm')) into vs_template_content from dual; select replace(vs_template_content,'$3</p>,to_char(customer.PLAN_ARR_TIME, 'dd')) into vs_template_content from dual; --最后整合信息插入到dms_sms_task中,准备发送短信 insert into dms_sms_task(sms_task_id, sms_mobile, sms_content, detail_id,template_id,sms_inserttime) select seq_dms_sms_task_id.nextval as sms_task_id, customer.customer_mobile as sms_mobile, vs_template_content as sms_content, customer.detail_id as detail_id, template_id as template_id, sysdate as sms_inserttime from dms_sms_template t where t.product_id = customer.product_id and t.big_type = 2 --提醒类型 and t.template_type = 1;--模板类型为短信; --更新tms_result中sms_remind_status状态为1 update DMS_APP_TMS_RESULT t set t.sms_remind_status = 1 where t.detail_id = customer.detail_id; end loop; commit; end Proc_auto_remind_sms;

2、自动发送彩信提醒create or replace procedure Proc_auto_remind_mms is --创建提醒彩信游标 cursor cur_remind_mms is select a.customer_mobile, a.detail_id, c.template_id, c.mms_model_id from dms_app_tms_result a, dms_app_task b, dms_sms_template c where a.invite_today = 2 and a.plan_arr_time is not null and trunc(a.plan_arr_time - 1) = trunc(sysdate) --邀约计划到达头一天 and a.task_id = b.task_id and a.mms_remind_status = 0 --是否发过提醒彩信 and a.product_id = b.product_id and b.product_id = c.product_id and b.automms = 1 --自动发提醒彩信 and b.task_exe_type = 0 --呼叫型任务 and c.big_type = 2 --提醒服务 and c.template_type = 2 --彩信模板 union select a.customer_mobile, a.detail_id, c.template_id, c.mms_model_id from dms_app_tms_result a, dms_app_task b, dms_sms_template c where a.invite_today = 2 and a.chase_plan_arr_time is not null and trunc(a.chase_plan_arr_time - 1) = trunc(sysdate) --邀约计划到达头一天 and a.task_id = b.task_id and a.mms_remind_status = 0 --是否发过提醒彩信 and a.product_id = b.product_id and b.product_id = c.product_id and b.automms = 1 --自动发提醒彩信 and b.task_exe_type = 0 --呼叫型任务 and c.big_type = 2 --提醒服务 and c.template_type = 2; --彩信模板 begin --循环游标 for remind_mms in cur_remind_mms loop --把结果添加到彩信任务中 insert into dms_mms_task (mms_task_id, mobile, mms_model_id, detail_id, template_id, mms_sendtype, mms_task_status) values (seq_dms_mms_task_id.nextval, remind_mms.customer_mobile, remind_mms.mms_model_id, remind_mms.detail_id, remind_mms.template_id, 2, 0); --添加成功 更改是否发送提醒彩信状态为是 update dms_app_tms_result set mms_remind_status = 1 where detail_id = remind_mms.detail_id; end loop; commit; end Proc_auto_remind_mms;  

3、产品策略视图create or replace view v_product_policy as select rownum sid, a.customer_id, trunc(a.last_dist_time) as last_dist_time, --客户最近分配时间 h.project_name last_dist_project_name, --最近分配楼盘 h.project_id, a.customer_age, --客户年龄 a.customer_mobile, --手机号码 a.mobile_region, --手机号码归属地 a.customer_mobile2, a.customer_otherphone, a.customer_level, a.customer_phone, --固定电话 a.phone_region, --固定电话归属地 a.customer_buyinfo, --已购房情况 a.customer_assets, --家庭总资产 a.customer_region, --所在区域 a.customer_salary, --目前月收入 a.customer_family, --家庭成员数 a.parents_city, --老人居住城市 a.customer_company, --工作单位 a.number_buy, --第几次购房 a.customer_hobbies, --个人爱好 a.CUSTOMER_TYPE,-- 客户类别 a.CUSTOMER_ACTIVE_LEVEL,--客户活跃程度 a.customer_STATUS, --客户身份; f.project_name, --楼盘名称 f.city, --城市 f.area, --区域 f.location, --位置 f.ringline, -- 环线 trunc(b.visite_date) as visite_date, --到访时间 c.customer_age subscribe_customer_age, --客户年龄 c.customer_job, --客户职业 c.customer_now_prov, --所在省份 c.customer_now_city, --现在居住城市 e.buy_object, --购房目的 d.project_name subscribe_project_name, --已购楼盘名称 g.housing_area, --建筑面积 g.PREBUY_PRICE_M2 as price_m2, --每平米价格 e.price_total_seal, --成交总价 e.first_pay, --首次付款额 e.pay_mode, --付款方式 e.rate_loan, --贷款比例 e.loan_years, --贷款年限 e.data_source, --数据来源 a.customer_name from dim_base_customer_info a, crc_app_customer_visite b, CRC_APP_CUSTOMER_PREBUY c, dim_base_project_info d, crc_app_buy e, dim_base_project_info f, dim_base_project_info h, dim_base_housing_info g where a.customer_id = b.customer_id(+) and a.customer_id = c.customer_id(+) and c.buy_id = e.buy_id(+) and b.project_id = f.project_id(+) and e.project_id = d.project_id(+) and e.housing_id = g.housing_id(+) and a.last_dist_project_id = h.project_id(+); 

4、任务variable job number; begin sys.dbms_job.submit(job => :job, what => 'Proc_auto_remind_mms;Proc_auto_remind_sms;', next_date => to_date(to_char(sysdate, 'yyyy-mm-dd') ||' 09:00:00','yyyy-mm-dd hh24:mi:ss')+1, interval => 'trunc(sysdate) +1'); commit; end; /  

你可能感兴趣的:(存储过程,视图)