Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 检查是否授权的程序_Sql_Oracle_Stored Procedures_Plsql - Fatal编程技术网

Sql 检查是否授权的程序

Sql 检查是否授权的程序,sql,oracle,stored-procedures,plsql,Sql,Oracle,Stored Procedures,Plsql,所以我有这个函数: create or replace function get_authorization( p_pnr in bankcustomer.pnr%type, p_knr in account.cnr%type) return number as v_authorization bankcustomer.pnr%type; begin select count(*) into v_authorization from bankcustomer,account where

所以我有这个函数:

create or replace function get_authorization( 
p_pnr in bankcustomer.pnr%type, 
p_knr in account.cnr%type) 
return number
as
v_authorization bankcustomer.pnr%type; 
begin
select count(*)
into v_authorization
from bankcustomer,account
where pnr = p_pnr 
and cnr = p_cnr;
return v_authorization; 
exception
when no_data_found then
return -1;
end;
如果允许,则返回1或0。我需要执行一个过程,在一个名为draw的表中添加一行,该过程需要调用get_authorization来检查客户是否被允许。这就是我到目前为止所做的:

create or replace procedure do_withdraw(
p_pnr in withdraw.pnr%type,
p_belopp in withdraw.belopp%type)
as
declare
authorization exception;
begin
insert into uttag(pnr,amount)
values((select pnr from account),p_amount); /*pnr is foreign key in withdraw*/
if user not in (select get_amount(p_pnr) from dual) then
raise authorization; 
end if; 
exception  
when authorization then
raise_application_error(-20007,'Unauthorized!');
commit;
end;

我收到很多错误消息,特别是关于declare的消息。我真的无法理解这一点:

您的代码几乎没有问题-

create or replace procedure do_withdraw(
                            p_pnr    in withdraw.pnr%type,
                            p_belopp in withdraw.belopp%type)
as
-- declare        -- Declare keyword is not used in procedure
authorization exception;
begin
     insert into uttag(pnr,amount)
     values((select pnr from account),       -- This might return multiple rows, So you have to add a where clause in this query.
            p_amount); /*pnr is foreign key in withdraw*/
     if user <> get_authorization(p_pnr) then  -- You are checking current user with amount which should be corrected.
        raise authorization; 
     end if;
     commit;        -- Commit should be last sattement of procedure
exception  
         when authorization then
              raise_application_error(-20007,'Unauthorized!');
         Rollback;  -- In exception you should use Rollabck instead of Commit;
end;

所以我试过你说的,我想我知道你的意思:

create or replace procedure do_withdraw(
                            p_pnr    in withdraw.pnr%type,
                            p_amount in withdraw.amount%type)
as
-- declare        -- Declare keyword is not used in procedure
authorization exception;
begin
     insert into withdraw(pnr,amount)
     values((select pnr from account where pnr = p_pnr),       -- This might return multiple rows, So you have to add a where clause in this query.
            p_amount); /*pnr is foreign key in withdraw*/
     if user not in (select get_authorization(p_pnr)) then  -- You are checking current user with amount which should be corrected.
        raise authorization; 
     end if;
     commit;        -- Commit should be last sattement of procedure
exception  
         when authorization then
              raise_application_error(-20007,'Unauthorized!');
         Rollback;  -- In exception you should use Rollabck instead of Commit;
end;

现在我得到错误:Line/Col:11/51 PLS-00103:在预期以下情况之一时遇到符号:,*%&-+/

对不起,先生,我的错。get amount应该是get_uuAuthorization。在您的代码中更改它,然后尝试上面代码中我建议的所有其他更改。如果您仍然面临任何问题,请告诉我们。对不起,先生,您看到我上面的帖子了吗?@HugoNilsson,请现在再试。谢谢!它起作用了