【问题标题】:how to create a function to print the sum of all salaries of employees, maximum salary and minimum salary from a table using pl/sql function如何创建一个函数来使用pl/sql函数从表中打印员工所有薪水的总和、最高薪水和最低薪水
【发布时间】:2021-04-29 12:17:52
【问题描述】:

下面是我用来将值存储在 varray 中并最终返回 varray 的代码。但是我在第 12 行遇到一个错误,说“Line/Col:12/8 PLS-00103:在预期以下之一时遇到符号“EMP_TYPE”: := 。 (@%;" 我需要做哪些改进?

create or replace type emp_type AS VARRAY(25) OF VARCHAR(10);
/

create or replace function emp_sal
return emp_type
is 
  emp emp_type := emp_type();
  l_salary number(10);
  maxim number(10);
  minim number(10);
BEGIN
   SELECT sum(salary) INTO l_salary FROM Employee8_43;
   SELECT max(salary) INTO maxim FROM Employee8_43;
   SELECT min(salary) INTO minim FROM Employee8_43;
   emp emp_type := emp_type(l_salary,maxim,minim);
  return emp;
END;

【问题讨论】:

    标签: oracle plsql varray


    【解决方案1】:

    你已经很接近了;很遗憾您没有阅读 Oracle 告诉您的内容。

    行/列:12/8 PLS-00103:在预期时遇到符号“EMP_TYPE”......

    它逐字地告诉了您需要知道的所有内容:行号、列号,以及它找到但预期的其他内容。

    这个:

    emp emp_type := emp_type(l_salary,maxim,minim);
    

    应该是

    emp          := emp_type(l_salary,maxim,minim);
    

    所以:

    SQL> create or replace type emp_type as varray(25) of varchar(10);
      2  /
    
    Type created.
    
    SQL> create or replace function emp_sal
      2  return emp_type
      3  is
      4    emp emp_type := emp_type();
      5    l_salary number(10);
      6    maxim number(10);
      7    minim number(10);
      8  begin
      9     select sum(salary) into l_salary from employee8_43;
     10     select max(salary) into maxim from employee8_43;
     11     select min(salary) into minim from employee8_43;
     12     emp := emp_type(l_salary,maxim,minim);                --> this is line #12
     13    return emp;
     14  end;
     15  /
    
    Function created.
    
    SQL> select emp_sal from dual;
    
    EMP_SAL
    -------------------------------------------------------------------------
    EMP_TYPE('29025', '5000', '800')
    
    SQL>
    

    【讨论】:

    • 这可以缩短为单选。 " select sum(salary),max(salary), min(salary) into l_salary,maxim,minim from employee8_43;"
    猜你喜欢
    • 2022-01-07
    • 2020-12-20
    • 1970-01-01
    • 1970-01-01
    • 2015-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-09
    相关资源
    最近更新 更多