2013-01-24 50 views
-3

有人可以告诉我为什么这个PSQL出现编译错误吗?Oracle - PSQL编译错误

set serveroutput on 
Create or replace function get_warehouse_location(Name in Customer.Name%type) 
return w.location %type as 
wLocation  warehouse.Location %type; 
begin 
select warehouse.location 
into wLocation 
from Customer c, Warehouse w 
where cName= 'Finch' 
and warehouse.address='  '; 
return (Location); 
end; 
+1

什么是语法错误?第一次脸红,你正在返回'location',它不是你在任何地方定义的变量 - 也许你的意思是'返回wLocation'。一旦你解决了这个问题,我强烈希望你会得到一个运行时错误,因为你的'SELECT'返回的行太多。您正在'客户'和'仓库'表之间进行笛卡尔连接,因此不太可能返回恰好为1的行。 –

回答

0

至少有一个问题,你怎么称呼类型。应该是table.field%TYPE。没有空间。

set serveroutput on 
Create or replace function get_warehouse_location(Name in Customer.Name%type) 
return w.location%type as 
wLocation  warehouse.Location%type; 
begin 
select warehouse.location 
into wLocation 
from Customer c, Warehouse w 
where cName= 'Finch' 
and warehouse.address='  '; 
return (Location); 
end; 
+1

在'%type'之前有一个空格是合法的(尽管很少见)。 –