SQL command not properly ended error : Error: ORA-00933 - sql

Here is the query i am trying to execute..
CREATE SEQUENCE "GARY"."TABL_PROD_DWH_SEQ"
MINVALUE 1 MAXVALUE 99999999999999999999999999999999
INCREMENT BY 1 START WITH 21 CACHE 20 NOORDER NOCYCLE NOPARTITION;
Error starting at line : 1 in command -
CREATE SEQUENCE "GARY"."TABL_PROD_DWH_SEQ"
MINVALUE 1 MAXVALUE 99999999999999999999999999999999
INCREMENT BY 1 START WITH 21 CACHE 20 NOORDER NOCYCLE NOPARTITION;
Error report -
SQL Error: ORA-00933: SQL command not properly ended 00933. 00000 - "SQL command not properly ended"
'Cause:
'Action:

What version of Oracle are you using? NOPARTITION doesn't ring a bell. It might only be available on more recent versions.
You can also use NOMAXVALUE. That seems more intuitive than your arbitrary value.

Explanaton
Please see the following question/answer: Oracle 12.2 - Replacement of NOPARTITION feature
Your problem is NOPARTITION.
It is a non-documented unsupported feature after a version of Oracle (I think 12).
Also see: https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:9523071800346490539
Test
http://sqlfiddle.com/#!4/1afa88 (Oracle 11g R2)
The below does work:
CREATE SEQUENCE "TABL_PROD_DWH_SEQ"
MINVALUE 1 MAXVALUE 99999999999999999999999999999999
INCREMENT BY 1 START WITH 21 CACHE 20
NOORDER NOCYCLE
;

You've already been told most of the things. Let me add a few more words.
Your problem looks like the one that happens when people use parameters they don't quite understand. I apologize if I sound impolite, but - that's my impression. Why? Because of the look of that CREATE SEQUENCE statement.
No living person I know has ever manually written it
using double quotes around uppercase owner and sequence name,
nor have they used such a MAXVALUE (heck, it is indefinite anyway),
nor they want to explicitly remind Oracle that default increment is 1,
as well as cache (which is 20 by default)
not to mention other options that are default anyway
Apart from start with, everything else is default anyway so you could have used
SQL> create sequence tabl_prod_dwh_seq start with 21;
Sequence created.
SQL> select tabl_prod_dwh_seq.nextval from dual;
NEXTVAL
----------
21
SQL> select tabl_prod_dwh_seq.nextval from dual;
NEXTVAL
----------
22
SQL>
and get the same result. So ... have a look at documentation related to your database version, try to follow it, don't do what's not allowed (or undocumented), keep it as simple as possible and you'll be good.

Related

Problem on creating postgres stored procedure | Postgres 12

I'm kinda new on Postgres, so I need your help for this one.
postgres=# select version();
version
------------------------------------------------------------
PostgreSQL 12.3, compiled by Visual C++ build 1914, 64-bit
(1 row)
1. CREATE PROCEDURE test (INT,varchar(200))
2. LANGUAGE plpgsql
3. AS $$
4. BEGIN
5.
6. create table test1 as
7. select id,name from mst_user_mobile limit 5
8.
9. COMMIT;
10. END;
11. $$;
From what I read, Postgres version above 10, support PROCEDURE method. But when I execute the code it always error on line 1 (on word PROCEDURE)
here error that i got:
ERROR: syntax error at or near "PROCEDURE"
LINE 1: CREATE PROCEDURE test (INT,varchar(200))
^
SQL state: 42601
Character: 8
any helps are welcome
You report to be using Postgres 12.3. Yet, the reported error message is exactly what I see in Postgres 10 (or older):
ERROR: syntax error at or near "PROCEDURE"
LINE 1: CREATE PROCEDURE test (INT,varchar(200))
db<>fiddle here
CREATE PROCEDURE was introduced with Postgres 11.
I suspect you are connected to the wrong / a different database.
All that aside, your example could just be a function. The COMMIT is pointless as last command. See:
In PostgreSQL, what is the difference between a “Stored Procedure” and other types of functions?
Or, it's another missing semicolon before the CREATE PROCEDURE command. (You show another one of those in the question.) I can reproduce the error message this way, too:
db<>fiddle here
I guess the problem are the ; on END and the last $$. You shouldn't use them in this cases!

Alter sequence .nextval in Oracle SQL 11 with prepared statement

I'm trying to advance a sequence by a negative number but I keep getting the following error:
ORA-02286: no options specified for ALTER SEQUENCE
So far no amount of Googling has helped. The statement that I use is
ALTER SEQUENCE %s.nextval INCREMENT BY ?
The sequence name is generally schema.table_name_seq. Including the schema name is unavoidable because the connection is not necessarily to the same one.
Appending an inconsequential option like minvalue 1 did nothing to satisfy it either.
My second attempt was to drop .nextval from the query and run ALTER directly on the sequence (just throwing stuff at the wall to see what sticks at this point), ie:
ALTER SEQUENCE %s INCREMENT BY ?
which results in
ORA-01722: invalid number
Next I supplied a positive integer and negated it in the query (INCREMENT BY -?) which produced the same error. The query is prepared as such:
num = -1 * Math.abs(num);
stmt = conn.prepareStatement(sql);
stmt.setLong(1, num); //also tried setInt()
stmt.execute();
The idea is to set the .nextval sequence for a given table back to an arbitrary number (but always more than minval).
JustinCave's comment was most illuminating:
alter sequence is DDL. You cannot use bind variables in DDL. You would need to dynamically build the DDL statement you want and execute that and it wouldn't make sense to use a PreparedStatement to do so.
Recognizing that there are better ways to do it, but acknowledging time constraints, I constructed the following SQL statement:
ALTER SEQUENCE %s INCREMENT BY %d
which works like a charm. Yes, the number to advance by is hardcoded in each request. Not the best solution but I cannot create stored procedures at this point, so it'll have to do.
Thank you Justin.

How this CREATE statement is parsed by sqlplus?

I saw some CREATE statements I never thought could be parsed by SQLPLUS:
plus#PDB1> #create
2 or
3 replace procedure p as
4 begin
5 null;
6 end;
7 /
Procedure created.
plus#PDB1> #create
2 table t3(x int);
Table created.
So how the pound signs (#) were parsed here ? I cannot find any documentation for this. If there is a documentation to it, point me there.
This is the SQLPREFIX character. The manual describes it:
While you are entering a SQL command or PL/SQL block, you can enter a SQL*Plus command on a separate line, prefixed by the SQL*Plus prefix character. SQL*Plus will execute the command immediately without affecting the SQL command or PL/SQL block that you are entering.
An example use case of running a SQL*Plus® command inside a SQL command:
SQL> SELECT *
# show release
release 1102000200
FROM dual;
D
-
X
While you would usually use this to run something immediately inside a larger command, since you can use it anywhere, you can actually use it on its own too.
SQL> # SELECT * FROM dual;
D
-
X

Can't load an SQL dump into Oracle 11g

I was given an SQL dump from an Oracle 11g database. It contains all of the statements to reproduce the database. Unfortunately, it fails at the very first one
CREATE SEQUENCE "XXX"."YYY"
INCREMENT BY 1
START WITH 129004
MAXVALUE 1000000000000000000000000000
NOMINVALUE
NOCYCLE
CACHE 20
NOORDER
GO
With the error SQL command not properly ended. If I throw out the GO at the end, the error user or role '' does not exist. What am I doing wrong? I tried this both in sqlplus command line client and in Oracle SQL developer.
Needless to say, I'm very new to Oracle, so please be easy on me :D.

Oracle 10gR2 trigger error

I have Oracle 10gR2. I am trying to create autoincrement trigger.
Here is the sample:
CREATE SEQUENCE TEST_SEQ
INCREMENT BY 1
START WITH 1
NOMAXVALUE
/
CREATE TABLE TESTER (
ID_TESTER INTEGER NOT NULL,
VAL VARCHAR2(20) NOT NULL
)
/
CREATE OR REPLACE TRIGGER TIB_TESTER BEFORE INSERT
ON TESTER FOR EACH ROW
BEGIN
SELECT TEST_SEQ.NEXTVAL
INTO :NEW.ID_TESTER
FROM DUAL;
END;
/
Trigger creation gives warning:
warning : ORA-24344: success with
compilation error
And when I get error value:
select OCI_SUCCESS_WITH_INFO;
/
It gives error:
error : ORA-00923: FROM keyword not
found where expected
What client are you using to issue these commands? ORA-24344 is a perculiar error.
In SQL*PLus we can get more information about compilation errors like this:
SQL> show errors
As for the ORA-00923 error, that is because in Oracle's version of SQL we always have to select from a table. So you should execute
select OCI_SUCCESS_WITH_INFO
from dual
/
I'm not sure how much sense that makes, but at least you won't get the error.
"It was Navicat problem"
That doesn't surprise me, as I ran your code against my database and it built without a hitch.
Maybe it will be useful for somebody:
If you are using Oracle 10g and OCI driver, ORA-24344 shows when trigger have carriage return sign (\r) in code eg. file was created with Windows end of line style.