Solved

ORACLE -- SUBSTR update ?

Posted on 2010-11-08
4
1,072 Views
Last Modified: 2013-12-18
I HAVE AN ORG_CODE varchar2 column,
RUN the BELOW STATEMENT WHICH SHOULD
update all 100+ of MY ORG_CODE = '130xxx'
RECORDS to ORG_CODE = '100xxx', BUT
updates them to '231' instead.

How can I fix ?

update COMPANY_POSITION_TAB
--set ORG_CODE = '100101' -- works
set ORG_CODE = '100' + SUBSTR(ORG_CODE,4,3) -- fails
where SUBSTR(ORG_CODE,1,3) = '130'
0
Comment
Question by:finance_teacher
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 9

Expert Comment

by:jerrypd
ID: 34084008
i would verify the whole ORG_CODE before going any further.
The code looks ok to me, but not knowing what the 4th 5th and 6th chars are makes it a bit tough to diagnose...
0
 
LVL 10

Accepted Solution

by:
laneduncan earned 500 total points
ID: 34084029
Oracle doesn't use the '+' character for concat.  You'd need to do something like this, instead:

set ORG_CODE = '100' || SUBSTR(ORG_CODE,4,3)
where SUBSTR(ORG_CODE,1,3) = '130'
0
 
LVL 9

Expert Comment

by:jerrypd
ID: 34084051
oops! I missed that '+' sign - - good catch!!
0
 
LVL 32

Expert Comment

by:awking00
ID: 34105424
Another way -
UPDATE COMPANY_POSITION_TAB
SET ORG_CODE = REGEXP_REPLACE(ORG_CODE,'^130','100');
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question