1

Hi i need to remove space within string .can any one help me with these.

String1 = "Biotin-dPEG <REFERENCE ID="9869" TYPE="trademark"/>n-azide products are single molecular weight dPEG <REFERENCE ID="9869" TYPE="trademark"/> products that permit biotin labeling with precise spacing" .

I need to remove space before <REFRENCE ID = "9869 ...> in string1.

8
  • Oracle is a database. It is not normally used to do string manipulations on individual values. PL/SQL is a scripting language associated with Oracle. But, if you are using that, then the string is defined using :=, not =. Hence, I don't understand the question. Commented Feb 1, 2017 at 11:46
  • try trim function Commented Feb 1, 2017 at 11:47
  • sure sorry for not cleary mentioning this earlier Commented Feb 1, 2017 at 11:56
  • "Biotin-dPEG <REFERENCE ID="9869" TYPE="trademark"/>n-azide products are single molecular weight dPEG <REFERENCE ID="9869" TYPE="trademark"/> products that permit biotin labeling with precise spacing" i need to remove space before <REFRENCE> . Commented Feb 1, 2017 at 11:57
  • @mohsen.b - what do you think will be the result of trim()? Commented Feb 1, 2017 at 11:59

3 Answers 3

2

Using regexp_replace:

with t(col) as (
  select 'Biotin-dPEG <REFERENCE ID="9869" TYPE="trademark"' from dual
)
-- test data. Dont mind the above --

select
  regexp_replace(col, '\s+(<REFERENCE)','\1')
from t;

Produces:

Biotin-dPEG<REFERENCE ID="9869" TYPE="trademark"
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks @GurV . i modified this little and it worked .thanks for your valuable time and suggestion.
select regexp_replace(col, '\s+(<REFERENCE ID)','\1') from table
@Animesh The with part was anyway to build a test table using CTE. Glad if it helped
What happens if the string is Biotin-dPEG <REFERENCE TYPE="trademark" ID="9869" />?
@MT0 Previously I thought if we're looking for <REFERENCE ID, but now OP says he want only <REFERENCE. So, updated.
0

This will remove all space surrounding =

select  regexp_replace('String1 = "Biotin-dPEG <REFERENCE ID="9869" TYPE="trademark"/>n-azide products are single molecular weight dPEG <REFERENCE ID = "9869" TYPE="trademark"/> products that permit biotin labeling with precise spacing" .
','\s*=\s*','=')
from    dual

String1="Biotin-dPEG <REFERENCE ID="9869" TYPE="trademark"/>n-azide products are single molecular weight dPEG <REFERENCE ID="9869" TYPE="trademark"/> products that permit biotin labeling with precise spacing" .

Here is a simple demo

select  regexp_replace('A =  1,B=   2,C=3,D=  4,E   =  5','\s*=\s*','=')
from    dual

A=1,B=2,C=3,D=4,E=5

https://docs.oracle.com/cd/E18283_01/olap.112/e17122/dml_functions_2068.htm

https://docs.oracle.com/cd/E18283_01/server.112/e17118/ap_posix.htm#SQLRF020

Comments

0

Oracle Setup:

CREATE TABLE data ( string ) AS
SELECT 'Biotin-dPEG <REFERENCE ID="9869" TYPE="trademark"/>' FROM DUAL UNION ALL
SELECT 'Biotin-dPEG <REFERENCE TYPE="trademark" ID="9869"/>' FROM DUAL;

Query:

SELECT REGEXP_REPLACE(
         UPDATEXML(
           xml,
           '/root/REFERENCE[@ID="9869"][1]/preceding-sibling::text()',
           RTRIM(
             EXTRACT(
               xml,
               '/root/REFERENCE[@ID="9869"][1]/preceding-sibling::text()'
             )
           )
         ).getClobVal(),
         '^<root>|</root>$|^<root/>$'
       ) AS string
FROM   ( SELECT XMLType( '<root>' || string || '</root>' ) AS xml
         FROM   DUAL );

Output:

STRING
--------------------------------------------------
Biotin-dPEG<REFERENCE ID="9869" TYPE="trademark"/>
Biotin-dPEG<REFERENCE TYPE="trademark" ID="9869"/>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.