建表
CREATE SET TABLE WAPBI.MMS_BANDWIDTH ,FALLBACK , NO BEFORE JOURNAL, NO AFTER JOURNAL, CHECKSUM = DEFAULT ( id INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1 INCREMENT BY 1 MINVALUE -2147483647 MAXVALUE 2147483647 NO CYCLE), area_code VARCHAR(100) CHARACTER SET LATIN NOT CASESPECIFIC, area_name VARCHAR(100) CHARACTER SET LATIN NOT CASESPECIFIC, arrive_custom DECIMAL(18,2) TITLE '到达客户数', net_growth DECIMAL(18,2) TITLE '净增客户数', income DECIMAL(18,2) TITLE '收入', complete_progress DECIMAL(18,2) TITLE '完成进度', create_at TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP(0)) UNIQUE PRIMARY INDEX ( id );
1
= |
等于 |
<> |
不等于 |
[NOT] BETWEEN <a> |
介于a和b之间或不介于a和b之间 |
[NOT] IN |
属于或不属于某个集合 |
IS [NOT] NULL |
一个数值是空值或不是空值 |
[NOT] EXISTS |
一个查询至少返回一行或不返回任何行 |
CREATE PROCEDURE test_value (IN p1 INTEGER, OUT pmsg CHAR(30)) BEGIN IF p1 > 0 THEN SET pmsg = 'Positive value'; ELSEIF p1 = 0 THEN SET pmsg = 'Zero Value'; ELSE SET pmsg = 'Negative Value'; END IF; END;
SET、 END IF 和 END 语句都以分号";"结束。
执行存储过程test_value。
CALL test_value(3, pmsg);
REPLACE PROCEDURE handler_2 (IN deptnum INTEGER, OUT lastnm CHAR(20)) BEGIN DECLARE EXIT HANDLER FOR SQLSTATE '21000', SQLSTATE '42000' BEGIN PRINT 'EXCEPTION 21000 OCCURRED'; INSERT INTO error_log VALUES (:SQLCODE, :SQLSTATE, CURRENT_TIME); END; DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN PRINT 'WARNING - EXCEPTION CONDITION OCCURRED'; INSERT INTO error_log VALUES (:SQLCODE, :SQLSTATE, CURRENT_TIME); END; SELECT last_name INTO :lastnm FROM employee WHERE department_number = :deptnum; PRINT 'Successful Completion'; END;
EXIT 处理 - 在执行了例外处理的动作后,过程终止。
CONTINUE 处理 - 在执行了例外处理的动作后,过程从例外语句的下一条
处理例外时,可以使用两个保留字:
SQLSTATE - 返回特定的错误码。
SQLEXCEPTION - 告诉处理程序处理所有的例外。
例
BT; INSERT row1; (txn #1) INSERT row2; COMMIT WORK; ET;