For Loop and Join in Databases – Oracle & PostgreSQL