问题没有完: 为何我的函数一旦加入SQL%FOUND就什么值也不返回了 ????????????????Create OR REPLACE FUNCTION F_Get_Equip_Economic_Class ( in_class_code IN T_EQUIP.CLASS_CODE%TYPE) RETURN VARCHAR IS economic_class_code T_EQUIP_STANDARD.YES_INCLUDE%TYPE ; class_code_len3 T_EQUIP.EQUIP_CODE%TYPE ; class_code_len4 T_EQUIP.EQUIP_CODE%TYPE ; BEGIN class_code_len3 := SubStr( in_class_code, 1, 3 ) || ',' ; class_code_len4 := SubStr( in_class_code, 1, 4 ) || ',' ;
SELECT a.class_code into economic_class_code FROM T_EQUIP_STANDARD a where in_class_code like a.yes_include and (instr( a.not_include, class_code_len3 ) = 0 and instr( a.not_include, class_code_len4 ) = 0 ) and ( a.class_level > 2 ) ; if SQL%FOUND then Return '0000-000' ; ---economic_class_code ; end if ; Return '3333-000' ; ---economic_class_code ; end ;
SQL%ROWCOUNT, SQL%NOTFOUND, SQL%FOUND这些好像都是游标,不使用游标不知道是否可以正常运行。我给你的建议是用个土办法,添加一段异常处理程序,如果程序运行没有出错, 说明只有一行纪录返回,否则会出错,然后在异常处理中select count(*) into count 然后return count,不就行了,这是个土办法,如果只需要返回记录数,我觉得还能用
在 PL/SQL中,有一个默认人的游标 ? 如何使用这个游标 ?
知道这个游标了: SQL%ROWCOUNT, SQL%NOTFOUND, SQL%FOUND
问题没有完:
为何我的函数一旦加入SQL%FOUND就什么值也不返回了 ????????????????Create OR REPLACE FUNCTION F_Get_Equip_Economic_Class
( in_class_code IN T_EQUIP.CLASS_CODE%TYPE)
RETURN VARCHAR
IS economic_class_code T_EQUIP_STANDARD.YES_INCLUDE%TYPE ;
class_code_len3 T_EQUIP.EQUIP_CODE%TYPE ;
class_code_len4 T_EQUIP.EQUIP_CODE%TYPE ;
BEGIN
class_code_len3 := SubStr( in_class_code, 1, 3 ) || ',' ;
class_code_len4 := SubStr( in_class_code, 1, 4 ) || ',' ;
SELECT a.class_code into economic_class_code
FROM T_EQUIP_STANDARD a
where in_class_code like a.yes_include
and (instr( a.not_include, class_code_len3 ) = 0
and instr( a.not_include, class_code_len4 ) = 0 )
and ( a.class_level > 2 ) ;
if SQL%FOUND then
Return '0000-000' ; ---economic_class_code ;
end if ;
Return '3333-000' ; ---economic_class_code ;
end ;
说明只有一行纪录返回,否则会出错,然后在异常处理中select count(*) into count 然后return count,不就行了,这是个土办法,如果只需要返回记录数,我觉得还能用
这个比count(*)要快些
你这样选多了一次列选呀刚开始学,多指教