Monday, September 15, 2008

Quotes for strings in SQL

If the field is character, we need to ensure the variable is enclosed by quotes, this will allow Oracle to utilise the indexed key for lookup.

Example - &Condition = “where BUSINESS_UNIT = ‘UQUNI’ and EMPLID = ‘“ &Emplid “’”; i.e. putting single quotes around the variable &Emplid

A better solution is to use the bind variables as shown below:&rsCharge.Fill(“where BUSINESS_UNIT = :1 and EMPLID = :2”, “UQUNI”, &Emplid);For Oracle, EMPLID = 12345678 is less efficient than EMPLID = ‘12345678’












No comments: