I'm trying to get a user's ID number based on their network ID, but for some reason when I try to pass in their network ID in the WHERE clause of the SELECT statement in this PL/SQL I get an error.
However if I output what is in user_rec.USER_NAME to the console there is a valid value, and if I hardcode a string ex: WHERE UserID = 'USERNAME' it also works as expected. It seems to only fail for string variables in the WHERE clause.....?
ORA-01403: no data found
ORA-06512 at line 12
01403.00000 - "no data found"
*Cause
*Action
Error at line 1
PL/SQL:
DECLARE
v_addressbooknum number;
v_addresstype nchar(3);
CURSOR SELECT_PORTALUSERS is
SELECT USER_NAME FROM PERSONS WHERE DEFAULT_GROUP <> 'Employees';
BEGIN
FOR user_rec IN SELECT_PORTALUSERS LOOP
-- Fetch Address Book # based on user ID
SELECT ABNum INTO v_addressbooknum
FROM OWNER.TABLE@DBLINK
WHERE UserID = user_rec.USER_NAME;
END LOOP;
END;
===================================================================== EDIT
Here is the new PL/SQL I ran based on DCookie's suggestion
DECLARE
v_addressbooknum number;
v_addresstype nchar(3);
CURSOR SELECT_PORTALUSERS is
SELECT USER_NAME FROM PERSONS WHERE DEFAULT_GROUP <> 'Employees';
BEGIN
FOR user_rec IN SELECT_PORTALUSERS LOOP
-- DEBUG --
DBMS_OUTPUT.PUT_LINE('DEBUG Found User: ' || user_rec.USER_NAME);
-- END DEBUG --
BEGIN
-- Fetch Address Book # based on user ID
SELECT ABNum INTO v_addressbooknum
FROM OWNER.TABLE@DBLINK
WHERE UserID = user_rec.USER_NAME;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('User: '||user_rec.USER_NAME);
END;
END LOOP;
-- DEBUG --
DBMS_OUTPUT.PUT_LINE('DONE');
-- END DEBUG --
END;
And here is the output I get, you can see if finds values in the user_rec.user_name. And if I hardcode one of the user IDs found into the where clause it works properly (meaning the User IDs exist in the tabled the fetch is being executed against).
DEBUG Found User: USER846
User: USER846
DEBUG Found User: USER241
User: USER241
DEBUG Found User: USER780
User: USER780
DEBUG Found User: USER783
User: USER783
DEBUG Found User: USER294
User: USER294
DONE