if you don't want to move to a real SQL database, and temporarily storing the result is not possible, you'll have to make sure you don't run concurrent SELECT and UPDATE on the same table.
see LIMIT directive for SELECT.
so you'd do something like:
line=x while [ -n "$line" ] do line=$(sqlite3 database.db "select NUMBER from table WHERE STATUS = 'N'" LIMIT 1) SELECTION=$(echo $line | awk -F'|' '{ print $1 }') [some magic]™ sqlite3 database.db "update table SET STATUS='Y' WHERE NUMBER='$SELECTION'" done
That would make SELECT always return just one result and finish, which you would then process and UPDATE, and rerun SELECT to get next result (as STATUS changed, SELECT would get next value, not the old one as it no longer matches "N")
or maybe you could do "some magic (tm)" via SQL instead of a shell, so you could offload all the work to SQL engine...