我的程序sql有什么问题

时间:2018-05-29 19:26:44

标签: oracle plsql

我的程序如下;

CREATE OR REPLACE PROCEDURE updateWEEK_SALES_REPORTS

(   p_start IN WEEK_SALES_REPORT.StartDate%TYPE,
     p_end IN weekly_sales_report.EndDate%TYPE)

IS

BEGIN


 UPDATE WEEK_SALES_REPORT SET ComAmount = SaleAmount*ComRate WHERE (StartDate-EndDate) = (p_start-p_end);

 SELECT concat('The commission amount for report ',ReportID,' has been updated to ',ComAmount,' dollars,
 which is',ComRate,'% of the total sale amount of ',SaleAmount,' dollars.')

 COMMIT;


END;

/

但显示错误

  

7/3 PL / SQL:忽略SQL语句

     

7/10 PL / SQL:ORA-00909:参数数量无效

2 个答案:

答案 0 :(得分:0)

我很确定您正在尝试将消息打印到控制台。为此,您需要dbms_output

CREATE OR REPLACE PROCEDURE updateWEEK_SALES_REPORTS
(   p_start IN date,
     p_end IN date)
IS

BEGIN

 UPDATE WEEK_SALES_REPORT SET ComAmount = SaleAmount*ComRate WHERE (StartDate-EndDate) = (p_start-p_end);

 dbms_output.put_line('The commission amount for report ' || ReportID || ' has been updated to ' || ComAmount || ' dollars,
 which is' || ComRate || '% of the total sale amount of ' || SaleAmount || ' dollars.');

 COMMIT;

END;

答案 1 :(得分:-1)

是的,@ Jacob H是对的,CONCAT只有2个参数。相反,请使用||,比您的版本更加丑陋:

SELECT 'The commission amount for report ' || ReportID ||
       ' has been updated to ' || ComAmount || ' dollars, which is' ||
        ComRate || '% of the total sale amount of ' || SaleAmount ||
       ' dollars.' ...

此外,您需要SELECT INTO一些变量,例如f.i。

SELECT ... INTO myvar FROM DUAL;