Oracle iSQL 函数问题
Oracle iSQL function issue
编辑:我现在已经更改了我的代码。
我的函数有问题,我在创建函数时没有出错,我可以运行我创建的函数的基本版本没有问题,但是当我调用整个函数时,我得到空白行.
这个版本有效
SELECT SUM(t.estimated_hours*c.hrly_charge_rate)
FROM task t, task_history ta, task_type tt, charge_grade c
WHERE t.task_id = ta.task_id
AND tt.task_type_no = t.task_type_no
AND c.grade_no = tt.grade_no
AND ta.task_history_id = 1;
但这不起作用行只是空白???
SHOW ERRORS
CREATE OR REPLACE FUNCTION total_cost (tn task.task_id%TYPE)
RETURN NUMBER IS
cost_var NUMBER;
BEGIN
SELECT SUM(t.estimated_hours*c.hrly_charge_rate)
INTO cost_var
FROM task t, task_history ta, task_type tt, charge_grade c
WHERE t.task_id = ta.task_id
AND tt.task_type_no = t.task_type_no
AND c.grade_no = tt.grade_no
AND t.task_type_no = tn
AND ta.task_history_id = 1;
RETURN cost_var;
END;
/
-- my call select statment
SELECT total_cost(t.task_id) AS task_cost
FROM task t;
它运行没有错误,但行都是空白的?
请告诉我我做错了什么。
这是实体关系图 (ERD)
和问题
/*
(b) 在估计日期使用给定任务的标准费率计算和 return 总成本
(即在对估计小时数进行任何进一步更改之前。
代码脚本,包括 SELECT 语句来测试每个函数 + 每个测试语句输出的“屏幕截图”。 */
您似乎在使用 HAVING
来应用简单的 WHERE
条件。同样的例子:
SQL> create table groupTable (id number, num number);
Table created.
SQL> select sum(num)
2 from groupTable
3 where id = 1;
SUM(NUM)
----------
SQL> select sum(num)
2 from groupTable
3 having id = 1;
having id = 1
*
ERROR at line 3:
ORA-00979: not a GROUP BY expression
SQL> select sum(num)
2 from groupTable
3 group by id
4 having id = 1;
no rows selected
SQL> select sum(num)
2 from groupTable
3 group by id
4 having sum(num) = 1;
no rows selected
SQL> select sum(num)
2 from groupTable
3 where sum(num) = 1
4 group by id;
where sum(num) = 1
*
ERROR at line 3:
ORA-00934: group function is not allowed here
SQL>
编辑:我现在已经更改了我的代码。
我的函数有问题,我在创建函数时没有出错,我可以运行我创建的函数的基本版本没有问题,但是当我调用整个函数时,我得到空白行.
这个版本有效
SELECT SUM(t.estimated_hours*c.hrly_charge_rate)
FROM task t, task_history ta, task_type tt, charge_grade c
WHERE t.task_id = ta.task_id
AND tt.task_type_no = t.task_type_no
AND c.grade_no = tt.grade_no
AND ta.task_history_id = 1;
但这不起作用行只是空白???
SHOW ERRORS
CREATE OR REPLACE FUNCTION total_cost (tn task.task_id%TYPE)
RETURN NUMBER IS
cost_var NUMBER;
BEGIN
SELECT SUM(t.estimated_hours*c.hrly_charge_rate)
INTO cost_var
FROM task t, task_history ta, task_type tt, charge_grade c
WHERE t.task_id = ta.task_id
AND tt.task_type_no = t.task_type_no
AND c.grade_no = tt.grade_no
AND t.task_type_no = tn
AND ta.task_history_id = 1;
RETURN cost_var;
END;
/
-- my call select statment
SELECT total_cost(t.task_id) AS task_cost
FROM task t;
它运行没有错误,但行都是空白的? 请告诉我我做错了什么。
这是实体关系图 (ERD)
您似乎在使用 HAVING
来应用简单的 WHERE
条件。同样的例子:
SQL> create table groupTable (id number, num number);
Table created.
SQL> select sum(num)
2 from groupTable
3 where id = 1;
SUM(NUM)
----------
SQL> select sum(num)
2 from groupTable
3 having id = 1;
having id = 1
*
ERROR at line 3:
ORA-00979: not a GROUP BY expression
SQL> select sum(num)
2 from groupTable
3 group by id
4 having id = 1;
no rows selected
SQL> select sum(num)
2 from groupTable
3 group by id
4 having sum(num) = 1;
no rows selected
SQL> select sum(num)
2 from groupTable
3 where sum(num) = 1
4 group by id;
where sum(num) = 1
*
ERROR at line 3:
ORA-00934: group function is not allowed here
SQL>