I have created a sequence but it gives me invalid identifier error. I am running select urc_id_SEQ.nextval from dual;
Rebuild the sequence without using double quotes in the command. If you use double-quotes it makes the name case sensitive and then you must always use double quotes to reference the object. Eliminating the quotes keeps the object name case-insensitive.
CREATE SEQUENCE A.urc_id_SEQ MINVALUE 1 MAXVALUE 9999999999 INCREMENT BY 1 START WITH 1 NOCACHE ORDER NOCYCLE;
Related
This code does not run:
alter table States
add Key varchar(400) character set utf8 not null
The error:
Error in query (1064): Syntax error near 'varchar(400) character set utf8 not null' at line 2
What is wrong in this code?
Key is a reserved keyword in MySql (hence in MariaDB too), so to use it as an identifier you must enclose it in backticks. This will do:
alter table `States` add `Key` varchar(400) character set utf8 not null
I've also enclosed States in backticks, just for the sake of consistency, even though it's not really required.
An option would be to use another name for the new column, so to avoid the same problem in queries involving it afterwards.
I'm trying to create a table and I get the error. Could someone please let me know how to add a column which has an integer starting in its name. Find below the statement and error
Create table mutablecode
(
4th_Procedure_Code varchar(20)
);
Syntax error, expected something like ','
between an integer and the word 'th_Procedure_Code'
A valid object name in Teradata consists of a-z,A-Z,0-9,#,_,$ but must not start with a digit.
If you really need this column name you must double quote it (then almost any character is allowed):
"4th_Procedure_Code" varchar(20)
Remark: According to Standard SQL a double quoted name is case-sensitive, but in Teradata it's still case-insensitive.
I need to replace single quotes in a string of numbers and use in a WHERE IN clause. for example, I have
WHERE Group_ID IN (''4532','3422','1289'')
The criteria within parenthesis is being passed as a parameter, so I have no control over that. I tried using :
WHERE Group_ID IN (REGEXP_REPLACE(''4532','3422','1289'', '[']', ' ',1,0,i))
also tried using OReplace
WHERE Group_ID IN (OReplace(''4532','3422','1289'', '[']', ' '))
but get the same error:
[Teradata Database] [3707] Syntax error, expected something like ','
between a string or a Unicode character literal and the integer '4532'.
Please suggest how to remove the single enclosing quotes or even removing all single quotes should work as well.
The string ''4532','3422','1289'' you are using is incorrect because it contains non-escaped single quotes. This is a syntax error in SQL. In this particular form, no matter what function you use to fix it or which RDBMS you use, it will result in error with standard SQL.
Functions in the SQL cannot fix syntax errors. REGEXP_REPLACE and OReplace never get executed because the query never enters the execution state. It never goes past the SQL syntax parser.
To see the error from perspective of the SQL parser, you may break the string in to multiple parts
'' -- SQL Parser sees this as a starting and ending quote and hence an empty string
4532 -- Now comes what appears to SQL parser as an integer value
',' -- Now this is a pair of quotes containing a single comma
3422 -- Again an integer
',' -- Again a comma
1289 -- Again integer
'' -- Again emtpy string
This amalgam of strings and numbers will not mean anything to the SQL parser and will result in an error.
Fix
The fix is to properly escape the data. Single quotes must be escaped using another preceding single quote. So correct string in this scenario becomes '''4532'',''3422'',''1289'''
Another thing is that the OReplace usage (once syntax is fixed) is like OReplace(yourStringValueHere, '''', ' ')) Observe the usage of escaped single quote here. Two outer quotes are for the string start and end. First inner quote is the escape character and second inner quote is the actual data passed to the function.
I have a table named CASE.
And let's say I have the ff code:
declare
a CASE%rowtype;
begin
null;
end;
The above code will throw the error: PLS-00103: Encountered the symbol "CASE" when expecting one of the following: ...
Is there anyway for me to create a variable of CASE%rowtype without manually creating the datatype itself? Thanks!
as Case is a reserved keyword,
you can escape it with double quotes
a "CASE"%rowtype;
useless to say that you should avoid reserved keywords in object naming... (or not that useless ?)
I know heading is not so clear.This is the picture
I am using &a it is considering it as $a. ,in the output &a and &a. is giving the same output. and why single .(DOT) after &a is giving no error but if we put any character, operator or wild characters after &a gives error.
This is the code.
BEGIN
FOr i in &&a...3 LOOP
DBMS_OUTPUT.PUT_LINE(i||' '||&a.||' '||&a);
END LOOP;
END;
Output Coming
1 1 1
2 1 1
3 1 1
The dot is a delimiter for the & define. In most cases you won't notice a difference, but if you for some reason didn't have whitespace or similar after the variable name it could cause confusion. For example, if you were concatenating something with your variable in a string, '&asomething', it would ask for a variable named 'asomething'. If you did it as '&a.something' then it would ask for a variable named 'a' and tack 'something' on the end of whatever value is supplied. Any other character after the &a would be treated as either part of the variable name or would cause an error if it isn't valid as part of the name.