How to remove spaces from varchar in Oracle [duplicate] - sql

This question already has answers here:
Oracle trim whitespace on the inside of a string
(2 answers)
Closed 8 years ago.
I need to remove all spaces from column values of varchar2 type in an Oracle table.
For example, 2012_2 psk should become 2012_2psk.
I've tried to use REPLACE(column_name, ' ', '') but it doesn't work.
Can anyone help me?

I've found the solution. There are not white spaces, there are some other symbols that show themselves as blank spaces. So next code is working fine:
SELECT regexp_replace(docnum, '\W','') FROM tmp_uploadtable;

Please try:
regexp_replace(column_name, '[[:space:]]*','')
SQL Fiddle Demo

Related

Splitting a string by CRLF in SQL [duplicate]

This question already has answers here:
SQL Server 2005 Weird varchar Behavior
(2 answers)
Closed 6 months ago.
SO I know that there are a few post like this already here, but those post don't seem to work for me. My string contains '^' in it, and replace does not seem to like that character. Because of this, SELECT * FROM STRING_SPLIT(REPLACE(#InbMsg,#CLRF,'|'),'|')
does not seem to work The example message is this:
'W^1^Wave1102^2^11
H^12345678900987654321^OD1128263^MLO^7^Bill’s Order^98712391^N^A2^3^11
D^OGMens77162^123456789009^Y^4^Medium^Red^006134^000101^11728492'
When I run it through the previous statment, I just get 'W'. Anyone know why?
You want to replace the newline between 11 and H and also between 11 and D. You can replace the newline by looking for CHAR(10) then replace it with '^'. Then you can now split the rows using '^' as delimiter.
select * from STRING_SPLIT(REPLACE('W^1^Wave1102^2^11
H^12345678900987654321^OD1128263^MLO^7^Bill’s Order^98712391^N^A2^3^11
D^OGMens77162^123456789009^Y^4^Medium^Red^006134^000101^11728492',CHAR(10),'^'),'^');
Sample result:
https://dbfiddle.uk/?rdbms=sqlserver_2019&fiddle=0dc110c889af42a8b02096eedee3c393
value
W
1
Wave1102
2
11
H
12345678900987654321
OD1128263
MLO
7
…
10 rows of 26
CHAR(10) is ascii value for New Line / Line Break for SQL Server
It was a situation of not using varchar correctly. Make sure to declare variables correctly! ```SELECT * FROM STRING-SPLIT(REPLACE(#msg, #CLRF, ','),',') works in this situation!

MSSQL - substring a value between other values [duplicate]

This question already has answers here:
Turning a Comma Separated string into individual rows
(16 answers)
Closed 2 years ago.
NOIDEHOB_NOIDE1_4321-123
i want to create a querie that extract the following values from the example above:
NOIDEHOB
NOIDE1
4321-123
I need to base the query on the sign _. The values NOIDEHOB, NOIDE1 and 4321-123 are dynamic and the length will vary. There will never be any other _ sign in the string.
Any suggestions?
You can use string_split():
select s.value
from string_split('NOIDEHOB_NOIDE1_4321-123', '_') s

How to remove leading 0 from string in Oracle SQL? [duplicate]

This question already has answers here:
Removing leading zeros from varchar sql developer
(5 answers)
Closed 4 years ago.
I have a string looks like this.
00000000004000000
00000000001100000
00000001432000000
00000000167700000
I want to remove all leading leading 0 from that column, how can I achieve that?
You can use the TRIM function:
SELECT TRIM(LEADING '0' FROM col)
this will work:
select ltrim(colname,'0') from table_name;

Finding a record with apostrophe using LIKE [duplicate]

This question already has answers here:
PL/SQL, how to escape single quote in a string?
(5 answers)
How to anticipate and escape single quote ' in oracle
(2 answers)
How to handle a single quote in Oracle SQL
(2 answers)
Closed 4 years ago.
I need to find a below record
O'GRAD
I wanted to use LIKE
LIKE 'O'GRAD'
But i come across a problem with apostrophe.
What would be the best way around it?
Double up the apostrophe
LIKE 'O''GRAD'
or use the Q syntax
LIKE q'{O'GRAD}'
if your Oracle DB version is 10g or upper you may use :
select *
from mytable t
where t.col1 like '%'||q'$O'GRAD$'||'%';
/
or classically add an extra quote to existing quote
select *
from mytable t
where like '%'||'O''GRAD'||'%';
/
to overcome the single quotation mark problem.

How to replace characters in SQL [duplicate]

This question already has an answer here:
Converting special character to plain text in oracle
(1 answer)
Closed 5 years ago.
I'm a new SQL user, and I'd like to know if there is a simple way of replacing non-English characters in Oracle SQl-developer. Let's Say, I want Hernán Nuñez to show up as Hernan Nunez, but without having to actually replace "Hernán" with "Hernan". What I need is to replace everything that contains "á" to the same thing, but with "a" instead, for example. Any suggestions?
US7ASCII will give you the right result. Example:
SELECT CONVERT('BESANÇON','US7ASCII')
FROM table;
CONVERT(
--------
BESANCON
1 row selected.