Results 1 to 4 of 4

Thread: Problem using REPLACE

  1. #1
    Join Date
    Jun 2009
    Posts
    49

    Problem using REPLACE

    Hello, I have to change codes in my Oracle database: I have to extract the codes beginning with 02 and having a length of 4 and 6 characters of the 59,350 community. Once extracted I must replace 02 of the top 3 by letters LVB. The problem with this request and if for example a 4 digit code is '0202'; the request will turn into 'LVBLVB' but I want it as 'LVB02'.

    The query works for codes 02XX or type 02XXXX, X is different from '02 'and between 2 or 4 characters.

    SELECT REPLACE (or.CODE, '02', 'LVB')
    FROM ORGANIZATION or
    WHERE or.COL = '59350'
    AND SubStr(or.CODE, 1, 2) = '02'
    AND (or.LGCODE = '4' OR or.LGCODE = '6')

    I tried in the first row to SELECT REPLACE (or.CODE, '02%', 'LVB') the percentage here is not caught in the LIKE expression. So I am stuck.

  2. #2
    Join Date
    May 2008
    Posts
    271

    Re: Problem using REPLACE

    Code:
    SELECT 'LVB' || substr(OR.CODE,3,4000)
    FROM ORGANIZATION OR
    WHERE OR.COL = '59350'
    AND SubStr(OR.CODE, 1, 2) = '02'
    AND (OR.LGCODE = '4' OR OR.LGCODE = '6')
    Personally, I would have avoided using the alias "OR"

  3. #3
    Join Date
    Nov 2008
    Posts
    996

    Re: Problem using REPLACE

    I have an example that can do what you want, here I am replacing the first character of a postal code by another without using REPLACE:
    Code:
    SELECT ad.adr_cod_pos, '6' || substr(ad.adr_cod_pos, 2, length(ad.adr_cod_pos) - 1) 
    FROM address AD 
    WHERE ad.adr_cod_pos LIKE '5%'
    If you want to adapt, I think that by
    Code:
    SELECT or.CODE, 'LVB' || substr(or.CODE, 3, length(or.CODE) - 2) 
    FROM ORGANIZATION or 
    WHERE or.COL = '59350' 
    AND SubStr(or.CODE, 1, 2) = '02' 
    AND (or.LGCODE = '4' OR or.LGCODE = '6')

  4. #4
    Join Date
    Jun 2009
    Posts
    49

    Re: Problem using REPLACE

    Thank you for your responses. By the way XSI, why would you recommend me to not to use "or" alias? Would it clash with logical "OR" in SQL and thus generating an error message to me? In such case, I think I will go for "org" simply because as you might know aliases makes the query look quiet understandable.

Similar Threads

  1. How to replace the bezel of the cpu ?
    By Grayson in forum Hardware Peripherals
    Replies: 3
    Last Post: 31-10-2010, 05:23 AM
  2. Replace Image In SVG
    By ASHER in forum Portable Devices
    Replies: 5
    Last Post: 30-06-2010, 09:13 AM
  3. How to replace a key by another?
    By Caidenn in forum Hardware Peripherals
    Replies: 5
    Last Post: 11-03-2010, 06:59 AM
  4. What is the use of the replace() in C++
    By D-Mon in forum Software Development
    Replies: 5
    Last Post: 18-02-2010, 05:19 PM
  5. Replace fan on dell
    By Conner in forum Hardware Peripherals
    Replies: 3
    Last Post: 17-07-2009, 10:15 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,524,093.51522 seconds with 16 queries