I have the following package function in 10g that doesn't seem to be counting the number of rows correctly returned by the execute immediate command. When I run the query manually, it returns 1 row, however when the query runs inside the function, it returns 0 rows. The function and the tables are owned by the same account, so I don't think it's related to that, but I could be wrong.
Any ideas would be greatly appreciated.
Thank you.
Code:
function isValidDomain(sessdomainid in number, laid in number)
return number
is
Begin
declare
sqlDomains varchar2(500);
rows number(10):=0;
begin
sqlDomains :=' SELECT count(*) into recCount
FROM DRLearningActivityInstance
WHERE learningActivityID = ' || laid ||
' AND id NOT IN
(SELECT DM.EntityID
FROM DRDomainMembership DM, DRLearningActivityInstance LAI
WHERE DM.entityTypeID IN (Select id from drDomainEntityType where upper(tableName)=''DRLEARNINGACTIVITYINSTANCE'')
AND DM.entityId = LAI.ID
AND LAI.learningActivityID= ' || laid ||
' AND DM.domainId IN (' || sessdomainid || '))';
print_out(sqlDomains);
execute immediate (sqlDomains);
rows:= SQL%ROWCOUNT;
print_out('the number of rows returned was ' || rows);
if rows=0 then
return 1;
else
return 0;
end if;
end;
end isValidDomain;
This returns
Code:
SELECT id, code
FROM DRLearningActivityInstance
WHERE learningActivityID = 8461 AND id NOT IN
(SELECT DM.EntityID
FROM DRDomainMembership DM, DRLearningActivityInstance LAI
WHERE DM.entityTypeID IN
(Select id from drDomainEntityType where upper(tableName)='DRLEARNINGACTIVITYINSTANCE')
AND DM.entityId = LAI.ID
AND LAI.learningActivityID= 8461 AND DM.domainId IN
(1))
the number of rows returned was 0
1