long time lurker, first time asker.
I'm trying to populate a LOV using a PL/SQL Function returning a Query for the first time. I can't seem to get the syntax correct as I'm always receiving the following error on validation:
ORA-20999: Parsing returned query results in "ORA-20999: Failed to parse SQL query!
ORA-06550: line 2, column 145: ORA-00923: FROM keyword not found where expected
of the following PL/SQL Function:
DECLARE
EMPLOYEES NUMBER := 0;
QR varchar(4000);
BEGIN
SELECT COUNT(*) INTO EMPLOYEES FROM TS4_USER@TS_INFO_4.STT
WHERE MAN_QT = :APP_USER
IF EMPLOYEES = 0 THEN
QR := 'select FIRST_NAME|| '' '' ||LAST_NAME d, select FIRST_NAME|| '' ''
||LAST_NAME r
FROM TS4_USER@TS_INFO_4.STT
WHERE MAN_QT IN (SELECT QT FROM TS4_USER@TS_INFO_4.STT
WHERE MAN_QT = (SELECT MAN_QT FROM TS4_USER@TS_INFO_4.STT
WHERE QT = :APP_USER)) AND FL = ''ESA''';
ELSE
QR := 'select FIRST_NAME|| '' '' ||LAST_NAME d, select FIRST_NAME|| '' ''
||LAST_NAME r
from TS4_USER@TS_INFO_4.STT
where MAN_QT = :APP_USER';
END IF;
RETURN QR;
END
This is confusing as Line 2 is part of my declaration area and I wouldn't expect a FROM here. I've done some googling on the matter and come up with very little. I'm fairly new to SQL and APEX, so I realize I could be overlooking something fairly simple. Any and all help is appreciated.
EDIT: Sorry about the formatting