| 1 | #!/bin/bash |
|---|
| 2 | |
|---|
| 3 | #######################################################33333] |
|---|
| 4 | ########## |
|---|
| 5 | # ÿÌìµÄ9£¬10£¬11£¬12£¬14£¬15£¬16£¬17£¬18£¬21 |
|---|
| 6 | # žüÐÂ3žöÁÙʱ±íÍê³ÉitÉ̳ǵĜӿÚÊýŸÝžüР|
|---|
| 7 | # |
|---|
| 8 | # |
|---|
| 9 | |
|---|
| 10 | NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK" |
|---|
| 11 | ORACLE_HOME=/oracle/product/10.2.0 |
|---|
| 12 | ORACLE_SID=v880 |
|---|
| 13 | ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data |
|---|
| 14 | PATH=/usr/ccs/bin:/usr/bin:/usr/local/bin:/usr/sbin:/usr/ucb:/etc:$ORACLE_HOME/bin:. |
|---|
| 15 | export NLS_LANG |
|---|
| 16 | export ORACLE_HOME |
|---|
| 17 | export ORACLE_SID |
|---|
| 18 | export ORA_NLS33 |
|---|
| 19 | export PATH |
|---|
| 20 | |
|---|
| 21 | cd /data/oracle/crontab/app/ |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | TIM=`/usr/bin/date +%H` |
|---|
| 25 | |
|---|
| 26 | TAB_NAME_1=v_ent_product_min_1 |
|---|
| 27 | TAB_NAME_2=v_ent_product_max_1 |
|---|
| 28 | TAB_NAME_3=v_ent_product_1 |
|---|
| 29 | TAB_NAME_4=v_ent_brand_product_1 |
|---|
| 30 | TAB_NAME_5=v_ent_news_1 |
|---|
| 31 | TAB_NAME_6=ent_tmp_user_brand_1 |
|---|
| 32 | TAB_NAME_7=pdl_temp_product_pic_1 |
|---|
| 33 | |
|---|
| 34 | # 9, 11, 14, 16, 18 # TAB_NAME = 1 |
|---|
| 35 | # 10, 12, ,15, ,17, ,21 # TAB_NAME = 2 |
|---|
| 36 | # |
|---|
| 37 | # v_ent_news |
|---|
| 38 | # v_ent_product |
|---|
| 39 | # v_ent_product_min |
|---|
| 40 | # |
|---|
| 41 | # only refresh this three tables |
|---|
| 42 | # |
|---|
| 43 | # |
|---|
| 44 | |
|---|
| 45 | if [ $TIM -eq 9 -o $TIM -eq 11 -o $TIM -eq 14 -o $TIM -eq 16 -o $TIM -eq 18 ] |
|---|
| 46 | then |
|---|
| 47 | TAB_NAME_1=v_ent_product_min_1 |
|---|
| 48 | TAB_NAME_2=v_ent_product_max_1 |
|---|
| 49 | TAB_NAME_3=v_ent_product_1 |
|---|
| 50 | TAB_NAME_4=v_ent_brand_product_1 |
|---|
| 51 | TAB_NAME_5=v_ent_news_1 |
|---|
| 52 | TAB_NAME_6=ent_tmp_user_brand_1 |
|---|
| 53 | TAB_NAME_7=pdl_temp_product_pic_1 |
|---|
| 54 | else |
|---|
| 55 | TAB_NAME_1=v_ent_product_min_2 |
|---|
| 56 | TAB_NAME_2=v_ent_product_max_2 |
|---|
| 57 | TAB_NAME_3=v_ent_product_2 |
|---|
| 58 | TAB_NAME_4=v_ent_brand_product_2 |
|---|
| 59 | TAB_NAME_5=v_ent_news_2 |
|---|
| 60 | TAB_NAME_6=ent_tmp_user_brand_2 |
|---|
| 61 | TAB_NAME_7=pdl_temp_product_pic_2 |
|---|
| 62 | fi |
|---|
| 63 | |
|---|
| 64 | echo `date +%Y%m%d%H%m ` |
|---|
| 65 | |
|---|
| 66 | echo $TAB_NAME_1 |
|---|
| 67 | echo $TAB_NAME_2 |
|---|
| 68 | echo $TAB_NAME_3 |
|---|
| 69 | echo $TAB_NAME_4 |
|---|
| 70 | echo $TAB_NAME_5 |
|---|
| 71 | echo $TAB_NAME_6 |
|---|
| 72 | echo $TAB_NAME_7 |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | sqlplus "/ as sysdba" << EOF |
|---|
| 77 | |
|---|
| 78 | SET TIMING ON ; |
|---|
| 79 | |
|---|
| 80 | alter session set current_schema=cyp_nw_app; |
|---|
| 81 | |
|---|
| 82 | set timing on ; |
|---|
| 83 | |
|---|
| 84 | --v_ent_product_min |
|---|
| 85 | |
|---|
| 86 | prompt $TAB_NAME_1 ; |
|---|
| 87 | spool $TAB_NAME_1 ; |
|---|
| 88 | |
|---|
| 89 | truncate table $TAB_NAME_1 ; |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | drop table r_temp ; |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | create table r_temp as |
|---|
| 96 | select /*+index r (IDX_ENT_PRODUCT_2)*/
|
|---|
| 97 | r.id,r.type_id,r.user_id,r.product_id,r.name,z.status,r.CREATION_DATE,
|
|---|
| 98 | z.LAST_UPDATE_DATE,z.PRODUCT_ORDER,z.HAVE_PRODUCT,r.TYPE,r.SMALL_IMG,
|
|---|
| 99 | r.PRODUCT_INTRO,z.RETAIL_PRICE,r.RETAIL_VALID_DATE,r.VALIDATION,r.REF_PRICE,
|
|---|
| 100 | r.CHANGE_RATE,z.PRICE_STATUS,r.ADUIT_BY,r.ADUIT_DATE,r.VERSION,r.PROVINCE,
|
|---|
| 101 | r.CITY,r.DISTRICT,z.ONLINE_FLAG,z.WARRANTY,r.TITLE,r.IMG,r.BRAND_NAME,z.SELL_STATUS,
|
|---|
| 102 | z.COUNT,z.START_DATE,z.END_DATE,z.PAYMENT,z.ADD_COUNT,z.LAST_UPDATE_BY,
|
|---|
| 103 | z.FIRST_ON_SELL_TIME,z.SOLD_COUNT,r.EDITOR_RECOMMEND,r.EDITOR_SMALL_RECOMMEND, |
|---|
| 104 | z.LAST_RETAIL_PRICE,
|
|---|
| 105 | decode(r.editor_recommend+r.editor_small_recommend,0,0,1) as e_recommend
|
|---|
| 106 | from ent_product r, ent_product_item z
|
|---|
| 107 | where r.id=z.company_product_id
|
|---|
| 108 | and z.status <=1
|
|---|
| 109 | and z.retail_price>0
|
|---|
| 110 | and r.type_id is not null
|
|---|
| 111 | and sysdate between z.start_date and z.end_date; |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | create index idx1_r1 on r_temp( user_id,type_id, product_id) ; |
|---|
| 115 | analyze index idx1_r1 compute statistics ; |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | insert /*+append*/ into $TAB_NAME_1 |
|---|
| 120 | select t1.* from
|
|---|
| 121 | r_temp t1
|
|---|
| 122 | , (select r1.user_id,r1.type_id,r1.product_id,r1.e_recommend,min(r1.online_flag) as online_flag from r_temp r1,
|
|---|
| 123 | (select user_id,type_id,product_id,max(e_recommend) as e_recommend
|
|---|
| 124 | from r_temp
|
|---|
| 125 | group by user_id,type_id, product_id) r2
|
|---|
| 126 | where r1.user_id=r2.user_id
|
|---|
| 127 | and r1.type_id=r2.type_id
|
|---|
| 128 | and r1.product_id=r2.product_id
|
|---|
| 129 | and r1.e_recommend=r2.e_recommend
|
|---|
| 130 | group by r1.user_id,r1.type_id,r1.product_id,r1.e_recommend ) t2
|
|---|
| 131 | where t1.user_id=t2.user_id
|
|---|
| 132 | and t1.type_id=t2.type_id
|
|---|
| 133 | and t1.product_id=t2.product_id
|
|---|
| 134 | and t1.e_recommend=t2.e_recommend
|
|---|
| 135 | and t1.online_flag=t2.online_flag ; |
|---|
| 136 | |
|---|
| 137 | commit; |
|---|
| 138 | |
|---|
| 139 | |
|---|
| 140 | ##### È·±£ÏÂÃæµÄ±íÊýŸÝµÄžüÐÂʹÓõœ×îеÄÊýŸÝ¡£ |
|---|
| 141 | |
|---|
| 142 | create or replace synonym cyp_nw_app.v_ent_product_min for $TAB_NAME_1 ; |
|---|
| 143 | |
|---|
| 144 | spool off ; |
|---|
| 145 | |
|---|
| 146 | --insert /*+append*/ into $TAB_NAME_1 |
|---|
| 147 | -- select t1.* from ( |
|---|
| 148 | -- select r.*,decode(editor_recommend+editor_small_recommend,0,0,1) as e_recommend |
|---|
| 149 | -- from ent_product r |
|---|
| 150 | -- where r.status <=1 |
|---|
| 151 | -- and r.retail_price>0 |
|---|
| 152 | -- and r.type_id is not null |
|---|
| 153 | -- and sysdate between r.start_date and r.end_date) t1 |
|---|
| 154 | -- , (select r1.user_id,r1.type_id,r1.product_id,r1.e_recommend,min(r1.online_flag) as online_flag from |
|---|
| 155 | -- (select r.*,decode(editor_recommend+editor_small_recommend,0,0,1) as e_recommend |
|---|
| 156 | -- from ent_product r |
|---|
| 157 | -- where r.status <=1 |
|---|
| 158 | -- and r.retail_price>0 |
|---|
| 159 | -- and r.type_id is not null |
|---|
| 160 | -- and sysdate between r.start_date and r.end_date) r1, |
|---|
| 161 | -- (select user_id,type_id,product_id,max(e_recommend) as e_recommend |
|---|
| 162 | -- from (select /*+index r (IDX_ENT_PRODUCT_2)*/ r.*,decode(editor_recommend+editor_small_recommend,0,0,1) as e_recommend |
|---|
| 163 | -- from ent_product r |
|---|
| 164 | -- where r.status <=1 |
|---|
| 165 | -- and r.retail_price>0 |
|---|
| 166 | -- and r.type_id is not null |
|---|
| 167 | -- and sysdate between r.start_date and r.end_date) |
|---|
| 168 | -- group by user_id,type_id, product_id) r2 |
|---|
| 169 | --where r1.user_id=r2.user_id |
|---|
| 170 | -- and r1.type_id=r2.type_id |
|---|
| 171 | -- and r1.product_id=r2.product_id |
|---|
| 172 | -- and r1.e_recommend=r2.e_recommend |
|---|
| 173 | -- group by r1.user_id,r1.type_id,r1.product_id,r1.e_recommend ) t2 |
|---|
| 174 | -- where t1.user_id=t2.user_id |
|---|
| 175 | -- and t1.type_id=t2.type_id |
|---|
| 176 | -- and t1.product_id=t2.product_id |
|---|
| 177 | -- and t1.e_recommend=t2.e_recommend |
|---|
| 178 | -- and t1.online_flag=t2.online_flag ; |
|---|
| 179 | -- |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | --v_ent_product |
|---|
| 183 | |
|---|
| 184 | prompt $TAB_NAME_3 ; |
|---|
| 185 | SPOOL $TAB_NAME_3 ; |
|---|
| 186 | |
|---|
| 187 | truncate table $TAB_NAME_3 ; |
|---|
| 188 | |
|---|
| 189 | |
|---|
| 190 | insert /*+append*/ into $TAB_NAME_3 |
|---|
| 191 | select t7.* from v_ent_product_min t7 , |
|---|
| 192 | (select t5.user_id,t5.type_id,t5.product_id,t5.e_recommend,t5.online_flag, t5.last_update_date,max(t5.id) as id |
|---|
| 193 | from v_ent_product_min t5 , |
|---|
| 194 | (select t3.user_id,t3.type_id,t3.product_id,t3.e_recommend,t3.online_flag, |
|---|
| 195 | max(t3.last_update_date) as last_update_date |
|---|
| 196 | from v_ent_product_min t3 |
|---|
| 197 | group by t3.user_id,t3.type_id,t3.product_id,t3.e_recommend,t3.online_flag |
|---|
| 198 | ) t6 |
|---|
| 199 | where t5.user_id=t6.user_id |
|---|
| 200 | and t5.type_id=t6.type_id |
|---|
| 201 | and t5.product_id=t6.product_id |
|---|
| 202 | and t5.e_recommend=t6.e_recommend |
|---|
| 203 | and t5.online_flag=t6.online_flag |
|---|
| 204 | and t5.last_update_date=t6.last_update_date |
|---|
| 205 | group by t5.user_id,t5.type_id,t5.product_id,t5.e_recommend,t5.online_flag, |
|---|
| 206 | t5.last_update_date) t8 |
|---|
| 207 | where t7.id=t8.id; |
|---|
| 208 | |
|---|
| 209 | commit; |
|---|
| 210 | |
|---|
| 211 | delete from $TAB_NAME_3 r_temp where exists (select 1 from pdl_product t2 where r_temp.product_id=t2.id and t2.type_id<>r_temp.type_id); |
|---|
| 212 | |
|---|
| 213 | COMMIT; |
|---|
| 214 | |
|---|
| 215 | spool off; |
|---|
| 216 | |
|---|
| 217 | |
|---|
| 218 | --v_ent_news |
|---|
| 219 | |
|---|
| 220 | prompt $TAB_NAME_5 ; |
|---|
| 221 | spool $TAB_NAME_5 ; |
|---|
| 222 | |
|---|
| 223 | truncate table $TAB_NAME_5 ; |
|---|
| 224 | |
|---|
| 225 | insert /*+append*/ into $TAB_NAME_5 |
|---|
| 226 | SELECT t.*, m.new_update_date from ENT_NEWS t, |
|---|
| 227 | (SELECT MAX(c.id) AS id, c.user_id, c.small_id, c.brand_id, c.province, |
|---|
| 228 | c.city,c.new_update_date |
|---|
| 229 | FROM ( SELECT a.id, a.user_id, a.small_id, a.brand_id, a.province, a.city, |
|---|
| 230 | a.last_update_date, |
|---|
| 231 | DECODE(b.news_id,NULL, a.last_update_date, sysdate) AS new_update_date |
|---|
| 232 | FROM ENT_NEWS a, ENT_NEWS_POSITION_AD b |
|---|
| 233 | WHERE a.status<=1 AND a.id = b.news_id(+) |
|---|
| 234 | ) c, |
|---|
| 235 | ( SELECT user_id, small_id, brand_id, province, city, |
|---|
| 236 | MAX(new_update_date) AS new_update_date |
|---|
| 237 | FROM (SELECT a.id, a.user_id, a.small_id, a.brand_id, a.province, a.city, |
|---|
| 238 | a.last_update_date, |
|---|
| 239 | DECODE(b.news_id,NULL, a.last_update_date, sysdate) AS new_update_date |
|---|
| 240 | FROM ENT_NEWS a, ENT_NEWS_POSITION_AD b |
|---|
| 241 | WHERE a.status<=1 AND a.id = b.news_id(+) |
|---|
| 242 | ) GROUP BY user_id, small_id, brand_id, province, city |
|---|
| 243 | ) d |
|---|
| 244 | WHERE c.user_id = d.user_id |
|---|
| 245 | AND c.small_id = d.small_id |
|---|
| 246 | AND c.brand_id = d.brand_id |
|---|
| 247 | AND c.province = d.province |
|---|
| 248 | AND c.city = d.city |
|---|
| 249 | AND c.new_update_date = d.new_update_date |
|---|
| 250 | GROUP BY c.user_id, c.small_id, c.brand_id, c.province, c.city, c.new_update_date ) m |
|---|
| 251 | where t.id=m.id ; |
|---|
| 252 | |
|---|
| 253 | COMMIT; |
|---|
| 254 | |
|---|
| 255 | SPOOL OFF; |
|---|
| 256 | |
|---|
| 257 | |
|---|
| 258 | --- ŲµœÉÏÃæÖŽÐÐÁË£¬ÕâÀïÆÁ±Î |
|---|
| 259 | ---create or replace synonym cyp_nw_app.v_ent_product_min for $TAB_NAME_1 ; |
|---|
| 260 | |
|---|
| 261 | |
|---|
| 262 | create or replace synonym cyp_nw_app.v_ent_product for $TAB_NAME_3 ; |
|---|
| 263 | |
|---|
| 264 | --- ²úÆ·¿âÒ²Òª ÒýÓà v_ent_productÕâÌõ±íÀ²£¬ÐèÒª ŽŠÀíÏÂÈšÏÞÎÊÌâ |
|---|
| 265 | |
|---|
| 266 | grant select on cyp_nw_app.$TAB_NAME_3 to product_app; |
|---|
| 267 | |
|---|
| 268 | grant select on cyp_nw_app.$TAB_NAME_3 to product_pub; |
|---|
| 269 | |
|---|
| 270 | grant select on cyp_nw_app.v_ent_product to product_app; |
|---|
| 271 | |
|---|
| 272 | create or replace synonym product_app.v_ent_product for cyp_nw_app.v_ent_product; |
|---|
| 273 | |
|---|
| 274 | grant select on cyp_nw_app.v_ent_product to product_pub; |
|---|
| 275 | |
|---|
| 276 | create or replace synonym product_pub.v_ent_product for cyp_nw_app.v_ent_product; |
|---|
| 277 | |
|---|
| 278 | |
|---|
| 279 | |
|---|
| 280 | create or replace synonym cyp_nw_app.v_ent_news for $TAB_NAME_5 ; |
|---|
| 281 | |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | EOF |
|---|