SqlServer楂樼骇鐗规€?-瀛樺偍杩囩▼
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SqlServer楂樼骇鐗规€?-瀛樺偍杩囩▼相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/%e5%ad%98%e5%82%a8%e8%bf%87%e7%a8%8b' title='瀛樺偍杩囩▼'>瀛樺偍杩囩▼
add class code 鍙橀噺 receive temp end var闇€姹傦細
鐢ㄦ埛闇€瑕佹彁浜ゅ姞瀵嗘暟鎹紝鎻愪氦涔嬪悗闇€瑕佽В瀵嗚繕鍘燂紝杩樺師鏈変袱绉嶇粨鏋滐細鎴愬姛鍜屽け璐ワ紒
100涓敤鎴凤紝涔嬪墠7澶╋紝鍒ゆ柇鏄惁鏈夋彁浜ゆ暟鎹紝濡傛灉鏈夋彁浜ゆ湁鏁版嵁锛屽垽鏂槸鍚﹁В瀵嗘垚鍔燂紙鍒嗗埆瀛樺湪涓や釜琛ㄤ腑锛夈€傚鏋滄病鏈夋彁浜わ紝鏄剧ず榛勮壊锛涙彁浜わ紝鏈В瀵嗘垚鍔燂紝绾㈣壊锛涙彁浜ゅ苟瑙e瘑鎴愬姛锛岀豢鑹诧紝骞舵樉绀哄搴旀椂闂淬€?/p>
鍒嗘瀽锛?/h3>
娴嬭瘯杩囬亶鍘嗘墍鏈夊崟浣嶏紝涔嬪悗閬嶅巻姣忎竴澶╋紝鍘绘煡璇㈡彁浜ゆ暟鎹紝鐒跺悗鍦ㄥ幓鏌ヨ瑙e瘑鏁版嵁銆傜粨鏋滀竴涓?00瀹跺崟浣嶏紝绔熺劧闇€瑕佸ぇ姒?-3鍒嗛挓鐨勬椂闂存潵鏌ヨ銆傦紙鎺ユ敹璁板綍閲岄潰鏁版嵁澶х害50w鏉★紝鍚庢湡鍙兘浼氭洿澶氾級锛屾槑鏄句笉鍚堥€傦紝铏界劧鍔犺繃缂撳瓨锛屼絾鏄笉绗﹀悎瑕佹眰銆?/p>
浼樺寲鎬濊矾锛?/p>
銆€銆€1. 鎴戞兂鐢?00瀹跺崟浣嶅拰7澶╁悓鏃跺幓鍏宠仈鎺ユ敹璁板綍琛紝杩涜鏌ヨ銆備篃灏辨槸澶氭潯浠跺乏澶栬繛鎺ユ煡璇€?/p>
銆€銆€2. 鎴戣鑾峰彇100瀹跺崟浣嶅拰7澶╃殑杩欐牱鐨勮〃锛岄渶瑕?00瀹跺崟浣嶅拰7涓棩鏈熺殑绗涘崱灏旂Н
銆€銆€3. 鎴戦渶瑕佷竴涓?澶╂棩鏈熺殑琛紝鍙互鍦ㄥ瓨鍌ㄨ繃绋嬩腑杩涜鍒涘缓涓存椂琛ㄣ€?/p>
鏁翠綋鎬濊矾灏辨槸杩欐牱鐨勩€?/p>
浠g爜锛?/h3>
鏁翠綋瀛樺偍杩囩▼浠g爜濡備笅锛?/p>
ALTER PROCEDURE [dbo].[AUTOTRANS] @xz VARCHAR(10)=鈥?/span>410000鈥?/span> , @day INT =7, @industryCode varchar(10)=鈥?/span>6001鈥?/span> AS BEGIN SET NOCOUNT ON; --瀹氫箟涓€涓彉閲忥細涓存椂琛紝鐢ㄦ埛瀛樺偍7澶╂暟鎹€?/span> DECLARE @days table (date date) DECLARE @today date = GETDATE() --瀹氫箟涓€涓惊鐜紝鐢ㄤ簬鎻掑叆涔嬪墠7澶╃殑鏁版嵁锛屼粠褰撳ぉ寮€濮?/span> WHILE @day >= 0 BEGIN insert into @days select DATEadd(dd,-@day, @today ); set @day =@day-1 END --涓氬姟鍖哄煙 SELECT D.XZ_CODE,D.UNIT_CODE,D.UNIT_NAME, CONVERT(varchar,D.RECEIVE_TIME,108) RECEIVE_TIME, CONVERT(varchar,MAX (E.RESTORE_TIME),108) RESTORE_TIME,D.date SELECT_DATE FROM ( SELECT A.XZ_CODE,A.UNIT_CODE,A.UNIT_NAME,MAX(C.RECEIVE_TIME) RECEIVE_TIME,B.date FROM (SELECT XZ_CODE,UNIT_CODE,UNIT_NAME FROM T_UNIT_AUDIT WHERE XZ_CODE = @xz AND INDUSTRY_CODE = @industryCode ) A CROSS JOIN @days B LEFT JOIN T_FILE_RECEIVE_RECORD C ON A.UNIT_CODE = C.UNIT_CODE AND A.XZ_CODE = C.XZ_CODE AND CONVERT(VARCHAR,B.date,23) = CONVERT(VARCHAR,C.RECEIVE_TIME,23) GROUP BY A.XZ_CODE,A.UNIT_CODE,A.UNIT_NAME,B.date ) D LEFT JOIN T_FILE_RESTORE_RECORD E ON D.XZ_CODE = E.XZ_CODE AND D.UNIT_CODE = E.UNIT_CODE AND CONVERT(VARCHAR,D.RECEIVE_TIME,23) = CONVERT(VARCHAR,E.RESTORE_TIME,23) GROUP BY D.RECEIVE_TIME,D.XZ_CODE,D.UNIT_CODE,D.UNIT_NAME,D.date END
缁撴灉娴嬭瘯锛?/h3>
鐩墠锛岄拡瀵?00瀹跺崟浣?澶╃殑鏁版嵁锛屽彲浠ヤ繚璇佸ぇ绾?绉掑唴瀹屾垚鏌ヨ锛屽綋鐒惰繖杩樺寘鍚簡鎴戝湪鍚庢湡杩涜鏁版嵁澶勭悊鐨勬椂闂淬€?/p>
鍐欏湪鏈€鍚庯細
鐢变簬椤圭洰鏄娇鐢ㄧ殑jdbcTemplate杩涜鐨勬寔涔呭眰鎿嶄綔锛屾墍浠ユ寔涔呭眰鎿嶄綔浠g爜闄勪笂锛?/p>
public List<Map<String, Object>> autoTrans(Map<String, Object> param) { String sql = "{call AUTOTRANS(?,?,?)} "; //璋冪敤瀛樺偍杩囩▼ List<Map<String, Object>> resultList = jdbcTemplate.execute( //瀹氫箟浼犲叆鍙傛暟锛岃繑鍥瀞tatement (connection)->{ CallableStatement statement = connection.prepareCall(sql); 銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€statement.setString(1,param.get("xzCode").toString()); 銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€statement.setString(2,param.get("days").toString()); 銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€statement.setString(3,param.get("industryCode").toString()); return statement; }, //鎵ц瀛樺偍杩囩▼锛屾嬁鍒扮粨鏋滈泦锛屽鐞嗙粨鏋滈泦銆傚洜涓鸿繖閲宭ambda琛ㄨ揪寮忓鏋滀笉璁剧疆鍙傛暟绫诲瀷浼氬鑷撮噸澶嶏紝灏辫缃簡鍙傛暟绫诲瀷 (CallableStatement callableStatement) -> { List<Map<String,Object>> resultListParam =new ArrayList<>(); callableStatement.execute(); ResultSet resultSet = callableStatement.getResultSet(); while (resultSet.next()){ Map<String,Object> result = new HashMap<>();
銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€result.put("xzCode",resultSet.getString("XZ_CODE"));
銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€result.put("unitCode",resultSet.getString("UNIT_CODE"));
銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€result.put("unitName",resultSet.getString("UNIT_NAME"));
銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€result.put("receiveTime",resultSet.getString("RECEIVE_TIME"));
銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€result.put("restoreTime",resultSet.getString("RESTORE_TIME"));
銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€result.put("selectDate",resultSet.getDate("SELECT_DATE")); resultListParam.add(result); } return resultListParam; }); return resultList; }
鍒版缁撴潫锛屾湰娆℃煡璇紭鍖栧畬鎴愶紝鍩烘湰杈惧埌鐩爣瑕佹眰銆?/p>
以上是关于SqlServer楂樼骇鐗规€?-瀛樺偍杩囩▼的主要内容,如果未能解决你的问题,请参考以下文章
闃舵1 璇█鍩虹+楂樼骇_1-3-Java璇█楂樼骇_02-缁ф壙涓庡鎬乢绗?鑺?鎶借薄绫籣19-鍙戠孩鍖呮渚媉瀹炵幇
鈥滃垎甯冨紡瀛樺偍鎶€鏈€濇垨灏嗘垚涓轰腑鍥界鎶€鑵鹃鐨勪笅涓€涓敮鐐癸紝IPFS/FIL鍗冲皢杩庢潵澶х垎鍙戯紒