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!
Related
This question already has an answer here:
how to replace non ascii characters with empty values
(1 answer)
Closed 2 months ago.
We have data in Postgres something as below , there is possibility of having mutiple non-ascii chars in a string
Name
Kate SolutionǸǸs
Etak Solutions
We are trying to identify if there are any NON-ASCII char set from the string and remove all of them if there are any(if there no non-ascii then keep the string as is) and expecting output below output
Name
Kate Solutions
Etak Solutions
Tried using below SQL but its just removing only one non-ascii char irrespective of the position where it is present
select REGEX_REPLACE(name,'[^ -~]', '') as new_name from table
Appreciate any help!
From the Postgresql documentation:
If the g flag is given, or if N is specified and is zero, then all matches at or after the start position are replaced. (The g flag is ignored when N is specified.)
So either add a 4th parameter as zero, 0, or add a 6th parameter as 'g'.
This question already has answers here:
What is the meaning of the prefix N in T-SQL statements and when should I use it?
(4 answers)
Closed 2 years ago.
I have a database column that is nvarchar(50). There are some records that might have an em dash in them.
I want to find those records.
However, when I copy and paste an em-dash from another program, SQL Server Management Studio treats it like a regular hyphen.
This just returns all the parts with hyphens even though it's an em-dash in between the percent signs:
select * from part
where partnum like '%−%'
How can I make SSMS search for the em-dash and not hyphens?
emdash: −
hyphen: -
In case anyone is wondering this was solved by learning how to use NVARCHAR searches. You can search for something you copy paste from another program by prefixing the search string with an 'N' like this:
SELECT * FROM part
WHERE PartNum LIKE N'%−%'
You could try something like this.
select * from part
where partnum like '%' + NCHAR(8212) + '%'
This question already has an answer here:
Oracle SQL Regex not returning expected results
(1 answer)
Closed 3 years ago.
I tied searching on SO about my issue but didn't find one. I apologize if it is a duplicate.
Let's say I have a table as shown below:
|ACCOUNT | FEES_DETAILS |
================================
|AX001 | AOF=£20.5,VAT=25% |
|AX009 | AOF=11.25%,VAT=12.5%|
I want to fetch all the rows when FEES_DETAILS column has a %-based AOF(in the above example, I need to fetch the second record - AX009 as AOF=11.25%).
I am executing the following query but it is not returning any row(s):
SELECT * FROM ACCOUNT_FEES_DATA WHERE REGEXP_LIKE(FEES_DETAILS, 'AOF\s*=\s*\d+(?:\.\d+)?%');
I thought % at the end of my regular expression AOF\s*=\s*\d+(?:\.\d+)?% is being treated as a special character so I tried to escape it with a \. But that too didn't return any rows. Is there any other way of escaping a % in REGEXP_LIKE function? Can anyone help me with this?
Try this:
select * from test where REGEXP_LIKE(fees,'AOF=\d+.\d+%,');
This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 3 years ago.
I have to put a string after every 5 characters in a given string (varchar2).
Given string can have different length.
I already solved it by a loop using substrings.
Is there any way i could reach the goal using REGEXP in Oracle DB?
You can use REGEXP_REPLACE to replace every 5 characters with those 5 characters followed by another string. For example:
SELECT REGEXP_REPLACE('ABCDE12345FGHIJ67890KL', '(.{5})', '\1*') FROM DUAL
Output:
ABCDE*12345*FGHIJ*67890*KL
Demo on dbfiddle
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.