Solved

ORACLE -- SUBSTR update ?

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PL/SQL Two changes 7 41
Database Design Dilemma 6 65
Oracle TRC and TRM files are taking too much space at Oracle client computer. 5 63
return value based on substr 10 48
Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

749 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