sql >> Base de Datos >  >> RDS >> Oracle

Sentencias ACCEPT de Oracle SQL*Plus

Puede hacerlo habilitando la verificación de errores y luego generando un error.

ACCEPT p_cname PROMPT 'Enter Customer Name: '

WHENEVER SQLERROR EXIT SUCCESS ROLLBACK;

DECLARE
     v_count  INTEGER;
BEGIN
     SELECT COUNT(*) INTO v_count
            FROM customer
     WHERE cname = '&p_cname';

     IF v_count > 0 THEN
            raise_application_error( -20100, 'Customer already exists' );
     END IF;

END;
/

-- Issue a new WHENEVER statement here if you want different error-handling for
-- the rest of the script

-- Other ACCEPT statements if a match was not found.

En el WHENEVER comando, el SUCCESS La palabra clave significa que SQLPlus devolverá un código de éxito al shell desde el que se invocó. También puede usar FAILURE para devolver un código de error genérico u otras opciones para devolver valores específicos.