Query of the sequence
Is it possible to change sequence value on monthly basis.
ex. I want to start sequence from 1to 1000 and then reset from 1 to 1000 after month.
for every month i want to reset sequence is it possible.
Thanks in advance
Hi,
I agree with Gj. I think you should use dbms_scheduler to do this at the beginning of every month.
I don't like the idea of dropping and re-creating the sequence. You'll lose grants, and procedures that reference the sequence will become invalid.
You can't alter the actual value of the sequence, but you can temporarily alter the INCREMENT BY value to get the same result, as shown in the script below:
PROMPT ========== reset_seq procedure ==========
CREATE OR REPLACE PROCEDURE reset_seq
( in_seq_name IN VARCHAR2 -- Name of sequence to be reset
, in_new_val IN NUMBER := 1 -- Bew value
AUTHID CURRENT_USER
AS
-- reset_seq changes the value of the given sequence.
-- This assumes:
-- (a) no one else will use the sequence while this is running
-- (b) the INCREMENT BY value of the sequence is 1
-- (c) the MINVALUE value of the sequence is less than in_new_val
-- A little extra coding can fix (b) and (c)
current_val PLS_INTEGER;
get_txt VARCHAR2 (1000) := 'SELECT ' || in_seq_name || '.NEXTVAL'
|| ' FROM dual';
set_txt VARCHAR2 (1000) := 'ALTER SEQUENCE ' || in_seq_name
|| ' INCREMENT BY ';
BEGIN
EXECUTE IMMEDIATE get_txt INTO current_val;
EXECUTE IMMEDIATE set_txt || TO_CHAR (FLOOR ((in_new_val - 1) - current_val));
EXECUTE IMMEDIATE get_txt INTO current_val;
EXECUTE IMMEDIATE set_txt || '1';
END reset_seq
SHOW ERRORS
PROMPT ========== Creating sequence ==========
DROP SEQUENCE x_seq;
CREATE SEQUENCE x_seq
MINVALUE 0
NOCACHE
START WITH 1;
PROMPT ========== Using some values ==========
SELECT x_seq.NEXTVAL
FROM dual
CONNECT BY LEVEL <= 5;
PROMPT ========== Re-setting sequence ==========
EXECUTE reset_seq ('x_seq');
SELECT x_seq.NEXTVAL AS new_improved
FROM dual;The first two steps (creating the reset_seq procedure and creating the sequence) are done once, for all time.
The next step "using some value" simulates your normal work during the month.
At the beginning of every month, call reset_seq, as shown.
Similar Messages
-
How to write a query for grouping them the columns and give the sequence order to each group/
Hi i have table that contains country columns .
India,USA,UK like these when ever the group changed into the differt country i make a group and arrange them the sequence into those Countries
like below
1)India
2)India
1)USA
2)USA
like these to write a query ..........pls help me for this queryAssuming you're using SQL Server you can ask here:
http://www.sqlteam.com/forums/forum.asp?FORUM_ID=23
Otherwise, please ask in the relevant forum for the type of technology you're using.
Basically it's either:
select *
from [table name]
order by country
If you want to do something with groups do something like:
select (max) income, country
from [table name]
group by country
Kind regards,
Margriet Bruggeman
Lois & Clark IT Services
web site: http://www.loisandclark.eu
blog: http://www.sharepointdragons.com -
I seem to be missing something in how the various version numbers are supposed to be used. My end goal is to log and possibly display in the UI the version of the sequence and which installer version was used to inspect a UUT. I have gotten most of the way there using:
How Can I Programmatically Query the Sequence File Version of My TestStand Sequence?
and logging this into the report with a function which contains:
Parameters.UUT.AdditionalData.SetValString("Test Version",1,RunState.SequenceFile.Data.Version),
Parameters.UUT.AdditionalData.SetFlags("",0,PropFlags_IncludeInReport)
The "Deployment Version" in the TestStand Deployment Utility auto incrementing the 3rd position of a version number while the sequence auto increment is working on the 4th.
My first question is are these 2 version numbers in anyway supposed to be related to each other? As it seems to me you would want those 2 reversed, I can make several installers based on sequence version X, making changes to what supporting files are also installed.
If they are not related as I suspect that they are not. How do I programatically grabed the installer version and also log that into the result report?
is there an option to perform a custom deployment build step to log the deployment version before it builds and then reference that log at runtime of the test?Hi,
The sequence file version and deployment versions are not related.
You can build the installer with whatever version you want using the command line :
https://decibel.ni.com/content/docs/DOC-38947
Hope this helps,
Ravi -
How to maintain the sequence in the custom table
Hi,
We have custom table where we will store the standard text name based on different flags and it will be fetched the value according to the condition.
Example code
SELECT SINGLE field1
field2
INTO ( vaiable1 variable2 )
FROM custom table
WHERE tdobject = iv_signature
AND bukrs = vbdkr-bukrs
AND vkorg = iv_vkorg
AND vkbur = iv_vkbur
AND lland = vbdkr-land1
AND fkart = vbdkr-fkart
AND kschl = iv_kschl.
CHECK sy-subrc <> 0.
SELECT SINGLE field1
field2
INTO ( vaiable1 variable2 )
FROM custom table
WHERE tdobject = iv_signature
AND vkorg = iv_vkorg
AND vkbur = space
AND fkart = vbdkr-fkart
AND kschl = iv_kschl.
CHECK sy-subrc <> 0.
SELECT SINGLE field1
field2
INTO ( vaiable1 variable2 )
FROM custom table
WHERE tdobject = iv_signature
AND vkorg = iv_vkorg
AND vkbur = space
AND fkart = vbdkr-fkart
AND kschl = space.
The solution I created to avoid the select is, i have created the FM with all parameter. Addition to the FM, I have created a Table as well to maintain the flag.
New table
TDOBJECT TDID BUKRS VKORG VKBUR KUNNR MWSKZ AUART VGBEL_AUART KTGRM LLAND FKART WERKS KSCHL STNAME
FOOTER X X ZNET_DICI_FTR_FI
FOOTER X X ZNET_DICI_FTR_NL
FOOTER X X X
i.e. say example if we maintain the value in the custom table based on the first select query. Then we need to maintain the flag in the table which was created newly.
Note In the both field the key fields are same.
The problem now is we have plenty of select query for different condition, i though of maintain the sequences of the entries. But my worry is how many sequence number will be maintained and in what bases it will be maintained.
Could you please help me to resolve this problem?
Regards,
VijayHi,
I got your requirement as,
whenever a new entry is made in the table, one sequence has to be maintained somethign like serial number and everytime it has to be incremented. If it is so, then you can go for an additional field as serial number. Then get the max serial number from the following select query:
select max(serial) from cust_table
into v_serial.
Now, when you make a new entry, just give (v_serial + 1) to serial number...
Please let me know if i understood wrongly... or what you want... -
Get the Table name by providing the Sequence name
Hello,
I wish to retrieve the table name to which the sequence is related.
I understand that when the sequence was created, no reference is mentioned to any table. The sequence may be used across many tables.
But the DB definitely knows internally how many tables are referencing the particular sequence.
So, can anyone help me in finding the table (or all tables) referencing one particular sequence.
Thanks and Regards
(Please treat this as urgent as i am desperately in need of such a query)I share Adrian's scepticism. Using the data dictionary we could find all the program units - TRIGGERS, TYPES, PROCEDURES, etc - which use the sequence. From there we can find all the TABLES that are also referenced by those programs. And that's as good as it gets in Oracle. We cannot definitely say which tables use which sequences (although a good naming convention helps).
Of course, your DBA may have access to some accurate and up-to-date documentation. But that is maintained externally to the database and not derived from it.
Cheers, APC -
Find the sequence name for a particular table
Hi,
Please give query to find the sequence name for a particular table in oracle.
ThanksI mean getting List of Sequence names defined in DB.
I got the answers
select *from user_sequences -
How an INDEX of a Table got selected when a SELECT query hits the Database
Hi All,
How an Index got selected when a SELECT query hits the Database Table.
My SELECT query is as ahown below.
SELECT ebeln ebelp matnr FROM ekpo
APPENDING TABLE i_ebeln
FOR ALL ENTRIES IN i_mara_01
WHERE werks = p_werks AND
matnr = i_mara_01-matnr AND
bstyp EQ 'F' AND
loekz IN (' ' , 'S') AND
elikz = ' ' AND
ebeln IN s_ebeln AND
pstyp IN ('0' , '3') AND
knttp = ' ' AND
ko_prctr IN r_prctr AND
retpo = ''.
The fields in the INDEX of the Table EKPO should be in the same sequence as in the WHERE clasuse?
Regards,
VijiHi,
You minimize the size of the result set by using the WHERE and HAVING clauses. To increase the efficiency of these clauses, you should formulate them to fit with the database table indexes.
Database Indexes
Indexes speed up data selection from the database. They consist of selected fields of a table, of which a copy is then made in sorted order. If you specify the index fields correctly in a condition in the WHERE or HAVING clause, the system only searches part of the index (index range scan).
The primary index is always created automatically in the R/3 System. It consists of the primary key fields of the database table. This means that for each combination of fields in the index, there is a maximum of one line in the table. This kind of index is also known as UNIQUE. If you cannot use the primary index to determine the result set because, for example, none of the primary index fields occur in the WHERE or HAVING clause, the system searches through the entire table (full table scan). For this case, you can create secondary indexes, which can restrict the number of table entries searched to form the result set.
reference : help.sap.com
thanx. -
Creating variables/parameters from a code module that persist when the sequence is over
I am creating variables/parameters programmatically in a code module (C#) by passing in the Locals object and calling the method 'NewSubProperty'.
I've also tried SetValNumber with PropOption_InsertIfMissing.
But it seems they are only being created in that instance of the sequence, because they are gone when the sequence is over. I really wanted them to persist.
I wanted to avoid creating station globals dynamically like this, but maybe that's all I can do to make them last.
Any ideas would be gratefully appreciated.
Thanks,
Ronnie
TestStand 4.2.1, LabVIEW 2009, LabWindows/CVI 2009
Solved!
Go to Solution.Hi,
Check out the links on this response
http://forums.ni.com/ni/board/message?board.id=330&message.id=11226&query.id=267719#M11226
It maybe of help
Regards
Ray Farmer
Regards
Ray Farmer -
Setting the sequence of asset listeners
Hi All,
We have about 10 asset listeners and would like to have them execute in a specific sequence. I have contacted Fatwire Support and I got the standard answer:
"There is no documented way to specify ordering of asset listeners. If order of asset listeners is a concern, you could put all the asset listener code into one asset listener"
Obviously, putting all the listener code into a single listener is less than ideal. I'd like to know if any of you have been able to find a way of reliably setting the sequence in which the asset listeners are executed.
We tried the obvious approaches of ordering the listeners in our AssetListener_reg table using ID, insert order, etc but they have not proved reliable.
One option we are considering is to write a single listener that is responsible for invoking the existing listeners rather than rely on Fatwire to do this.
So, if we don't have to write custom code to do the obvious, I'd like to know what has worked for others.
Thanks,
--Adi.Hi,
Sadly the queries that retrieve listeners from the listener tables don't specify an ordering, e.g.:
select id from AssetListener_reg where listener = ...
select listener from AssetListener_reg where blocking = ...
In Oracle DB there is no way to reliably predict or influence the ordering that comes back from a query, except by using an explicit ORDER BY. See http://stackoverflow.com/questions/899514/default-row-ordering-for-select-query-in-oracle for more description on that.
It does seem like it could be useful to determine the order so I have logged enhancement request 16998818 "ALLOW FOR ORDERING OF ASSET LISTENER EXECUTION" for this.
Regards,
Phil -
Insert the sequence number in table
Hi..i created one table and i want to insert the sequence num in one column using sql query is it possible? please help me
Try this..
SQL> create table t1(x number);
Table created.
SQL> create sequence seq_x;
Sequence created.
SQL> insert into t1 values(seq_x.nextval);
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> commit;
Commit complete.
SQL> select * from t1;
X
1
2
3
4 -
Find the SEQUENCE created by an IDENTITY column
Hello,
Seems that Oracle 12c introduces IDENTITY columns based on SEQUENCES that are created automatically...
The sequence gets a name like ISEQ$$_<number>
I was wondering if it's possible to find the name of the sequence created for a given table.
We need that to query the last generated number, by doing:
select <seqname>.currval from dual
Or is there another way to find the last generated number for the current SQL session???
Thanks!
Seb
SQL> create table t1 ( key integer generated by default as identity, c char(10) );
Table created.
SQL> select sequence_name from all_sequences where sequence_name like 'ISEQ%';
SEQUENCE_NAME
ISEQ$$_93989
ISEQ$$_93991
ISEQ$$_93993
ISEQ$$_93995
ISEQ$$_93997
ISEQ$$_94107
6 rows selected.AlbertoFaenza wrote:
The sequence used can be found in the DATA_DEFAULT column of ALL_TAB_COLUMNS where IDENTITY_COLUMN = YES.
Yes, this is simplest way. But just FYI, 12C has a new data dictionary table SYS.IDNSEQ$ which ties identity column to a sequence. I'll use same table t1 as in this post:
SQL> select data_default
2 from user_tab_columns
3 where table_name = 'T1'
4 and column_name = 'KEY'
5 /
DATA_DEFAULT
"SCOTT"."ISEQ$$_91684".nextval
SQL> select s.object_name sequence_name
2 from user_objects s,
3 user_objects o,
4 user_tab_columns c,
5 sys.idnseq$ i
6 where o.object_name = 'T1'
7 and c.table_name = o.object_name
8 and c.column_name = 'KEY'
9 and i.obj# = o.object_id
10 and i.intcol# = c.column_id
11 and s.object_id = i.seqobj#
12 /
SEQUENCE_NAME
ISEQ$$_91684
SQL>
SY. -
Retrieve the sequence number just used in the insert
Hi All, is there a way to use the sequence.nextval for an insert and return the sequence value in one call?
We need to port our application from MS SQLServer to Oracle. The tables in SQLServer have Identity columns as the primary key. We can do the insert and retrieve the identity column value with one call to the database. I wonder if we can do the similar thing with Oracle.
I found out that there is a "returning into" clause for an insert statement that can return information on the current row, something like: insert into tbl (id, name) values (seq.nextval, 'name') returning id into my_id. I can't get the above query to work.
Any help is greatly appreciated.
XiaoyunHi Tim,
To avoid this problem you can do one thing. If you are quering the database from java, place both the commands in a synchronised block as follows:
synchronized(this){
This will allow only one user to enter the block and hence helps to retrieve the same value.
The same procedure is followed in Survey Sample located at
http://otn.oracle.com/sample_code/tech/xml/xmldb/content.html
Have a look at that. Check the saveChoiceGroups method in ChoiceGroupCache.java
Regards,
Anupama -
Help-how can i see the sequence in the table?
Hi, i created sequence for the table. but how can i view the sequence as a column in the table? like the sequence started with 1 and increment by 1. how can i make it available as a column in the table? thanks a lot for anyone's prompt reply. much appreciated.
eg.
Create table:
create table t1 (
id number(10),
col1 varchar(2)
Create sequence:
CREATE SEQUENCE "PEMARTEN"."T1_ID" NOCYCLE NOORDER CACHE 20 NOMAXVALUE MINVALUE 1 INCREMENT BY 1 START WITH 1
You can do 2 things:
Use the sequence in your insert query:
eg.
insert into t1 (id, col1) values (t1_id.nextval, 'example');
OR
Create a before insert trigger (prefered):
CREATE OR REPLACE TRIGGER "PEMARTEN"."BI_T1" BEFORE INSERT ON "PEMARTEN"."T1"
REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
DECLARE
new_id number;
BEGIN
SELECT t1_id.nextval
INTO new_id
FROM dual;
:new.id := new_id;
END;
Now you can just insert data:
insert into t1 (col1) values ('example');
sequence.nextval increments the sequence and returns the next value
sequence.currval returns the current value of a sequence
I hope that helps.
Kind regards,
Pieter -
Is there a way to create a renaming preset where the sequence starts at the number "0" zero?
What I am trying to achieve is the following:
Fro example, I am photographing a handbag and I need to rename the file using a barcode and a barcode scanner.
My sequence of images goes like this:
Image 1: Tag shot
Image 2: Front
Image 3: Back
Image 4: Inside bag
Let's say the barcode once scanned produces a code such as TRE8801AZT16-Z
Right now my current preset is "Custom Text_Image # (1)"
This results with the images being renamed as:
TagShot: TRE8801AST16-Z_1
Front: TRE8801AST16-Z_2
Back: TRE8801AST16-Z_3
Inside bag: TRE8801AST16-Z_4
What I need is the sequence to start at zero so the tag shot is _0 and my images are named like this:
TagShot: TRE8801AST16-Z_0
Front: TRE8801AST16-Z_1
Back: TRE8801AST16-Z_2
Inside bag: TRE8801AST16-Z_3
Is this possible? If yes, how?
Thanks for the help
CodyAbout as close as you can get is to right-click on a single clip and Make Multiclip Sequence. Hit OK to make an sequence out of the single clip. Open the sequence made and delete the multiclip and edit the clip you want back into the sequence.
-
I can not play the sequence in preview mode. How do I fix this issue?
Each frame loads in the preview window when highlighted, but I can not play the sequence.
I am working on a project for school. I have been draging clips down to the timeline and matching it with a few voice overs. Nothing too complex. I have been previewing my work as I go by pressing the space bar, Im not sure what I did but now Premiere will not play the preview in the Program sequence window.
Maybe you are looking for
-
Classic Report totals on all pages?
I've been using APEX (4.0.1) for about a week, & I'm generally loving it, but the question in the subject has me stumped despite half a day of Googling. The built-in totals (selecting 'sum' on the columns) are all well & good, but I need them to appe
-
Performance tuning in 11g for said query
Hello, I have the below query which needs to be tuned: SELECT DISTINCT a.emplid , a.upa_fiscal_year , b.balance_period , 0 , a.descr , a.UPA_CURRENT_AMT , a.UPA_CURRENT_AMT2 , a.UPA_CURRENT_AMT3 , a.UPA_CURRENT_AMT4 FROM ps_upa_eq_incal_vw a , ps
-
Hi Exports, PI7.0 My scinario is File to Mail. This is simple one pick the .txt format file and send with attachement by mail. We do not have any design objects by using Integration Repository. We confirgured with Integration directory direclty. In
-
I am looking into purchasing an external blu-ray burner. One thing the company told me whose product I am interested in is If I want the Blu-ray to play back on a normal Blu-ray player connected to a TV, like a typical commercial film on a Blu-ray di
-
Hi Folks, I am trying to create Standard Purchase Order. I have given todays date as Delivery Date. I am getting Error "Deliv. date outside period covered by factory calendar US" on clicking Save button. Calender 'US' is assigned to the Receivi