Display PL/SQL function warnings

半腔热情 提交于 2020-01-13 20:40:29

问题


I have the following function:

CREATE OR REPLACE Function pode_levar( pedidos NUMBER, viagens  NUMBER)
   RETURN NUMBER
IS
x NUMBER:=0;
y NUMBER:=0;
TRUE NUMBER:=0;
BEGIN

BEGIN
    Select id_pedido into x
    from pedido
    where id_pedido = pedidos;
    EXCEPTION 
    WHEN NO_DATA FOUND THEN 
    RAISE_APPLICAITON_ERROR(-20305,'PEDIDO TRANSPORTE ENIXISTENTE');
END;

BEGIN
    select lim_vei_vol - volume_total_viagem(viagens)  into y
    from v viagem , ve veiculo
    where v.id_viagem = ve.id_viagem
    and id_viagem = viagens;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    TRUE:=0;
    RAISE_APPLICATION_ERROR(-20304,'Viagem Enixistente');
    RETURN(TRUE);
END;

BEGIN 
    IF y <> 0 
    TRUE := 1;
    RETURN(TRUE);
    ELSE
    TRUE := 0;
    RETURN(TRUE);
    ENDIF;

END;

END;

The function compiles with one warning, how can I see it? show errors does not work

This is for school,


回答1:


You should use SQL* Plus and set

ALTER SESSION SET PLSQL_WARNINGS = 'ENABLE:ALL';

before you create your function. This setting will show you any warnings by using

SHOW ERRORS;

Read: http://docs.oracle.com/cd/B28359_01/server.111/b28320/initparams186.htm#REFRN10249




回答2:


Not sure why you aren't seeing this with show errors - possibly a buggy old version. You can try this instead:

select * from user_errors;

But you have your aliases declared the wrong way around and not always used when referencing the shared column:

from v viagem , ve veiculo
where v.id_viagem = ve.id_viagem
and id_viagem = viagens;

should be:

from viagem v, veiculo ve
where v.id_viagem = ve.id_viagem

    and v.id_viagem = viagens;

Or even:

from viagem v
join veiculo ve
on v.id_viagem = ve.id_viagem
where v.id_viagem = viagens;

There may be are other problems too as Ben pointed out in comments, and you haven't shown any table definitions, but that wasn't really the question.

If you had warnings turned on too (which is in the preferences in SQL Developer) I'd guess it would point out that the return after the raise in the second block is unreachable. You can't do both.



来源:https://stackoverflow.com/questions/17013487/display-pl-sql-function-warnings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!