回答1:
灞曞紑鍏ㄩ儴
鎵ц鎰忔€濓紝濡傛灉浣犲垱寤轰簡涓€涓瓨鍌ㄨ繃绋嬪悕涓篋emo,鑰屼笖閲岄潰灏辨槸绠€鍗曟煡璇?br />create proc Demoasselect * from 琛ㄥ悕鎵ц涓婇潰璇彞锛岀劧鍚庡氨鍒涘缓浜咲emo濡傛灉浣犳兂鎵цDemo锛屽氨鐢╡xec Demo灏辩洿鎺ユ墽琛屼簡select璇彞锛岀浉褰撲簬缂栫▼璇█涓殑璋冪敤鍑芥暟
回答2:
灞曞紑鍏ㄩ儴
鍙互閫氳繃SIGNAL鍜孯ESIGNAL鏉ユ樉绀虹殑瑙﹀彂涓€涓寚瀹氱殑SQLSTATE.浣跨敤SIGNAL鍜孯ESIGNAL鐨凪ESSAGE_TEXT鏉ヨ瀹氫即闅廠QLSTATE鐨勬枃鏈俊鎭紙鍙互鐞嗚В涓洪敊璇俊鎭級銆?br />鍦ㄤ笅闈㈢殑渚嬪瓙涓紝鍦⊿QL procedure瀹氫箟浜嗕竴涓鐞嗚嚜瀹氫箟SQLSTATE 72822鐨勬潯浠跺鐞嗗櫒(condition handler)銆傚綋鎵цSIGNAL 72822璇彞鏃讹紝DB2璋冪敤鏉′欢澶勭悊鍣?Condition Handler),璇ユ潯浠跺鐞嗗櫒棣栧厛閫氳繃IF璇彞娴嬭瘯鍙橀噺var锛屽鏋渧ar绛変簬OK,澶勭悊鍣ㄩ噸鏂板畾涔塖QLSTATE涓?2623锛屽苟涓旀寚瀹氫簡涓€涓猼ext锛屽鏋渧ar涓嶇瓑浜嶰K鏃讹紝澶勭悊鍣ㄩ噸鏂板畾涔塖QLSTATE涓?2319,鍚屾椂鎸囧畾涓€涓猼ext銆?br />DECLARE EXIT HANDLER FOR SQLSTATE '72822' BEGIN IF ( var = 'OK' ) RESIGNAL SQLSTATE '72623' SET MESSAGE_TEXT = 'Got SQLSTATE 72822'; ELSE RESIGNAL SQLSTATE '72319' SET MESSAGE_TEXT = var; END; SIGNAL SQLSTATE '72822';
回答3:
灞曞紑鍏ㄩ儴
sql 涓璭xec 鐨勫惈涔夊拰鐢ㄦ硶 EXEC 濂藉儚鏄? EXECUTE 鐨勭畝鍐欍€?br />鍙互鐢ㄦ潵鎵ц涓€涓瓨鍌ㄨ繃绋嬨€?br />1> CREATE PROCEDURE HelloWorld AS2> DECLARE3> @testvalue1 AS VARCHAR(20),4> @testvalue2 AS VARCHAR(20);5> BEGIN