Remove new line from the end of string SQL - sql

I have a database table called Players with almost 400 rows. I'm using sqlite under DB Browser for SQLite.
All of my TEXT fields have a "\n" added at the end of my string.
Ex:
"Louie
"
I tried RTRIM to get rid of the white spaces, but it didn't work.
How can I get from
"Louie
"
to
"Louie"
?

You can try replace function. For example:
Select replace(<ColumnName>, CHAR(10), '') from <table_name>;
Here, CHAR(10) is for newline character \n.

Try REPLACE function. replace new line character with null.

Related

How can I replace a string pattern with blank in hive?

I have a string as:
https://maps.googleapis.com/maps/api/staticmap?center=41.892532+-87.63811&zoom=11&scale=2&size=280x320&maptype=roadmap&format=png&visual_refresh=true%7C&markers=size:mid%7Ccolor:0x8000ff%7Clabel:1%7C2413+S+State+St++Chicago+IL+60616%7C&markers=size:mid%7Ccolor:0x8000ff%7Clabel:2%7C3000+N+Halsted+St++Chicago+IL+60657%7C&markers=size:mid%7Ccolor:0x8000ff%7Clabel:3%7C++++&key=AIzaSyBNEAQcC5niAEeiP3zkA_nuWGvtl0IOEs4
I want to replace the '++++' pattern at the end with blank and not the single occurrence of '+'. Tried using regexp_replace and translate functions in hive but that replaces all the single occurrences of '+' as well.
Use
regexp_replace(string,'[+]{4}','')
Pattern '[+]{4}' means + caracter four times.
Test:
select regexp_replace('++markers=size:mid%7Ccolor:0x8000ff%7Clabel:3%7C++++&','[+]{4}','');
Result:
OK
++markers=size:mid%7Ccolor:0x8000ff%7Clabel:3%7C&
Dod you try this?
replace(string, '++++', '')
Admittedly, this will replace all occurrences of '++++', but your string only has one of them.

how not to replace "]" when using regex_replace for removing special characters

I'm trying to remove few special characters from a comment column in my table. I used the below statement but it seems to remove the ']' even though it is in the ^[not] list.
UPDATE TEST
set comments=REGEXP_REPLACE(
comments,
'[^[a-z,A-Z,0-9,[:space:],''&'','':'',''/'',''.'',''?'',''!'','']'']]*',
' '
);
The table data contains the following:
[SYSTEM]:Do you have it in stock? 😊
My requirement is to have:
[SYSTEM]:Do you have it in stock?
You have two mistakes in you regex:
Do not put characters in quotes and don't split them with comma.
Remove inner square brackets.
And place closing square brackets first in the list, just after initial circumflex. Fixed regex:
UPDATE TEST set comments=REGEXP_REPLACE(comments,'[^]a-zA-Z0-9[:space:]&:/.?!]*',' ');
My try, I just removed the commas, put the "accepted" characters after the initial "not"(no brackets).
A special case are the brackets: https://dba.stackexchange.com/a/109294/6228
select REGEXP_REPLACE(
'[ION] are varză murată.',
'[^][a-zA-Z0-9[:space:]&:/,.?!]+',
' ')
from dual;
Result:
[ION] are varz murat .

Remove last x characters until a specific character

I got this string /uk-en/contact-us/frequently-asked-questions/your-trip/there-wi-fi-access-in-the-eurostar-terminals-and-board-your-trains and I need to get just the last part of the URL (until the last /).
Then I want to replace '-' with a space. The strings are not with the same number of characters.
How can I do?
Thank you!
Solution using BigQuery functions:
select regexp_replace(last(split(x, "/")), "-", " ") from
(select
"/uk-en/contact-us/frequently-asked-questions/your-trip/there-wi-fi-access-in-the-eurostar-terminals-and-board-your-trains"
as x)
Here is what I tried in SQL Server
DECLARE #s VARCHAR(max)= '/uk-en/contact-us/frequently-asked-questions/your-trip/there-wi-fi-access-in-the-eurostar-terminals-and-board-your-trains'
SELECT REVERSE(SUBSTRING(REVERSE(#s),CHARINDEX('/',REVERSE(#s)),LEN(REVERSE(#s))))+REVERSE(REPLACE(SUBSTRING(REVERSE(#s),1,CHARINDEX('/',REVERSE(#s))-1),'-',' '))
Sorry this was for SQL Server
did you try using split in big query
SPLIT('str' [, 'delimiter']) Returns a set of substrings as a repeated string. If delimiter is specified, the SPLIT function breaks str into substrings, using delimiter as the delimiter.

Escape sequence character in sql query parameter in windows azure

When querying a string column, if the search parameter has a " ' " in it, the execution fails due to a syntax error. I tried to use an escape sequence character (if thats how its called), but it still does not work.
SELECT * FROM OpusOne.Accounts WHERE firstName like '%jose\'%'
What would be the correct way to add a quote " ' " to a string parameter ?
Thank you
Try this:-
SELECT * FROM OpusOne.Accounts WHERE firstName like '%jose''%'
Escape using another single quote.

Remove extra spaces if more than one space through vb.net Oracle query

Just looking for another way to remove any excess spaces(>1) throughout a query. I'm taking information for my Oracle query from an Excel spreadsheet so there's bound to be some excess zeroes due to user error and whatnot so that when I'm taking the information from the excel it will have 2 sometimes 3 extra spaces after some values so we won't get any records returned from Oracle when we query it through the application. I have tried Trim(ds.Tables.Item(0).Rows.Item(k).Item(i).ToString.ToUpper) but this isn't removing the extra spaces in some of the values. Is there some SQL statement I don't know of or perhaps another reason why Trim isn't working?
Edit: Was writing replace function incorrectly.
Original: string.Replace(" ", " ")
New: string = string.replace(" ", " ")
Use String.Replace(" ", String.Empty) instead. Trim only removes leading and trailing spaces.
On the Oracle side, you can use the REGEXP_REPLACE function, but you need to apply it to each column you want to remove the extra spaces from:
SELECT
REGEXP_REPLACE(myCol1, ' {2,}', ' ') AS myCleanCol1,
REGEXP_REPLACE(myCol2, ' {2,}', ' ') AS myCleanCol2,
FROM myTable
The example here looks for all occurrences of two or more spaces (that's the second parameter) and replaces them with a single space (the third parameter).
You can use REGEXP_REPLACE
Could be something like this:
regexp_replace(your_column, '\s{2,}', '')
Here is a sqlfiddle demo