I have a view. the view has a function that returns a text string of either “TRUE” or “FALSE” based on two criteria
The function looks at two tables.
Condition 1: The customer table contains a date field – if the system date is > the date field it should return false
Condition 2: The customer table links to a customer_detail table. there is sometimes a record in the detail table and sometimes not (so i added the outer join sytax to the query which doesn’t really do anything because the additional criteria forces an inner join I believe). There can be multiple records in the customer_detail table for each record in the customer table. if there are multiple records in the detail table I need to look at the most recent record max(uniquefield). this table has a date field. if this field is not null the function should return false regardles of the first condition.
Here is what I have. When I compile I get two errors:
SQL statment ignored – at the first line of the first select statment
and
Error(17,45): PL/SQL: ORA-00942: table or view does not exist – on the subselect of the first select
create or replace FUNCTION "F_STATUS" (
N_UNIQUE IN NUMBER)
RETURN VARCHAR2
IS
V_TORF varchar2(20);
D_ACTDATE date;
D_STARTDATE date;
BEGIN
select b.startdate into D_STARTDATE
from customerdb.customer a, customerdb.customer_detail b
where a.uniquefield= b.uniquefield(+) and
b.uniquefield = N_UNIQUE and
b.uniquefield in
(select max(c.uniquefield) from customerdb.customer_detail c group by uniquefield);
if
D_STARTDATE is not null
then
V_TORF :='FALSE';
RETURN(V_TORF);
else
select expiredate into D_ACTDATE
from customerdb.customer
where customerdb.customer.uniquefield = N_UNIQUE;
IF
D_ACTDATE > SYSDATE
then
V_TORF :='TRUE';
RETURN(V_TORF);
else
v_TORF :='FALSE';
RETURN(V_TORF);
end if;
end if;
end;
Your procedure seems to be unable to see the table
customerdb.customer_detail. This is likely due to the fact that procedures are defined without any role enabled and you probably have a role with the SELECT ANY TABLE privilege. From the security guide:To see if your procedure will be able to run a query, you can test with your user after having disabled all roles with the following command:
In your case you probably need to be granted the SELECT privilege directly to your user: