Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy do I get 'No data found' when passing a string variable into PL/SQL where clause
    primarykey
    data
    text
    <p>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 <code>WHERE</code> clause of the <code>SELECT</code> statement in this PL/SQL I get an error. </p> <p>However if I output what is in <code>user_rec.USER_NAME</code> to the console there is a valid value, and if I hardcode a string ex: <code>WHERE UserID = 'USERNAME'</code> it also works as expected. It seems to only fail for string variables in the <code>WHERE</code> clause.....?</p> <pre><code>ORA-01403: no data found ORA-06512 at line 12 01403.00000 - "no data found" *Cause *Action Error at line 1 </code></pre> <p><strong>PL/SQL:</strong></p> <pre><code>DECLARE v_addressbooknum number; v_addresstype nchar(3); CURSOR SELECT_PORTALUSERS is SELECT USER_NAME FROM PERSONS WHERE DEFAULT_GROUP &lt;&gt; '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; </code></pre> <p>===================================================================== <strong>EDIT</strong></p> <p>Here is the new PL/SQL I ran based on DCookie's suggestion</p> <pre><code>DECLARE v_addressbooknum number; v_addresstype nchar(3); CURSOR SELECT_PORTALUSERS is SELECT USER_NAME FROM PERSONS WHERE DEFAULT_GROUP &lt;&gt; '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; </code></pre> <p>And here is the output I get, you can see if finds values in the <code>user_rec.user_name</code>. 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).</p> <pre><code>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 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload