Hi, I have writen a function that will return a specific field from a table. I want to be able to re-populate one of the parameters in the function as it executes, depending on what the user has entered as the parameter using the
following, but simple cant find where in the function to add the if..else statement without causing a compile error
BEGIN
IF vAddressElement = 1
THEN vAddressElement := 'FirstAddressLine';
ELSE vAddressElement := vAddressElement;
END IF;
END
CREATE OR REPLACE FUNCTION Fnc_Getaddresselements(iPerId IN Mpi_Addr_Link.Alk_Per_Id%TYPE :=1,
vAddressElement IN Mpi_Address.Add_Line1%TYPE,
vAddCurrentValue IN Mpi_Address.Add_Current%TYPE := 1)
RETURN VARCHAR IS
/*
$Revision: 2 $
$Modtime: 11/05/06 10:29 $
*/
RESULT Mpi_Address.Add_Line1%TYPE;
vSQL VARCHAR2(2000);
BEGIN
BEGIN
vSQL:= 'SELECT ' || vAddressElement || '
FROM vwe_mpi_address a INNER JOIN vwe_mpi_addr_link al
ON a.add_id = al.alk_add_id
WHERE al.alk_per_id = ' || (iPerId) || '
AND a.add_current = ' || vAddCurrentValue || '
AND (add_from IS NULL OR add_from <= trunc(SYSDATE))
AND (add_to IS NULL OR add_to >= trunc(SYSDATE))';
EXECUTE IMMEDIATE Rtrim(vSQL)
INTO RESULT;
EXCEPTION
WHEN OTHERS THEN
RESULT := NULL;
END;
/* dbms_output.put_line(vAddressElement);
dbms_output.put_line(RESULT);*/
RETURN(RESULT);
END Fnc_Getaddresselements;
Thanks in advance...
following, but simple cant find where in the function to add the if..else statement without causing a compile error
BEGIN
IF vAddressElement = 1
THEN vAddressElement := 'FirstAddressLine';
ELSE vAddressElement := vAddressElement;
END IF;
END
CREATE OR REPLACE FUNCTION Fnc_Getaddresselements(iPerId IN Mpi_Addr_Link.Alk_Per_Id%TYPE :=1,
vAddressElement IN Mpi_Address.Add_Line1%TYPE,
vAddCurrentValue IN Mpi_Address.Add_Current%TYPE := 1)
RETURN VARCHAR IS
/*
$Revision: 2 $
$Modtime: 11/05/06 10:29 $
*/
RESULT Mpi_Address.Add_Line1%TYPE;
vSQL VARCHAR2(2000);
BEGIN
BEGIN
vSQL:= 'SELECT ' || vAddressElement || '
FROM vwe_mpi_address a INNER JOIN vwe_mpi_addr_link al
ON a.add_id = al.alk_add_id
WHERE al.alk_per_id = ' || (iPerId) || '
AND a.add_current = ' || vAddCurrentValue || '
AND (add_from IS NULL OR add_from <= trunc(SYSDATE))
AND (add_to IS NULL OR add_to >= trunc(SYSDATE))';
EXECUTE IMMEDIATE Rtrim(vSQL)
INTO RESULT;
EXCEPTION
WHEN OTHERS THEN
RESULT := NULL;
END;
/* dbms_output.put_line(vAddressElement);
dbms_output.put_line(RESULT);*/
RETURN(RESULT);
END Fnc_Getaddresselements;
Thanks in advance...