有效/无效参数传递

时间:2018-04-10 13:32:05

标签: stored-procedures plsql sqlplus

有人可以解释一下哪些登录确实适用于参数传递,其中>=符号为varchar列?

代码

CREATE OR REPLACE PROCEDURE add_dept ( p_name

departments.department_name%TYPE DEFAULT .unknown ., p_loc

departments.location_id%TYPE DEFAULT 1700) IS BEGIN INSERT INTO

departments(department_id, department_name, loclation_id)

VALUES(dept_seq.NEXTVAL,p_name, p_loc); END add_dept; / You created the add_dept procedure above, and you now invoke the procedure in SQL *Plus.

问题

哪四个是有效的调用? (选择四个)

一个。执行add_dept(p_loc => 2500)

B中。执行add_dept('Education',2500)

℃。执行add_dept('2500',p_loc => 2500)

d。 EXECUTE add_dept(p_name =>'Education',2500)

电子。执行add_dept(p_loc => 2500,p_name =>'教育')

1 个答案:

答案 0 :(得分:0)

考虑到测试真的很容易,我不知道你为什么不自己做。

我修复了你已经犯过的错误(.unknown.会是什么?点?)并删除了不必要的程序部分,结果如下。 Oracle回答了您的问题(即无效的过程调用出了什么问题)。

SQL> create or replace procedure add_dept
  2    (p_name dept.dname%type default 'unknown',
  3     p_loc  dept.deptno%type default 99)
  4  is
  5  begin
  6    null;
  7  end;
  8  /

Procedure created.

SQL> -- A
SQL> EXECUTE add_dept(p_loc=>2500);

PL/SQL procedure successfully completed.

SQL>
SQL> -- B
SQL> EXECUTE add_dept('Education', 2500);

PL/SQL procedure successfully completed.

SQL>
SQL> -- C
SQL> EXECUTE add_dept('2500', p_loc =>2500);

PL/SQL procedure successfully completed.

SQL>
SQL> -- D
SQL> EXECUTE add_dept(p_name=>'Education', 2500);
BEGIN add_dept(p_name=>'Education', 2500); END;

                                    *
ERROR at line 1:
ORA-06550: line 1, column 37:
PLS-00312: a positional parameter association may not follow a named association
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored


SQL>
SQL> -- E
SQL> EXECUTE add_dept(p_loc=>2500, p_name=>'Education');

PL/SQL procedure successfully completed.

SQL>