Posts tagged with “oracle”

Alternative to Oracle Regular expression for word boundaries

You might already know that Oracle regular expression doesn't support \b. However, we need it. So the answer is

(^|\W)yourstring(\W|$)

Reference

Quoting string literals in PL/SQL

We sometimes need to include a single quote in an SQL statement, I believe you already know the normal way, use two single quote characters to express one single quote. However, if you are using oracle 10g or a more recent version, the following way could be better:

This is a new feature of 10g that enables us to embed single-quotes in literal strings without having to resort to double, triple or sometimes quadruple quote characters. This is particularly useful for building dynamic SQL statements that contain quoted literals.

The mechanism is invoked with a simple "q" in PL/SQL only. The syntax is q'[...]', where the "[" and "]" characters can be any of the following as long as they do not already appear in the string.

  • !
  • [ ]
  • { }
  • ( )

Note that at the time of writing, the quoting mechanism only appears to work with 10g clients/OCI. If used with any software that uses an older Oracle client it fails with ORA-01756: quoted string not properly terminated (confirmed with sqlplus, TOAD and PL/SQL Developer).

If you want samples, see Reference

Keep the the same order as input data when using `WHERE fieldName IN(fieldVal1, fieldVal2)`

Don't waste time; here's the sample code with the Oracle database.

SELECT * FROM SampleTable WHERE sample_field in (7,3,4,6) ORDER BY INSTR(',7,3,4,6,',  ',' || sample_field || ',');