0

I have existing records in the database the field description is

aa_desc NOT NULL VARCHAR2(8) 

i have existing record for this field and now i have to add - (hyphen) with the existing record.

since it is restricted to eight characters i have to pad only the remaining characters with existing.

ex : if the existing value is aaa it needs to be padded like -----aaa.

how do i do this.

Technical environment :

DB : Oracle

Development : java
Joe
  • 4,460
  • 19
  • 60
  • 106

1 Answers1

1

You should use Oracle's LPAD function. It adds the necessary character to the left side of the string to make of the specified lenght.So in your case, it should be:

LPAD(aa_desc, 8, '-')

http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions095.htm#SQLRF00663

Guneli
  • 1,691
  • 1
  • 11
  • 17
  • Thanks Guneli, update table set fieldName = lpad(fieldName , 8, '-' ) where matchingColumn=value.. .. – Joe May 15 '14 at 09:36