Searching for newlines in a Oracle DB using SQL 'like' clause - sql

I'm trying to see if a particular column in a table in my Oracle database has any strings which contain a newline character, so a wildcard, a newline, and another wildcard.
I've tried the like command and a combination with CHR(10) and tried escaping the newline itself, but to no avail. What would be the proper way to detect a newline in somewhere within a string?
Thanks!

like '%'||chr(10)||'%' ought to work.

select * from yourTable where InStr(yourCol, Chr(10))>0 would work

Related

DB2 to SQL LinkedServer OpenQuery NonAscii Character Issue

So I've been scouring SO for answer and I've seen some great SQL functions to help try and remove non-ascii characters from my db, but I wanted to post the entire question / process here first to see if maybe upstream on my select from db2 into sql there is a fix.
What I'm doing: Getting data from a db2 database into SQL
Issue: Non-ascii characters causing problems
Process: It's pretty simple. I have a SQL Insert statement to select a bunch of columns from a db2 linkedserver using open query
insert into [table](stuff) select (stuff) From Openquery(SSF400,'select stuff from table')
However, in my SQL db, when editing the landed table, I'm getting weird trailing characters that appear as a space in a sql select statement, but are actually artifacts in SQL Edit mode:
I've tried using a few functions I found here on SO to strip these characters, but after these function(s) I'm leftover with a combination of greek/english characters similar to the below:
I'm thinking there must be a better way for me to do the initial insert other than using openquery so that the junk characters don't come over. I know SQL pretty well, but DB2 not so much...any advice?
Update: There does seem to be a junk character or two in the source system. Discovered using iNavigator. Also, source system is using db2 v7r3m0
Update here is a screenshot of the regexp expression mentioned in the comments used in a query in iNavigator. Although several characters were removed, some do remain. The original column is on the left, the cleansed column is on the right.
Cheers,
MD
I would try REGEXP_REPLACE(stuff,'[^\u0020-\u007E\u0009\u000A\u000D]+','') which will remove everything that is not a character from the 7-bit ASCII set but also removes any 7-bit ASCII control characters apart from Tab, New Line and Carriage Return. It also removes DEL

sql plus oracle ASCII() how to know ascii code of single quote

how to know ASCII code of single quote in sql oracle using ASCII()
i tried select ASCII(''') from dual;
but it showing an error
which escape character can be used for this
Simply use two single quotes to escape it:
select ASCII('''') from dual;
Looks a little weird but that should do it.

how to write a word to a database that is between 2 Apostrophes?

I have a table in my database of type nvarchar(50);
I want to write to that specific column that string 'Tal' - Tal between 2 apostrophes.
When I'm trying to do so what is recorded in my DB is "Tal" - Tal between 2 quotation marks.
My database is an SQL database and so are my scripts.
How this can be solved?
The standard way to do what you want is this.
insert into mytable ( mycolumn ) values ('''Tal''');
The first and last ' are the start and end markers for the string. Each '' within these characters means '. Refer to page 89 of the SQL 92 specification at http://www.andrew.cmu.edu/user/shadow/sql/sql1992.txt
I think escaping is the key to your question. For SQL apostrophes are special characters, thus they have to be escaped by '' (two apostrophes). Have you checked that your scripts do not add the second apostrophe for you? Probably you have to add Tal without the apostrophes.
Escape % seems to be DB dependant. Oracles uses \%, others accespt [%] and some seem to have a keyword ESCAPE. You have read the documentation of your database, look for "escape characters".
Try inserting like this using the backslash \'Tal\'.

Special character in varchar in SQL

I am inserting text from a file into a table, few of the lines have words like "you'll" or "don't". When I insert these lines as varchar in my table, I get an error saying - near "ll": syntax error. How do I overcome this?
Your single quote is being considered as the end of your string. Escape the quote that exists within your string to avoid this problem.
You need to escape your SQL statement. If you are using SQL Server, then you can use QUOTENAME to resolve this.
Use two apostrophes within apostrophe-quoted strings to insert the apostrophe:
insert into footable (foo) values('you''ll')
Thank you all for responses, since I was using sqlite3, there are inbuilt string formating functions available with the library, so I was able to use sqlite3_mprintf with %q instead of %s and it took care of single quotes.

How does one escape an apostrophe in db2 sql

I'm looking for the db2 equivalent of T-SQL's:
INSERT INTO People (Surname) VALUES ('O''Hara');
Use two apostrophes '' to get a single apostrophe on DB2 too, according to the DB2 Survival Guide. Isn't that working for you?
Brabster is correct. You are supposed to escape ' with ''
So to insert O'Hara , you will have to write O''Hara
Excerpt from:
http://www.michael-thomas.com/tech/db2/db2_survival_guide.htm
Escape character.
To insert a single quote, use 2 single
quotes ( '' ). To insert pet's use
the following pet''s.
Example: insert into MYTABLE (question,answer) values ('What is
your pet''s name?','blacky') `
just make it simple.
Keep your query in the single quotes ('). and where ever you are using qoutes, make it double.
for e.g. u want to insert ...... I'm fine. There's an answer.
in SQL we need to give ....... 'I''m fine. There''s an answer.'
I was trying to insert into DB2 a regex expression for an email address. I thought I had to escape all characters as outlined at the proceeding link, but escaping only the single quote contained within the regex seems to be all I needed to escape to get it properly inserted into the database:
https://www.ibm.com/support/knowledgecenter/en/SSEPGG_10.1.0/com.ibm.db2.luw.admin.ts.doc/doc/c0059609.html