0

这会导致ORA-00923: From keyword not found错误:

create or replace function gr_pay_hrly (p_wage_rate IN Number, 
                                        p_hrs_worked In number)
Return Number IS

  t_wage pay_history.wage_rate%type;
  t_hours pay_history.hrs_worked%type;
  t_gross_pay number(10,2);

BEGIN

  select wage_rate into t_wage, 
         hrs_worked into t_hours
    from pay_history
   where wage_rate = p_wage_rate
     and hrs_worked = p_hrs_worked;

  IF t_hours >= 40 THEN
    t_gross_pay := (((t_hours - 40) * t_wage) * 1.5);
  ELSE
    t_gross_pay := t_hours * t_wage;
  END IF;

  RETURN t_gross_pay;

  END;
  /
4

1 回答 1

2

您的问题是该INTO子句-它仅在语句中声明一次:

SELECT ph.wage_rate,
       ph.hrs_worked
  INTO t_wage, t_hours
  FROM PAY_HISTORY ph
 WHERE ph.wage_rate = p_wage_rate
   AND ph.hrs_worked = p_hrs_worked;

变量的填充基于 SELECT 子句中声明的列的顺序。

完全重写:

如果你从 40 中减去 40hours_worked也是 40,你只是乘以零。而且您想将直接时间支出添加到加班费中...

CREATE OR REPLACE FUNCTION gr_pay_hrly (p_wage_rate IN NUMBER, 
                                        p_hrs_worked IN NUMBER)
RETURN NUMBER IS

  t_gross_pay NUMBER(10,2);

BEGIN

  SELECT CASE 
           WHEN ph.hrs_worked > 40 THEN ((ph.hrs_worked - (ph.hrs_worked - 40)) * ph.wage_rate) + (ph.hrs_worked - 40) * ph.wage_rate * 1.5
           WHEN ph.hrs_worked <= 40 THEN ph.hrs_worked * ph.wage_rate
           ELSE 0
         END
    INTO t_gross_pay
    FROM PAY_HISTORY ph
   WHERE ph.wage_rate = p_wage_rate
     AND ph.hrs_worked = p_hrs_worked;

  RETURN t_gross_pay;

END;
于 2011-05-04T01:16:01.807 回答