Getting SQL command not properly ended when creating a db2 sequence - db2

I'm trying to run some DB2 SQL from a tutorial and I keep getting "SQL command not properly ended" for this SQL:
CREATE SEQUENCE mdm_robins80.V_ELATTR_ID_SEQ AS INT START WITH 1000000 INCREMENT BY 1 MINVALUE 1000000 MAXVALUE 1009999 CACHE 10;
I can't see anything wrong with this statement.

Related

Does hbase have similar feature as nextval('sequence_name') provided by postgres db

Is there any feature in hbase to create and use sequence similar to postgres like below
CREATE SEQUENCE:
CREATE SEQUENCE schemaname."SEQUENCE_123456"
INCREMENT BY 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 20
NO CYCLE;
FETCH NextVal of SEQUENCE:
SELECT nextval('SEQUENCE_123456');
For Example if we call SELECT nextval('SEQUENCE_123456') it should return value as 1, if it call for next time it should give 2 and so on...
If not HBase is there any other nosql database which supports this feature.
Tried verifying hbase documentation.

What is the equivalent for NO ORDER of oracle sequence in postgresql?

I have a query
CREATE SEQUENCE "SEQ_ID"
MINVALUE 1
MAXVALUE 99999
INCREMENT BY 1 START WITH 121
CACHE 20
NOORDER
NOCYCLE;
This one is of oracle commands.
Now, I want to convert into a PostgreSQL command.
How do I replace NO ORDER here.
How do I replace NO ORDER here.
Just remove it.
There is no equivalent, and I you probably didn't need (or specify) it in Oracle to begin with.
In Oracle ORDER is only needed in a RAC environment and NOORDER is the default.
So the equivalent would be:
CREATE SEQUENCE seq_id
MINVALUE 1
MAXVALUE 99999
INCREMENT BY 1 START WITH 121
CACHE 20
NO CYCLE;
I removed the double quotes because you should avoid those dreaded quoted identifiers.

Postgres sequence does not reset when deleted and recreated

I have a Postgres sequence defined with the following code -
CREATE SEQUENCE mydb.mytable
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 25
CACHE 1;
I am running this as part of a SQL script on a Postgres 9.5 database.
When I ran the script the first time, the sequence generates integers starting with 1 correctly.
While testing, I dropped the sequence and the table associated with it and re ran the SQL script which re created the sequence. When re created, the sequence is incorrectly generating integers from the last number previously used. Why does it not reset to the minimum value 1 on re create?

PLS-00357 sequence.nextval not allowed

I'm trying to create a trigger and am getting the error "[Error] PLS-00357: PLS-00357: Table, View Or Sequence reference 'table_data_seq.nextval' not allowed in this context"
I have read a lot of information on the error and cannot find the difference between the PL/SQL that people say works and mine. Below is my code for creating the trigger ( keeping it as basic as possible to get it working ):
create or replace trigger tr_tabData
before insert on table_data
for each row
DECLARE
seq_value int;
begin
select table_data_sq.nextval into seq_value from dual;
end;
Oracle version is 10.2.0.5
As requested here it the script for the sequence:
DROP SEQUENCE DATA_ADMIN.TABLE_DATA_SQ;
CREATE SEQUENCE DATA_ADMIN.TABLE_DATA_SQ
START WITH 1000
MAXVALUE 999999999999999999999999999
MINVALUE 1
NOCYCLE
CACHE 20
NOORDER;
This is not possible before 11g. You can use sequence_name.NEXTVAL in regular assignments from 11g not before that, and that by the following:
select TABLE_DATA_SQ.NEXTVAL into :NEW.YourID from dual;
It turned out that this was a bug with the TOAD version and my Oracle database version. The same code in SQL*Plus and SQL Developer worked as expected.

Creating a DB2 sequence with a specific START WITH value

In Oracle we can do it like this:
declare current_max_value NUMBER;
begin select last_number+1 into current_max_value from USER_SEQUENCES where sequence_name = 'HIBERNATE_SEQUENCE';
execute immediate 'CREATE SEQUENCE SEQ__NEW_SEQUENCE MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH '||current_max_value|| ' CACHE 20 NOORDER NOCYCLE';
Is there a DB2 equivalent?
DB2 has vaugely equivalent functionality.
If you just need to generate uninque keys then:-
CREATE TABLE MYTABLE (
GENERATED_KEY BIGINT
GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1, CACHE 100),
MY_DATA VARCHAR(1000) ...........
On the create table statement will accomplish this without too much fuss. Anytime a null value is encountered on an insert an new number will be generated.
If you need an actual sequence number to be used over several tables then:
CREATE SEQUENCE ORG_SEQ
START WITH 1
INCREMENT BY 1
NO MAXVALUE
NO CYCLE
CACHE 24
will define a sequence you then use the "NEXTVAL" keyword anywhere you want the next number in you sql:
NEXTVAL FOR ORG_SEQ
After a great difficulty I was able to figure this out with DB2 syntax and here we go
CREATE PROCEDURE SEQ_NAME
LANGUAGE SQL
DYNAMIC RESULT SETS 1
BEGIN ATOMIC
DECLARE MAX_VAL_NO INTEGER;
SELECT MAX(COL_NAME)+1 INTO MAX_VAL_NO FROM TABLE_NAME;
execute immediate 'CREATE SEQUENCE SEQ_NAME NO MAXVALUE NO CYCLE START WITH '|| MAX_VAL_NO;
END
GO
Could any one tell me why should we use LANGUAGE SQL and DYNAMIC RESULT SETS 1
And what is the syntax used here, frankly speaking I really dont have an Idea but I hit it through trial and error method. Eagerly waiting to know what is the syntax is it either ANSI C or some other.
Appreciate if you could answer this. Also provide some links for good study.(Not regular IBM links)