Oracle SQL – Trimming a Specific Literal from a Field

Oracle Database
Oracle Database

I have frequently used the trim command for one purpose or another, but I have not used it to extract a literal out of a field, which I recently used to extract invalid values from a field in SQL.  So, I am providing a sample SQL for Future reference.

SQL Pattern:

  Select trim (‘I’ FROM <<FieldName>>)  AS <<FieldName>>

From <<TableName>>;

Substitution example:

In this example an invalid indicator (‘Y’) is being removed, performing a Null Value Logic (NVL) substitution to an integer compatible value, then the field is converted to an integer.

Select

CAST( NVL(trim (‘Y’ FROM AA.Status_ID) ,’0′)AS                   INT)         AS PACK_SZ

From  Inventory_code_TBL AA;

Reference Links:

One thought on “Oracle SQL – Trimming a Specific Literal from a Field

Comments are closed.