00911. 00000 - "invalid character" - sql

When I run this SQL I get this error
ORA-00911: invalid character
00911. 00000 -  "invalid character"
*Cause:    The identifier name started with an ASCII character other than a
           letter or a number. After the first character of the identifier
           name, ASCII characters are allowed including "$", "#" and "_".
           Identifiers enclosed in double quotation marks may contain any
           character other than a double quotation. Alternate quotation
           marks (q'#...#') cannot use spaces, tabs, or carriage returns as
           delimiters. For all other contexts, consult the SQL Language
           Reference Manual.
*Action:   Check the Oracle identifier naming convention. If you are
           attempting to provide a password in the IDENTIFIED BY clause of
           a CREATE USER or ALTER USER statement, then it is recommended to
           always enclose the password in double quotation marks because
           characters other than the double quotation are then allowed.
Error at Line: 2 Column: 1
select trim(ps_scrpt.M_NAME) "Processing Script", trim(actset.M_LABEL) "Batch of table feeders", trim(actset.M_FLTTEMP) "Global Filter", trim(actset.M_TAGDATA) "Label of data",
       trim(scanner_tmpl.M_TEMPLATE) "Scanner Template", trim(bat.M_LABEL) "Table Feeder", trim(feeder_ext.M_OUTPUT) "Reporting Table", trim(feeder_ext.M_MAIN) "M_MAIN", 
       case rep_def.M_TYPE
         when 0 then 'Dynamic Table Based REP table'
         when 1 then 'Data Dictionary Based REP table'
         when 2 then 'SQL Based REP table'
         else 'Unknown Type'
       end as "M_TYPE", 
       trim(rep_dyn.M_DYN_TABLE) "Dynamic Table"
  from ACT_SET_DBF actset, ACT_SETREP_DBF setrep, ACT_BAT_DBF bat, ACT_DYN_DBF feeder_ext, PROCESS#PS_ITEM_DBF ps_item, 
       PROCESS#PS_SCRPT_DBF ps_scrpt, RPO_DMSETUP_TABLE_DBF rep_def, RPO_DMSETUP_DYN_TABLE_DBF rep_dyn, SCANNERCFG_DBF scanner_tmpl
where actset.M_REF = setrep.M_REFSET
   and setrep.M_REFBAT = bat.M_REF
   and bat.M_REF = feeder_ext.M_REF
   and scanner_tmpl.M_REFERENCE (+)= actset.M_SCNTMPL
   and ps_item.M_PARAM_LAB2 (+)= actset.M_LABEL -- '(+)' incase the batch is not attached to a processing script
   and ps_scrpt.M_REF (+)= ps_item.M_REF -- '(+)' incase the batch is not attached to a processing script
   and rep_def.M_LABEL (+)= feeder_ext.M_OUTPUT -- '(+)' incase the feeder/ext does not have a reporting table
   and rep_dyn.M_REFERENCE (+)= rep_def.M_REFERENCE -- '(+)' incase the reporting table does not have a dynamic table
   --and feeder_ext.M_OUTPUT like '%REPORTING_TABLE%' -- reporting table
   --and rep_dyn.M_DYN_TABLE like '%DYN_TABLE%' -- dynamic table
   --and bat.M_LABEL like 'TABLE_FEEDER%' -- table feeder
   and actset.M_LABEL in
(
'E_CS_BF',
'E_DT_BF'
)
I want to get results

While there's nothing visibly wrong, and copying the query from the normal page view doesn't report the same error, if you copy it from the edit view instead the same error comes up.
You can examine that raw code in a hex editor, or use dump('...', 16) to see the characters you actually have. For example, dumping line 2 shows:
select dump('       trim(scanner_tmpl.M_TEMPLATE) "Scanner Template", trim(bat.M_LABEL) "Table Feeder", trim(feeder_ext.M_OUTPUT) "Reporting Table", trim(feeder_ext.M_MAIN) "M_MAIN", ', 16)
from dual;
Typ=96 Len=177: c2,a0,c2,a0,c2,a0,c2,a0,c2,a0,c2,a0,20,74,72,69,6d,28,73,63,61,6e,6e,65,72,5f,74,6d,70,6c,2e,4d,5f,54,45,4d,50,4c,41,54,45,29,20,22,53,63,61,6e,6e,65,72,20,54,65,6d,70,6c,61,74,65,22,2c,20,74,72,69,6d,28,62,61,74,2e,4d,5f,4c,41,42,45,4c,29,20,22,54,61,62,6c,65,20,46,65,65,64,65,72,22,2c,20,74,72,69,6d,28,66,65,65,64,65,72,5f,65,78,74,2e,4d,5f,4f,55,54,50,55,54,29,20,22,52,65,70,6f,72,74,69,6e,67,20,54,61,62,6c,65,22,2c,20,74,72,69,6d,28,66,65,65,64,65,72,5f,65,78,74,2e,4d,5f,4d,41,49,4e,29,20,22,4d,5f,4d,41,49,4e,22,2c,c2,a0
Examining that text shows that you have non-breaking spaces (unicode 00a0, UTF-8 hex c2a0) in quite a few places; six at the start of line 2 (ignoring the four spaces for Markdown formatting), one at the end of that line, six at the start of line 3, eight at the start of line 4, and so on. Those are causing the error, as Oracle isn't interpreting them as plain whitespace, as it would with a normal space or tab or newline.
You may have copied this from some editor that converted normal spaces to non-breaking, or an example that used them for formatting, or you could have typed them yourself though that seems less likely.
You need to either find-and-replace all those characters with a normal space, which you can do in a text editor; or just retype them all. Re-indenting every line would get rid of most of them, but you also need to get rid of the trailing ones on lines 2 and 8.
fiddle, before and after replacing all 88 non-breaking spaces with normal ones. (The 'after' still fails with ORA-00942 of course, as we don't have your tables, but that's fine - the ORA-00911 has gone.) The second line now dumps as:
Typ=96 Len=170: 20,20,20,20,20,20,20,74,72,69,6d,28,73,63,61,6e,6e,65,72,5f,74,6d,70,6c,2e,4d,5f,54,45,4d,50,4c,41,54,45,29,20,22,53,63,61,6e,6e,65,72,20,54,65,6d,70,6c,61,74,65,22,2c,20,74,72,69,6d,28,62,61,74,2e,4d,5f,4c,41,42,45,4c,29,20,22,54,61,62,6c,65,20,46,65,65,64,65,72,22,2c,20,74,72,69,6d,28,66,65,65,64,65,72,5f,65,78,74,2e,4d,5f,4f,55,54,50,55,54,29,20,22,52,65,70,6f,72,74,69,6e,67,20,54,61,62,6c,65,22,2c,20,74,72,69,6d,28,66,65,65,64,65,72,5f,65,78,74,2e,4d,5f,4d,41,49,4e,29,20,22,4d,5f,4d,41,49,4e,22,2c,20

Related

How do I load <file name>.csv.gz from snowflake stage into a snowflake table?

I have successfully loaded 1000 files into a Snowflake stage=MT_STAGE.
Every file has exact same schema.
Every file has exact same naming convention (filename).csv.gz
Every file is about 50 megs (+/- a couple megs).
Every file has between 115k-120k records.
Every file has 184 columns.
I have created a Snowflake table=MT_TABLE.
I keep on getting errors trying to do a "COPY INTO" to move files from stage into a single table.
I've tried countless variations of the command, with & without different options. I've spent 3 days reading documentation and trying to watch videos. I have failed. Can anyone help?
copy into MT_TABLE from #MT_STAGE;
Copy executed with 0 files processed
copy into MT_TABLE from #MT_STAGE (type=csv field_delimiter=”,” skip_header=1);
Syntax error: unexpected '('. (line 1)
copy into MT_TABLE from #MT_STAGE type=csv field_delimiter=”,” skip_header=1;
Syntax error: unexpected '”,'. (line 1)
So as per Mike's statement if there are comma's in your data
col_a
col_b
col c
no comma
one, comma
two,, commas
col_a, col_b, col_b
no comma, one, comma, two,, commas
how can anything tell which is the correct way to know what is in what
col_a
col_b
col c
no comma
one, comma
two,, commas
no comma, one
, comma
two,, commas
no comma
one, comma, two
, commas
no comma, one
, comma, two
, commas
no comma
one, comma, two,
commas
no comma, one
, comma, two,
commas
which is the correct line.
So you ether change the field delimeter from , to pipe | or you quote the data
no comma| one, comma| two,, commas
double quotes
"no comma","one, comma"," two,, commas"
single quotes
'no comma','one, comma',' two,, commas'
The cool thing is, if you change your column delimiter it has to not be in the in the data OR the data has to be quoted.
And if you change to quoting it has to not be in the filed OR it has to be escaped.
OR you can encode as some safe data type like base64 and it takes more space, but now it's transportation transport safe:
bm8gY29tbWE,IG9uZSwgY29tbWE,IHR3bywsIGNvbW1hcw

Error running query in oracle with extended ASCII character (128-255)

I have a query that need to run for SQL,MYSQL,ORACLE,Postgres.Basically I have a list of record where I want to get the record which matches the input pattern when searching.
For example
SELECT * FROM BOOKS WHERE NAME LIKE '%TEST¤_1%' ESCAPE '¤'
(This query is just an example of What I am actually trying to run).
I have used the escape '¤' (ascii code - 164) to escape the wildcard (underscore character) so for example If I search the 1,I would replace the _ character to ¤ so It would give me books containing the name 1 only and not the books containing any character before 1.
It is running fine for mysql,postgres, and sql but in oracle when I run the above query It is throwing the below error on latest version of oracle.
ORA-01425: escape character must be character string of length 1
01425. 00000 - "escape character must be character string of length 1"
*Cause: Given escape character for LIKE is not a character string of
length 1.
*Action: Change it to a character string of length 1.
It is working fine in 11G version of oracle.
Also the NLS_CHARACTERSET for 11G is WE8MSWIN1252 and for latest oracle version is AL32UTF8.
When running below query does give me length 1.
SELECT LENGTH('¤') FROM BOOKS
Do we get the option to enable support for extended ascii code(character code 128-255)) when installing the oracle or Do I need to use any other character to escape the wildcard character(_) If yes what other character Can I use?
Here is one way to do this - using the BEL character, with ASCII value 7.
with
sample_data (name) as (
select 'TWITTER' from dual union all
select 'MY_PHONE' from dual union all
select 'MYOHMY' from dual
)
select name
from sample_data
where name like 'MY' || chr(7) || '_%' escape chr(7)
;
NAME
---------
MY_PHONE
Notice the use of the CHR() function to enter special characters. If you use other mechanisms (keyboard combinations for example, using various special keys) you don't have full control; chr(7) for the BEL character doesn't have that problem.

Accessing a column named Cast in Bigquery

I have a table and one of the columns is named CAST. How can I access this column. I've tried
Select [Cast] AS cast_s FROM tablename without success, Can I use this name or must I reimport all my data into bigquery?
I know that cast is a function. This is the error message:
Error:
Encountered " "CAST" "Cast "" at line 10, column 63. Was expecting: < E O F > (EOF has no spaces, markdown makes it disappear)
Thanks.
The lexical rules for BQ use backticks for this purpose:
select `cast` as cast_s
from tablename;
The documentation is here.
For BigQuery Legacy SQL you CAN use square brackets
SELECT [cast] as cast_s
FROM tablename
From documentation
You can use square brackets to escape reserved words so that you can
use them as field name and aliases. For example, if you have a column
named "prefix", which is a reserved word in BigQuery syntax, the
queries referencing that field will fail with obscure error messages
unless you escape it with square brackets:
SELECT [prefix] FROM ...

Big Query Table Creation Confusion

I have to create a big query table with the schema as follows
snippet:STRING,comment_date:TIMESTAMP
And i have data as follows
"Love both of these brands , but the "" buy a $100k car , get or give a pair of $40 shoes "" message seems .",2015-06-22 00:00:00
"All Givens Best Commercial Ever",2015-06-22 00:00:00
I was confused because both the rows were accepted and were inserted in the table although in the first line all the snippet string is in between the double quotes but it also contains double quotes and comma in between
Why does not big query get confused there ?
When parsing CSV, BigQuery splits only on unquoted commas, and it treats double quotes "" as a single escaped quote character " when encountered inside a quoted string. So your input is valid CSV according to BigQuery.

List of special characters for SQL LIKE clause

What is the complete list of all special characters for a SQL (I'm interested in SQL Server but other's would be good too) LIKE clause?
E.g.
SELECT Name FROM Person WHERE Name LIKE '%Jon%'
SQL Server:
%
_
[specifier] E.g. [a-z]
[^specifier]
ESCAPE clause E.g. %30!%%' ESCAPE '!' will evaluate 30% as true
' characters need to be escaped with ' E.g. they're becomes they''re
MySQL:
% - Any string of zero or more characters.
_ - Any single character
ESCAPE clause E.g. %30!%%' ESCAPE '!' will evaluate 30% as true
Oracle:
% - Any string of zero or more characters.
_ - Any single character
ESCAPE clause E.g. %30!%%' ESCAPE '!' will evaluate 30% as true
Sybase
%
_
[specifier] E.g. [a-z]
[^specifier]
Progress:
% - Any string of zero or more characters.
_ - Any single character
Reference Guide here [PDF]
PostgreSQL:
% - Any string of zero or more characters.
_ - Any single character
ESCAPE clause E.g. %30!%%' ESCAPE '!' will evaluate 30% as true
ANSI SQL92:
%
_
An ESCAPE character only if specified.
PostgreSQL also has the SIMILAR TO operator which adds the following:
[specifier]
[^specifier]
| - either of two alternatives
* - repetition of the previous item zero or more times.
+ - repetition of the previous item one or more times.
() - group items together
The idea is to make this a community Wiki that can become a "One stop shop" for this.
For SQL Server, from http://msdn.microsoft.com/en-us/library/ms179859.aspx :
% Any string of zero or more characters.
WHERE title LIKE '%computer%' finds all book titles with the word 'computer' anywhere in the book title.
_ Any single character.
WHERE au_fname LIKE '_ean' finds all four-letter first names that end with ean (Dean, Sean, and so on).
[ ] Any single character within the specified range ([a-f]) or set ([abcdef]).
WHERE au_lname LIKE '[C-P]arsen' finds author last names ending with arsen and starting with any single character between C and P, for example Carsen, Larsen, Karsen, and so on. In range searches, the characters included in the range may vary depending on the sorting rules of the collation.
[^] Any single character not within the specified range ([^a-f]) or set ([^abcdef]).
WHERE au_lname LIKE 'de[^l]%' all author last names starting with de and where the following letter is not l.
ANSI SQL92:
%
_
an ESCAPE character only if specified.
It is disappointing that many databases do not stick to the standard rules and add extra characters, or incorrectly enable ESCAPE with a default value of ‘\’ when it is missing. Like we don't already have enough trouble with ‘\’!
It's impossible to write DBMS-independent code here, because you don't know what characters you're going to have to escape, and the standard says you can't escape things that don't need to be escaped. (See section 8.5/General Rules/3.a.ii.)
Thank you SQL! gnnn
You should add that you have to add an extra ' to escape an exising ' in SQL Server:
smith's -> smith''s
Sybase :
% : Matches any string of zero or more characters.
_ : Matches a single character.
[specifier] : Brackets enclose ranges or sets, such as [a-f]
or [abcdef].Specifier can take two forms:
rangespec1-rangespec2:
rangespec1 indicates the start of a range of characters.
- is a special character, indicating a range.
rangespec2 indicates the end of a range of characters.
set:
can be composed of any discrete set of values, in any
order, such as [a2bR].The range [a-f], and the
sets [abcdef] and [fcbdae] return the same
set of values.
Specifiers are case-sensitive.
[^specifier] : A caret (^) preceding a specifier indicates
non-inclusion. [^a-f] means "not in the range
a-f"; [^a2bR] means "not a, 2, b, or R."
Potential answer for SQL Server
Interesting I just ran a test using LinqPad with SQL Server which should be just running Linq to SQL underneath and it generates the following SQL statement.
Records
.Where(r => r.Name.Contains("lkjwer--_~[]"))
-- Region Parameters
DECLARE #p0 VarChar(1000) = '%lkjwer--~_~~~[]%'
-- EndRegion
SELECT [t0].[ID], [t0].[Name]
FROM [RECORDS] AS [t0]
WHERE [t0].[Name] LIKE #p0 ESCAPE '~'
So I haven't tested it yet but it looks like potentially the ESCAPE '~' keyword may allow for automatic escaping of a string for use within a like expression.