
oracle 函数 返回值
我创建了一函数:createorreplacefunctionF_unload_amountFormatTrigger(idvarchar2)returnNumberis...
我创建了一函数:
create or replace
function F_unload_amountFormatTrigger(id varchar2) return Number is
v_unload_amount number;
begin
select b.amount into v_unload_amount from
Gz_Ord_Trans_Contract_Headers a,
Gz_Ord_Trans_Contract_Lines b
where b.cargo_description='卸车费' and
a.contract_header_id=b.contract_header_id and
a.contract_number=id;
return v_unload_amount;
end;
在SQL语句调用:
select F_unload_amountFormatTrigger('RJ0001') from Gz_Ord_Trans_Contract_Headers a
时返回大量行的'56'结果,
执行select b.amount from Gz_Ord_Trans_Contract_Headers a,
Gz_Ord_Trans_Contract_Lines b
where b.cargo_description='卸车费' and
a.contract_header_id=b.contract_header_id and
a.contract_number='RJ0001';
返回一行'56'结果,而我想在SQL语句中调用函数时返回单个结果,怎么做? 展开
create or replace
function F_unload_amountFormatTrigger(id varchar2) return Number is
v_unload_amount number;
begin
select b.amount into v_unload_amount from
Gz_Ord_Trans_Contract_Headers a,
Gz_Ord_Trans_Contract_Lines b
where b.cargo_description='卸车费' and
a.contract_header_id=b.contract_header_id and
a.contract_number=id;
return v_unload_amount;
end;
在SQL语句调用:
select F_unload_amountFormatTrigger('RJ0001') from Gz_Ord_Trans_Contract_Headers a
时返回大量行的'56'结果,
执行select b.amount from Gz_Ord_Trans_Contract_Headers a,
Gz_Ord_Trans_Contract_Lines b
where b.cargo_description='卸车费' and
a.contract_header_id=b.contract_header_id and
a.contract_number='RJ0001';
返回一行'56'结果,而我想在SQL语句中调用函数时返回单个结果,怎么做? 展开
展开全部
select F_unload_amountFormatTrigger('RJ0001') from Gz_Ord_Trans_Contract_Headers a
你这样写的话,Gz_Ord_Trans_Contract_Headers里有多少条数据,就会有多少个'56'.
如果'RJ0001'是固定,
可以写成select F_unload_amountFormatTrigger('RJ0001') from dual,
如果不固定,就可以考虑写成:
select F_unload_amountFormatTrigger(contract_number) from Gz_Ord_Trans_Contract_Headers
你这样写的话,Gz_Ord_Trans_Contract_Headers里有多少条数据,就会有多少个'56'.
如果'RJ0001'是固定,
可以写成select F_unload_amountFormatTrigger('RJ0001') from dual,
如果不固定,就可以考虑写成:
select F_unload_amountFormatTrigger(contract_number) from Gz_Ord_Trans_Contract_Headers
追问
select F_unload_amountFormatTrigger(contract_number) from Gz_Ord_Trans_Contract_Headers 不就是返回多条记录吗?
select F_unload_amountFormatTrigger('RJ0001') from dual的话,如果还需要查询其它字段呢?
比如 select F_unload_amountFormatTrigger('RJ0001'),b.contract_line_number from Gz_Ord_Trans_Contract_Lines b
要返回一条记录哦!
追答
那就加个条件。
select F_unload_amountFormatTrigger('RJ0001'),b.contract_line_number from Gz_Ord_Trans_Contract_Headers a,Gz_Ord_Trans_Contract_Lines b
where a.contract_header_id=b.contract_header_id and a.contract_number='RJ0001';
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询