Solved

ORACLE -- SUBSTR update ?

Posted on 2010-11-08
4
1,052 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
  • 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Oracle -- identify blocking session 24 52
database upgrade 8 75
Repeat query 13 46
make null the repeated levels 2 21
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
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…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

773 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