SQL & PL/SQL :: Number Sequence At Row Level Like ROWNUM
Jun 1, 2010
I have a result set with three columns as 'Product Category', 'Product' & 'QtySales' and 10 rows, sorted in the order Product Category, Product. This means, a product category will have one or more products under it.
Now i want to add a fourth column to my result set, which should display a incremental number sequence from starting from 1, 2, 3.. for each row. Also when the value of the Product Category (1st column) changes, this sequence should be restarted again from 1.
I'm on Oracle Database 10g Enterprise Edition Release 10.2.0.4.0
I am working on a project where have lots of view on a different schema. For performance reasons, we create tables on those views and index them.
The application that uses these tables requires a numeric primary key of a specific length, e.g. number(10). Not all tables have a natural key that matches this requirement, so I added a rownum to the query. I had hoped that casting the rownum to a number(10) would result in the same datatype once the table is created.
e.g. SQL> create or replace view rownum_to_number10_vw as 2 select cast(rownum as number(10)) objectid, dummy from dual;
View created
SQL> describe rownum_to_number10_vw; Name Type Nullable Default Comments -------- ---------------- -------- ------- -------- OBJECTID NUMBER(10) Y DUMMY VARCHAR2(1 BYTE) Y
SQL> perfect! Now create a table based on this view:
SQL> create table rownum_to_number10_tb as 2 select * from rownum_to_number10_vw;
Table created
SQL> describe rownum_to_number10_tb; Name Type Nullable Default Comments -------- ---------------- -------- ------- -------- OBJECTID NUMBER Y DUMMY VARCHAR2(1 BYTE) Y Oracle does not pick up on the number(10) cast!
How can I force Oracle to create a column with the same datetype as the underlying query?
ps:I know that the 10 in number(10) is more like a constraint than a datatype, but the application that uses this table will create an additional column if the datatype > 10. I want to prevent that from happening...
I have the following select query that works perfectly fine. Returns 25 rows based on the descending order of the price.But, I want add one more expression to this list of columns in this query (apart from customer_id).
the expression should look like Cust-01 for the first customer from the below query all the way to Cust-25 for the last customer.But how can I can generate 01 to 25 in oracle?
select customer_id from (select customer_id from capitalPLAN where member_status = 'MEMBER' AND customer_id NOT in ('156','201','1385','2125','3906','165') order by price desc ) where rownum <= 25
In our production, we have two nodes in the cluster. We use the sequence for one of the main table for primary key. Our application is expecting sequence number increments along with created date time stamp. Right now sequences are cached for each node and it creates problem for the application. We would not like to use NOCACHE option because it causes performance issue.
This is the current scenario -
Transaction #1 on Node 1 - Seq ID 1 - Time Stamp 12:01 Transaction #2 on Node 2 - Seq ID 51 - Time Stamp 12:02 Transaction #3 on Node 1 - Seq ID 2 - Time Stamp 12:03
When I try to query based on the time stamp, primary should also go up. To be very clear on what I would like to have, please consider the following example.Without using NOCACHE option, I need to have the data in the following order.
Transaction #1 on Node 1 - Seq ID 1 - Time Stamp 12:01 Transaction #2 on Node 2 - Seq ID 2 - Time Stamp 12:02 Transaction #3 on Node 1 - Seq ID 3 - Time Stamp 12:03
In other words, sequence number should always increment along with the time.
I have a following select statement where I am not generating a sequence in any of these WHERE clause, GROUP BY or ORDER BY clause, DISTINCT clause, along with a UNION or INTERSECT or MINUS or sub-query.
I have query like this
"SELECT AER_ID_TEMP.AER_ID, AER_ID_TEMP.D__PRNO, AER_ID_TEMP.D__PCNT, CAST((select char_value from aris_param_data where param_id = 101)||seq_record_id.nextval AS INT) as RECORD_ID FROM AER_ID_TEMP"
but still encountering a error "ORA-02287 sequence number not allowed"
CREATE OR REPLACE TRIGGER audit_emp AFTER INSERT OR UPDATE OR DELETE ON Employee FOR EACH ROW declare my emp_audit%ROWTYPE; begin if inserting then my.action := 'I'; [code].......
It works alright but i need to enter a sequenced value to a column audit_id which is a column in the emp_audit table when a change takes place, but when i define the variable it gives be an error as bad bind variable so where can i define this column in this trigger so get a sequenced value every time i d or u occurs .
Is there any way to get the last Sequence Number generated regardless the Sequence name? Something like dbinfo('sqlca.sqlerrd1') within Informix?
Imagine I have 2 sequences. Imagine that I run both several times until 20:00 hours. Imagine that at 21:00 hours I would like to know what was the last generated number created by any of the sequences. I don't wann know wich sequence generated the last NEXTVAL, I only want to know the value of the last NEXTVAL used.
Is it possible without mentionating the Sequence name?
I am facing issue with my sequence number about sequence number generated..I want it to follow the sequence all the time, i.e. it should take next incremental number to last generated seauence, but it generates random one all the time, i.e
I have a table ABC with two columns NAME and SEQUENCE. The valid values of sequence are from 1..50. The table may not have all the Sequence number. For example following is the data in my table..
Basically I want to have rows for the sequence numbers which are not present i my table. I thought of using the following query to generate a sequence and then join, but does not work.
select rownum from dual connect by rownum <=50
I tried something like
with temp as (select name, sequence from abc where supp_ref_order is not null order by sequence ) select rownum as num, temp.name from dual, temp connect by rownum <=50 where temp.sequence =num
I need generate an unique number without sequence. I am using Oracle 11.2, here is the details. The column idSeq is unique withing one specific idType. I don't want a sequence for each idType.
create sequence seq minvalue 1 maxvalue 99999 start with 1 increment by 1; create table t ( id number, b date); insert into t values (seq.nextval,sysdate); update t set b=sysdate-1 where id=seq.currval; update t set b=sysdate-1 where id=seq.currval * ERROR at line 1: ORA-02287: sequence number not allowed here
Name _____ Smith Street Smith Street John Street Ed Street Ed Street Ed Street
and need to assign sequence numbers only when the record (Name) changes, e.g. :
Name Seq _____ ____ Smith Street 1 Smith Street 1 John Street 2 Ed Street 3 Ed Street 3 Ed Street 3
I have experimented with row_number partition but then i just get the sequence returning to 1 when the name value changes.
If I grouped the records by Name I would like to have unique, sequential numbers: 1, 2, 3 but where there is the same name I would like the sequence to stop and the number to replicate?
i want to get serial numbers in oracle forms. i have one data block with 10 rows and a non database display item with corresponding length as that of the original data block .
when ever i am executing the form i want to see the serial number generated in the display item and when i inserted a new item or row it should show the corresponding rownum.
eg:
empno name serialno 5 tom 1 4 tinil 2 6 sofy 3 7 john 4 1 albert 5 2 michel 6
I have a CSV file with 100 records and one of the column as FILE_ID. I want to load one unique number for all 100 recs not for every records.
suppose my sequence returns 3 as next val i want to load 3 for all 100 records. How to implement this in control file or sh file . I am using shell script to call sqlldr.
My problem, I have the query which works correctly. However as you can see there is always a sequence number in the end of variables and I am not sure the total number of cases, so I have to create a loop for the same query.
I am doing the same things on BREINV1 BREINV2 BREINV3 BREINV4... AND BRENUMINV1 BRENUMINV2... so the sequence should add a number in the end of variables...
I have a table called table 1 and I am trying to insert a few values in this table and i am constantly getting bogged down by a primary key error. Strange thing is this primary key called "ID" on the table is a system generated sequence value number. The error is
why the error is coming up and any way to resolve it. I checked the max sequence number value and kept running it for a while and then tried to run my insert statement but no luck yet.
I am switching database from access to oracle 11g. I have create all the required tables, but I am stuck at one point. The previous person who created access database had auto increment with SG0101, SG0102,........ In oracle I know we can auto increment primary keys but only with the numbers not with characters.
So I have customerid which is a primary key and it automatically increments the number, but I have one more column with memberid where I am inserting all the ids that start with SG0101 bla bla.....
I already have 800 member ID's that start with SG, but that value doesnt automatically increment because I dont have any sequence or trigger to do that.
So how do I create a sequence and trigger that will automatically start value with SG and keeps auto incrementing?
what's the difference between checkpoint_change# and controlfile_change#. what's the checkpoint_change# use for ? does it use for recover ? what's the controlfile_change# use for ? when the controlfile_change# will be increase ?
SQL> select controlfile_sequence# from v$database;
I have query in that query i should display the number of row. I have tried to select the row num but when i use it the data will be duplicated. I have found something that related to use temporary table, or subquery but all of them will not work because the query depends on many tables and if i use temporary table filling the table and then reading from it will take too long time.
We are facing a different issue in our database. From yesterday night, the archive log generated with 5 digit. But it supposed to be 6 digit. Hence we are not able to apply the logs in DR Location.
I want to write a sql query which will fetch the data from manual_temp_master and manual_temp_detl.But from manual_temp_detl table, Price_bkt_cds columns should be displayed as columns. Like the should look like as below: