Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.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
Oracle plsql过程未在此范围内声明错误_Oracle_Plsql_Scope - Fatal编程技术网

Oracle plsql过程未在此范围内声明错误

Oracle plsql过程未在此范围内声明错误,oracle,plsql,scope,Oracle,Plsql,Scope,大家好,我正在为一个赋值做一个基本的PLSQL函数。代码如下 DECLARE e_child_record_found exception; PRAGMA EXCEPTION_INIT(e_child_record_found, -02292); v_afd number; function afdeling_van(p_mnr in MEDEWERKERS.AFD%type) RETURN MEDEWERKERS.AFD%type IS DEPNR MEDE

大家好,我正在为一个赋值做一个基本的PLSQL函数。代码如下

DECLARE
e_child_record_found  exception;
    PRAGMA EXCEPTION_INIT(e_child_record_found, -02292);
v_afd number;

function afdeling_van(p_mnr in MEDEWERKERS.AFD%type)
    RETURN MEDEWERKERS.AFD%type
    IS
    DEPNR MEDEWERKERS.AFD%type;
    BEGIN
    SELECT AFD into DEPNR FROM MEDEWERKERS WHERE AFD = p_mnr;
end afdeling_van;

procedure ontsla_med(p_mnr in MEDEWERKERS.AFD%type)
    IS 
    BEGIN
    DELETE FROM UITVOERINGEN WHERE DOCENT = p_mnr;
    DELETE FROM INSCHRIJVINGEN WHERE CURSIST = p_mnr;
    DELETE FROM MEDEWERKERS WHERE MNR = p_mnr;
end ontsla_med;

procedure neem_med_aan(p_naam in MEDEWERKERS.NAAM%type,
                       p_voorl in MEDEWERKERS.VOORL%type,
                       p_gbdatum in MEDEWERKERS.GBDATUM%type,
                       p_maandsal in MEDEWERKERS.MAANDSAL%type,
                       p_afd in MEDEWERKERS.AFD%type,
                       p_functie in MEDEWEKERS.FUNCTIE%type DEFAULT('NULL'),
                       p_chef in MEDEWERKERS.CHEF%type DEFAULT('NULL'))
IS    
    v_mnr number;
BEGIN
    SELECT max(MNR)into v_mnr FROM MEDEWERKERS;
    v_mnr := v_mnr + 1;
    INSERT INTO MEDEWERKERS(MNR, naam, voorl, functie, chef, gbdatum, maandsal, afd) VALUES(v_mnr,p_naam, p_voorl, p_gbdatum, p_maandsal, p_afd, p_functie, p_chef);
end neem_med_aan;

BEGIN
    ontsla_med(p_mnr => 7900);
    v_afd := afdeling_van(p_mnr => 7369);
    dbms_output.put_line(v_afd);
    neem_med_aan(p_naam => 'Vermeulen',
                 p_voorl => 't',
                 p_gbdatum => '15-02-1961',
                 p_maandsal => 2000,
                 p_afd => 10);
    neem_med_aan(p_naam => 'derks',
                 p_voorl => 'm',
                 p_gbdatum => '05-aug-61',
                 p_maandsal => 2500,
                 p_afd => 30,
                 p_functie => 'Verkoper',
                 p_chef => 7698);
    neem_med_aan(p_naam => 'Martens',
                 p_voorl => 'i',
                 p_gbdatum => '11-05-1956',
                 p_maandsal => 2100,
                 p_afd => 20,
                 p_functie => 'Trainer');
    neem_med_aan(p_naam => 'Verbeek',
                 p_voorl => 'j',
                 p_gbdatum => '12-09-1950',
                 p_maandsal => 2600,
                 p_afd => 30,
                 p_functie => 'verkoper',
                 p_chef => 7782);
exception
when e_child_record_found then --ORA-melding, zelf gedefinieerd
    raise_application_error(-20000,'De medewerker is nog verbonden aan andere gegevens');
when no_data_found then --voorgedefinieerd door Oracle
    raise_application_error(-20000,'Deze medewerker bestaat niet');
end;
现在我得到以下错误

Error report -
ORA-06550: line 27, column 41:
PLS-00201: identifier 'MEDEWEKERS.FUNCTIE' must be declared
ORA-06550: line 22, column 5:
PL/SQL: Item ignored
ORA-06550: line 41, column 9:
PLS-00313: 'NEEM_MED_AAN' not declared in this scope
ORA-06550: line 41, column 9:
PL/SQL: Statement ignored
ORA-06550: line 46, column 9:
PLS-00313: 'NEEM_MED_AAN' not declared in this scope
ORA-06550: line 46, column 9:
PL/SQL: Statement ignored
ORA-06550: line 53, column 9:
PLS-00313: 'NEEM_MED_AAN' not declared in this scope
ORA-06550: line 53, column 9:
PL/SQL: Statement ignored
ORA-06550: line 59, column 9:
PLS-00313: 'NEEM_MED_AAN' not declared in this scope
ORA-06550: line 59, column 9:
PL/SQL: Statement ignored
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:

declare中的过程和函数已经存在,所以我只是在其中添加了代码。这和里面的代码有关吗?或者是程序设置有问题或者类似的问题。希望得到帮助,提前谢谢。

此:
p\u MEDEWEKERS中的functie。functie%type DEFAULT('NULL'),
据报告是错误的;表
MEDEWEKERS
似乎不包含名为
FUNCTIE
的列

其余的错误取决于此-一旦你修复了它,另一个错误将自动消失

如果我可以的话,还有一些反对意见:

函数
afdeling\u van
一调用就会失败,因为它没有
RETURN
子句

程序
neem\u med\u aan
在多用户环境中无法正常工作;许多用户可以同时调用它,所有用户都将获得相同的
MAX(mnr)+1
值,这可能不是您想要的。切换到序列。或者,如果您坚持您的选择,您应该创建一个自治事务函数,该函数将最大值存储到表中,并在每次获取时提交。再次-切换到序列

除此之外,您的代码看起来还可以。sqldeveloper将其正确格式化,这意味着没有明显的错误

此外,一个非常简化的版本编译并执行OK:

SQL> declare
  2    v_afd number;
  3
  4    function afdeling_Van return number is
  5    begin
  6      return 1;
  7    end;
  8
  9    procedure neem_med_aan is
 10    begin
 11      null;
 12    end;
 13
 14  begin
 15    v_afd := afdeling_Van;
 16
 17    neem_med_aan;
 18  exception
 19    when others then null;
 20  end;
 21  /

PL/SQL procedure successfully completed.

SQL>

所以-修复MEDEWEKERS.FUNCTIE列问题,您应该会没事的。

此:
p\u MEDEWEKERS.FUNCTIE%类型默认值('NULL'),
报告错误;表
MEDEWEKERS
似乎不包含名为
FUNCTIE
的列

其余的错误取决于此-一旦你修复了它,另一个错误将自动消失

如果我可以的话,还有一些反对意见:

函数
afdeling\u van
一调用就会失败,因为它没有
RETURN
子句

程序
neem\u med\u aan
在多用户环境中无法正常工作;许多用户可以同时调用它,所有用户都将获得相同的
MAX(mnr)+1
值,这可能不是您想要的。切换到序列。或者,如果您坚持您的选择,您应该创建一个自治事务函数,该函数将最大值存储到表中,并在每次获取时提交。再次-切换到序列

除此之外,您的代码看起来还可以。sqldeveloper将其正确格式化,这意味着没有明显的错误

此外,一个非常简化的版本编译并执行OK:

SQL> declare
  2    v_afd number;
  3
  4    function afdeling_Van return number is
  5    begin
  6      return 1;
  7    end;
  8
  9    procedure neem_med_aan is
 10    begin
 11      null;
 12    end;
 13
 14  begin
 15    v_afd := afdeling_Van;
 16
 17    neem_med_aan;
 18  exception
 19    when others then null;
 20  end;
 21  /

PL/SQL procedure successfully completed.

SQL>

因此-修复
MEDEWEKERS.FUNCTIE
列问题,您应该会没事。

neem\u med\u aan的定义目前为:

procedure neem_med_aan(p_naam in MEDEWERKERS.NAAM%type,
                       p_voorl in MEDEWERKERS.VOORL%type,
                       p_gbdatum in MEDEWERKERS.GBDATUM%type,
                       p_maandsal in MEDEWERKERS.MAANDSAL%type,
                       p_afd in MEDEWERKERS.AFD%type,
                       p_functie in MEDEWEKERS.FUNCTIE%type DEFAULT('NULL'),
                       p_chef in MEDEWERKERS.CHEF%type DEFAULT('NULL'))
似乎在第六行,
MEDEWERKERS
应更改为
MEDEWERKERS


祝你好运。

尼姆医学院的定义目前为:

procedure neem_med_aan(p_naam in MEDEWERKERS.NAAM%type,
                       p_voorl in MEDEWERKERS.VOORL%type,
                       p_gbdatum in MEDEWERKERS.GBDATUM%type,
                       p_maandsal in MEDEWERKERS.MAANDSAL%type,
                       p_afd in MEDEWERKERS.AFD%type,
                       p_functie in MEDEWEKERS.FUNCTIE%type DEFAULT('NULL'),
                       p_chef in MEDEWERKERS.CHEF%type DEFAULT('NULL'))
似乎在第六行,
MEDEWERKERS
应更改为
MEDEWERKERS

祝你好运