在PL / SQL过程中显示消息框

时间:2014-09-26 04:05:02

标签: sql stored-procedures

我有以下程序,

CREATE OR REPLACE PROCEDURE Add_Shipment_Method(
shipment_method_id_p IN NUMBER,
shipment_description_p IN VARCHAR2)
AS
BEGIN
INSERT INTO shipment_method 
    SELECT shipment_method_id_p, shipment_description_p
    FROM dual
    WHERE NOT EXISTS (SELECT * FROM SHIPMENT_METHOD WHERE SHIPMENT_METHOD_ID = shipment_method_id_p AND SHIPMENT_DESCRIPTION = shipment_description_p);
COMMIT;
EXCEPTION WHEN
OTHERS THEN
ROLLBACK;
END;
/

该过程通常允许在行不存在时将新的装运方法添加到表shipment_method中。 我想修改它并在主键' shipment_method_id'时显示一个消息框。确实存在,并允许在行不存在时写入行。 有什么建议吗?

1 个答案:

答案 0 :(得分:2)

您无法从存储过程中显示MessageBoxes。

现在检查INSERT是否已在输出窗口中插入任何行并显示消息。

使用

BEGIN
     INSERT INTO shipment_method 
     SELECT shipment_method_id_p, shipment_description_p
     FROM dual
     WHERE NOT EXISTS (SELECT * FROM SHIPMENT_METHOD 
                       WHERE SHIPMENT_METHOD_ID = shipment_method_id_p
                       AND SHIPMENT_DESCRIPTION = shipment_description_p);

     IF SQL%ROWCOUNT = 0 THEN           --if this is true, then no records were added.
      DBMS_OUTPUT.PUT_LINE( 'Not records added');     --writes this message

COMMIT;

注意:INSERT语句和“IF SQL%ROWCOUNT = 0”验证之间不应该有任何其他语句。 SQL%ROWCOUNT反映了最近执行的语句。