I have the following stored procedure:
create or replace PROCEDURE A2CountSkus
(v_count out Number )
AS
BEGIN
SELECT count(*)
INTO v_count
FROM a2sku;
EXCEPTION
When Others THEN
RAISE;
END A2CountSkus;
When I run this script.
SET SERVEROUTPUT ON
BEGIN
DBMS_OUTPUT.PUT_LINE('SKU COUNT ' || A2CountSkus);
END;
/
Instead of output being printed it gives an error.
First, normally, if you have a named PL/SQL block whose only purpose is to return a value, you would declare a function rather than a procedure. If you had declared
A2CountSkusas a function that returned a number, the syntax that you want to use would work.Second, you do not want that exception clause– it does nothing useful. It should be eliminated.
Third, if you do want the block to be a procedure, the caller would need to declare a local variable that can be passed in to the procedure and then print the value in the local variable.
If you want to declare a function
If you are sure that you want to declare a procedure, the caller would need to be something like