Re: Horrible, but maybe unavoidable
This doesn't look a Pascal-based procedural language like Oracle PL/SQL, this looks like Pascal (probably Delphi) code. PL/SQL IF blocks are terminated by END IF and don't require the begin..end blocks.
This looks a symptom of bad copy&paste, lack of knowledge of proper containers (arrays, lists, etc.), sloppy variable naming, and probably lack of security - that code may be easily vulnerable to SQL injection.