PL/SQL :: Ranking Partitions - Value Identifier

Jul 4, 2012

Lets say I have a table like the following -

ID--------DATE_TIME-----------------VALUE
101----- 01/01/2012 14:00:00 ---12
101----- 11/01/2012 23:00:00 ---17
101----- 13/01/2012 10:00:00 ---22
101----- 19/03/2012 08:00:00 ---7
101----- 19/03/2012 19:00:00 ---7
101----- 19/03/2012 20:00:00 ---7
101----- 20/03/2012 02:00:00 ---3
101----- 20/03/2012 03:00:00 ---3
101----- 21/03/2012 13:00:00 ---14
101----- 21/03/2012 14:00:00 ---14
101----- 21/03/2012 21:00:00 ---13
101----- 21/03/2012 22:00:00 ---13
101----- 21/03/2012 23:00:00 ---13
101----- 22/03/2012 00:00:00 ---13

I'm looking for a script to partition the data into sections where the VALUE is the same over a constant period of time with no breaks. I'd like to give each partition a value to identify it by.

So the outcome of the script would be the following -

ID--------DATE_TIME-----------------VALUE-----IDENTIFIER
101----- 01/01/2012 14:00:00 ---12----------1
101----- 11/01/2012 23:00:00 ---17----------2
101----- 13/01/2012 10:00:00 ---22----------3
101----- 19/03/2012 08:00:00 ---7------------4
101----- 19/03/2012 19:00:00 ---7------------5
101----- 19/03/2012 20:00:00 ---7------------5
101----- 20/03/2012 02:00:00 ---3------------6
101----- 20/03/2012 03:00:00 ---3------------6
101----- 21/03/2012 13:00:00 ---14----------7
101----- 21/03/2012 14:00:00 ---14----------7
101----- 21/03/2012 21:00:00 ---13----------8
101----- 21/03/2012 22:00:00 ---13----------8
101----- 21/03/2012 23:00:00 ---13----------8
101----- 22/03/2012 00:00:00 ---13----------8

I was trying to do something with trunc(date_time) but that didnt work out right as the blocks of data can carry over several days as seen in the rows with IDENTIFIER = 8.

View 7 Replies


ADVERTISEMENT

SQL & PL/SQL :: Move Data From Old Partitions To Corresponding New Partitions?

Jul 1, 2010

Initially 2008 to 2010 and 2009 to 2011 partitions are created, After that two more new partitions are created 2008 to 2009 and 2009 to 2010.

How can we move data from old partitions to corresponding new partitions.

View 9 Replies View Related

PL/SQL :: Ranking Sum Total But Not Overall?

Sep 7, 2012

I'm trying to Rank Username based on the Total Sum of amount waived but I want to avoid Ranking the Overall Total at the bottom, plus I dont want them in Ranking order, I want the order to stay the same as it currently is.

SELECT DECODE(GROUPING(USERNAME),1,'TOTAL',0,UPPER(USERNAME)) as "USERNAME",
       SUM(CASE WHEN TO_CHAR(DATE_PROCESSED,'MON') = 'JAN' THEN AMOUNT_WAIVED ELSE 0 END) AS JAN,
       SUM(CASE WHEN TO_CHAR(DATE_PROCESSED,'MON') = 'FEB' THEN AMOUNT_WAIVED ELSE 0 END) AS FEB,
    
[code]....

View 8 Replies View Related

SQL & PL/SQL :: Ranking Non-Consecutive Rows?

Aug 23, 2012

I have a table T with columns

Col1 Col2
1 A
2 B
3 C
4 D

[code]..

I want to do group ranking in desired col3 in such a way that it checks for different values across consecutive rows under col2 and assigns a number to each group. Just when two consecutive rows in col2 have same value then the group ends and the next group starts.

So my desired output is:

Col1 Col2 Col3
1 A 1
2 B 1
3 C 1
4 D 1
5 D 2
6 A 2

[code]...

Here you can see that the first four rows under col2 are unique i.e A,B,C,D so col3 assigns this as group number 1. It ends at row 4 becuase row 5 also has value D under column 2. So in other words, each group must have all unique values and there should not be any repetition. For example, see group 3 (under col3) in above desired output; it starts from row 9 and ends at row 11 because row 12 also has value 'C' and the value 'C' has already occurred in group 3 in row 9.

I want to achieve this SQL. I tried using Dense rank but couldn't go through. I want the shortest possible query to acheive this.

View 3 Replies View Related

Forms :: Ranking Within A Form?

Jul 25, 2013

I have a query find window that allows you to search on various attributes.Also i have a radio button within the query find that allows you to filter the results either as a single record or mulitiple records For example consider the data below.....

Header Table
Record_Id = 1, Record_No = 'Rec1'

Lines Table
Record_Id = 1, Line_desc = 'Line1'
Record_Id = 1, Line_desc = 'Line2'
Record_Id = 1, Line_desc = 'Line3'

I have a View that joins the 2 tables together so for Record_Id = 1 the view returns 3 rows

I would like to have a query find window that allows you to search using:
Record_No
Line_Desc

and has a radio button to allow you to either show the records as a single line or as all detail lines Therefore i would like the following selections:

1) Enter no search criteria but select Single radio option will return 1 record with default line description of Line1
2) Enter no search criteria but select Multiple radio option will return all 3 records
3) Enter Line_Desc = Line1 with Single radio option brings back one record with Line_Desc = Line1
4) Enter Line_Desc = Line2 with Single radio option brings back one record with Line_Desc = Line2
5) Enter Line_Desc = Line3 with Single radio option brings back one record with Line_Desc = Line3
6) Enter Line_Desc = Line1 with Multi radio option brings back one record with Line_Desc = Line1
7) Enter Line_Desc = Line2 with Multi radio option brings back one record with Line_Desc = Line2
7) Enter Line_Desc = Line3 with Multi radio option brings back one record with Line_Desc = Line3

I need the form to select from the view but then perform a rank after it has selected the relavant data. Then the radio button would use the ranking to select either one record or multi records.

View 4 Replies View Related

SQL & PL/SQL :: Ranking Based On A Group?

Jun 29, 2011

I have a table t

CREATE TABLE T
(ID NUMBER(4),
NAME VARCHAR2(40))

INSERT INTO T VALUES (1,'JAMES');
INSERT INTO T VALUES (1,'DOLLY');
INSERT INTO T VALUES (2,'MICHEAL');
INSERT INTO T VALUES (2,'FLASH');
INSERT INTO T VALUES (3,'JAMES');
INSERT INTO T VALUES (3,'MARY');
INSERT INTO T VALUES (4,'JAMES');
INSERT INTO T VALUES (4,'DOLLY');
INSERT INTO T VALUES (5,'JAMES');
INSERT INTO T VALUES (5,'DOLLY');
INSERT INTO T VALUES (6,'JAMES');
INSERT INTO T VALUES (6,'MARY');

SELECT * FROM T ORDER BY 1

ID NAME
1 JAMES
1 DOLLY
2 MICHEAL
2 FLASH
3 JAMES
3 MARY
4 JAMES
4 DOLLY
5 JAMES
5 DOLLY
6 JAMES
6 MARY

each 'ID' has two values always. I want to rank the data based on same pair 'name' in an 'ID'

for example, my desired output is:

ID NAME RANK
1 JAMES 1
1 DOLLY 1
2 MICHEAL 1
2 FLASH 1
3 JAMES 1
3 MARY 1
4 JAMES 2 ---> THAT IS RANK 2 BECAUSE THIS IS THE 2ND TIME JAMES AND DOLLY ARE IN THE SAME 'ID'
4 DOLLY 2 -----> SAME AS ABOVE
5 JAMES 3 ---> THAT IS RANK 2 BECAUSE THIS IS THE 3RD TIME JAMES AND DOLLY ARE IN THE SAME 'ID'
5 DOLLY 3 -----> SAME AS ABOVE
6 JAMES 2 ---> THAT IS RANK 2 BECAUSE THIS IS THE 2ND TIME JAMES AND MARY ARE IN THE SAME 'ID'
6 MARY 2 -----> SAME AS ABOVE

I want the output in exactly above format.

View 3 Replies View Related

SQL & PL/SQL :: Ranking Function And Duplicate Records

Aug 30, 2012

I have the following table :

CREATE TABLE A_TEST (A INTEGER, B INTEGER, C INTEGER, D INTEGER, FLAG CHAR(11));

INSERT INTO A_TEST (A,B,C,D) VALUES(1,2,3,4);
INSERT INTO A_TEST (A,B,C,D) VALUES(2,4,5,8);
INSERT INTO A_TEST (A,B,C,D) VALUES(1,2,3,4);
INSERT INTO A_TEST (A,B,C,D) VALUES(2,4,5,8);
INSERT INTO A_TEST (A,B,C,D) VALUES(7,2,3,4);
INSERT INTO A_TEST (A,B,C,D) VALUES(9,2,3,4);
[code]....

I would like to perform an update on the FLAG column by setting to "D" if it is a duplicate record.1,2,3,4);I would like to use the rank function.

Desired update:

A B C D FLAG
1 2 3 4
2 4 5 8
1 2 3 4 D
2 4 5 8 D
7 2 3 4
9 2 3 4
7 2 3 4 D
1 2 3 4 D
5 4 5 8
2 2 3 9
2 4 5 8
6 2 3 4
1 3 3 4
8 2 8 4

View 3 Replies View Related

SQL & PL/SQL :: Analytic Functions And Ranking / Ordering?

Jul 17, 2008

I need to return an ordered list of documents. The documents may belong to a set id (optional) and if so, are either a "master" or a "duplicate" type. For each set there can be only one master but many duplicates. My goal is to group all the sets together such that each master is proceeded by its duplicates.

Table description:
document_master_duplicates
(
documentid,
duplicate_setid,
is_master
)

This needs to join to another table briefcase_documents which contains our set of documents. The briefcase / document relationship is many-to-many.

Table description:
briefcase_documents
(
briefcaseid,
documentid
)

There's also a documents table containing the documentid and among other things a page_count. In the following example I want to sort the documents first by page count but preserving the master/dupe grouping. Any documents which don't belong to a set or are just a duplicate without a master i want at the end of my set but also ordered by page count.

Here's an example set that I would want to order by:

DocumentId Page_Count SetId Is_Master
2002 2 1 0
2003 20 2 0
2008 20 NULL NULL
2010 20 4 0
2012 1 4 1
2001 5 1 1
2004 16 3 1
2011 17 4 0
2014 10 5 0
2009 9 NULL NULL

As you can see I have a little bit of everything here. Docs 2001 and 2002 are the typical set of 1 master and its duplicate. Docs 2010, 2011, and 2012 is the same just a set of 3. Doc 2004 is a master but without any duplicates. Docs 2003 and 2014 are duplicates without a master (these docs have a master in the table but that doc isn't in the set i need to order by). Docs 2008 and 2009 do not belong to a set and as such do not have a master/dupe type.

The result i'm looking to achieve will be ordered as follows:

DocumentId Page_Count SetId Is_Master
2012 1 4 1
2011 17 4 0
2010 20 4 0
2001 5 1 1
2002 2 1 0
2004 16 3 1
2009 9 NULL NULL
2014 10 5 0
2003 20 2 0
2008 20 NULL NULL

As I said above I first want to get the groupings of master/dupes and order ascending on the masters page count. For each duplicate of a master I then want to order the duplicates by page count. After I finished ordering all the master/dupe groups I then want to move on to the rest of the documents which will contain documents that don't belong to a set along with documents which are duplicates but have no master in my set. However, documents which are masters but without duplicates should have been ordered along with the other master/dupes groupings.

With this all in mind I have just been completely overwhelmed as to where to even start. Am I using analytic functions? Hierarchical stuff?

View 10 Replies View Related

SQL & PL/SQL :: Ranking Of Consecutive Non-increasing Values In A Column?

Apr 14, 2012

I have a table with numbers like this in a column

sr no. value
1 17
2 0
3 0
4 38
5 32
6 24
7 12
8 51
9 42
10 1
11 1
12 0
13 0
14 1
15 1
.
.
.
so on....

I want to find out consecutive non-increasing sequences of value (2nd column) order by sr. no (first column) in ascending order.

For example, in the 2nd column, 17 is followed by 0 and 0 and then 38 so it means 3 consecutive values (i.e starting from 17 are 0 and 0) are non-increasing and they are ranked by '1' in my desired in third column as shown below. similarly, the 2nd non-increasing sequence starts with 38,32,24 and 12 and this is ranked as '2' in the third column. same is the case with rank '3' for the third non increasing sequence. so bascially i want the third column with "ranks" starting and ending as per above logic. i tried using LEAD function but doesn't get what I want. I need the shortest possible query to get that third column since i have other columns in the original table in a multiple group by query.

my desired output is:

sr no. value Rank
1 17 1
2 0 1
3 0 1
4 38 2
5 32 2
6 24 2
7 12 2
8 51 3
9 42 3
10 1 3
11 1 3
12 0 3
13 0 3
14 1 4
15 1 4
.
.
.

View 3 Replies View Related

Metadata For Some Of Partitions

Nov 10, 2010

i have many partitions in one table. i need metadata for some of the partitions. We have any option to get the metadata for partitions only.because while selecthing the table meatdata i am getting long script.

View 2 Replies View Related

PL/SQL :: Query To Get Last N Used Partitions

Aug 20, 2013

I have a day based partitioned table TAB1.Let say for month Aug 2013 Partitions are like P010813,P020813,P030813 up to P310813.When gather stats job will run i want to analyze only the last 3 used partitions based on current date, this would be P180813,P190813,P200813. write a query which will give the last 3 used partitions.e.g.

If run query on 20-AUG-2013.P180813P190813P200813FOR 25-AUG-2013P230813P240813P250813

View 1 Replies View Related

PL/SQL :: Dropping Partitions At Once

Nov 2, 2012

ALTER TABLE table_name DROP PARTITION (partition_1000);
ALTER TABLE table_name DROP PARTITION (partition_1001);
...
.........
......
ALTER TABLE table_name DROP PARTITION(partition_1320);(b

it is a delta partition,so trying to remove 320 partitions at once in pl/sql developer for a single table.

Like this i have to remove for more then 15 tables one by one, will this effect the database like filling up the archinve log destination by writing more logs.

kind of problems that i am going to face , as i am doing it on the production box directly.

View 5 Replies View Related

Create Table As With Partitions?

Jan 8, 2011

If I try create table from the following syntax

create table a as select * from table b;

Then I could get only base table structure alone, I would like to get partition syntax as well.

View 1 Replies View Related

Select From Multiple Partitions

Nov 2, 2010

I have more 100 partition in a table, I would like to query 10 partitions alone in single statement, Hope it could be possible like query data for single partitions, provide the syntax for the same.

Because if I try to query for all the partition then the query is Hanging due to the large no of data, then I can query single partition by partition then it takes more than a day. so, I would like query data for 10 partition in a single select.

View 1 Replies View Related

SQL & PL/SQL :: Drop Partitions With Zero Rows

Sep 26, 2011

Query to drop partitions on a table who have no.of rows as zero.

select 'ALTER' || '' || 'TABLE' || TABLE_NAME || 'DROP' || 'PARTITION' || PARTITION_NAME from dba_tab_partitions where TABLE_OWNER='xyz' ;
select count(*) from table_name partition (partition_name);

View 14 Replies View Related

Partitions On Materialized Views?

Nov 29, 2012

Can we add partitions for materialized views like tables ? ALTER TABLE owner.tablename ADD PARTITION p1 VALUES LESS THAN (2012,12);

Like is there any syntax for mview ALTER TABLE mv.mviewname ADD PARTITION ..... ?

View 2 Replies View Related

PL/SQL :: Create Partitions On Table

Sep 13, 2012

My developer came with a requirement of creating partitions on a table which has 40 million records. His exact requirement is to create as many as partitions in such a way that 1 partition should not exceed 5k-10k records and these records should be inserted/updated on the same date (i.e. using a column as source_timestamp field). How to accomplish this?

View 2 Replies View Related

Table DDL Extraction For Mentioned Partitions

Nov 10, 2010

I have tables in production which has got huge no of partitions(say more than 100), but I would like to extract table definiation along with mentioned few partitions(say 10 partitions) alone. How to do that, which way is the best to extract DDL with right format.

because when I use metadata package the format for the extraction is not good, is there a way to extract table definition with mentioned partition names.

View 2 Replies View Related

SQL & PL/SQL :: Partition Existed Table Into 3 Partitions

Mar 9, 2010

How can we partition the existed table.

The table is like this

CREATE TABLE my_table (
id NUMBER,
description VARCHAR2(50)
);

[Code]...

I want to partition this table into 3 partitions.

The first partition should contain the values less than 3.

The Second partition should contain the values less than 5.

The third partition should contain the values less than 6.

View 16 Replies View Related

PL/SQL :: Dictionary For Materialized View Partitions

Sep 2, 2012

I created a materilaized view with partitions and i need to add partitions dynamicaaly using stored procedure for that i need to check whther the partiions with the same name existing.where can i see the partition names for a materilaized view is there any table like "USER_TAB_PARTITIONS"?.if the same query exists in the forum

View 3 Replies View Related

Swap Multiple Partitions Into A Table?

Sep 28, 2012

We are using partition exchnage to swap individual partitions into table which then backed up.

This being done one partition at a time.

Is it possible to swap several partitions of a tabel in one go.

using Oracle 11.2.0.3

partioned by date, one partition of reach day.

Is it possible say to move the last 7 days partitions into the other table for backup using partition exchange?

View 9 Replies View Related

PL/SQL :: How To Truncate Data In Table Partitions

Aug 9, 2013

I couldn't either DROP or TRUNCATE the table partitions that were created. Here are the DDLs and DMLs I'm using. 

Create table student(no number(2),name varchar(2)) partition by range(no) (partition 
p1 values less than(10), partition p2 values less than(20), partition p3 values less     
than(30),partition p4 values less than(40)); 
Insert into student values(1,'a');
Insert into student values(11,'b');
Insert into student values(21,'c');
Insert into student values(31,'d'); 

When I do the following query, it returns data.

SELECT * FROM STUDENT PARTITION(p1); 

But, when I try to perform any of the following queries, it says invalid partition name. 

ALTER TABLE STUDENT DROP PARTITION p4;
ALTER TABLE STUDENT TRUNCATE PARTITION p3;

I am using Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit

View 9 Replies View Related

Range Partitions On A Date Column

Jul 7, 2012

I have a table which has 2 range partitions on a date column currently.

CREATE TABLE TABLEA (
     RUN_TIME INT NOT NULL
)
PARTITION BY RANGE (RUN_TIME)
(
     PARTITION DATAONE VALUES LESS THAN (20110101000000) TABLESPACE SPACE1
     PARTITION DATATWO VALUES LESS THAN (MAXVALUE) TABLESPACE SPACE2
);

I am planning to drop one partition i.e DATAONE. So table will have one partition left for MAXVALUE. Does it make sense to have a partition with MAXVALUE? Isn't it same as TABLEA in terms of number of records? TABLEA is also in tablespace SPACE2. Should i remove partition DATATWO also? If i have to what is the best way to move all DATATWO records to base table TABLEA?

View 6 Replies View Related

Drop Some Partitions In Table On Production Environment

Jul 8, 2011

I have to drop some partitions in table on production environment (to get free space). The environment have to be continuously available. I was considering of use ALTER TABLE ... DROP PARTITION ... UPDATE INDEXES but it is slow, because of use clause UPDATE INDEXES. Is there another possibility to remove these data?

View 2 Replies View Related

Max Limit On Number Of Partitions / Can Have In A Table In Oracle

Feb 11, 2013

What is the limit on number of partitions on a table.on many forums , 1024k-1 is given the maximum limit.But Exactly , I am not able to understand this 1024k-1.

View 2 Replies View Related

Partitions For Archiving - Date With Completed Flag?

Jan 29, 2011

I am working on an archiving strategy. I want to roll off transactions that are older than seven days, but only if they are flagged as Completed. The numbers of transactions are very large so this is a worthwhile venture.

The only strategy I have been able to come up with so far is to partiton on date. Then when 7 days comes up, sweep the about-to-be archived day for the few remaining not Completed transactions, put those into a new table (a new version of this partiton) and switch partitions. Each day I do this until the older parititions are empty.

View 7 Replies View Related

SQL & PL/SQL :: Trigger To Drop Partitions And Local Indexes

Sep 29, 2011

writing a trigger to drop partitions with zero rows which are older than 6months and drop the local indexes and rebuild the global indexes for any schema in a databaase ?

I have tried the below code :

declare
v_statement varchar2(600);
v_rows number;
begin
for x in (select *
from dba_tab_partitions
[code]........

I want to avoid using row number and also want to dynamically select a schema when executing the script.

View 39 Replies View Related

Drop Partitions Stale Percent Of Stats?

Nov 12, 2012

In my database,stale_percent is set to 10. and i have table which has partition. i have dropped table partition dropped which has 10% of data. I would like to know whether oracle will consider only insert,update,delete as stale percent or will it include the dropping paritition data also. Because my stats gather is not running. When i include drop partition data it exceed 10% of stale_percent,But excluding dropped partition it is not exceeds 10% of stale.

TABLE_NAME PARTITION_NAME SUBPARTITION_NAME INSERTS UPDATES DELETES TIMESTAMP TRU DROP_SEGMENTS
------------------------------ ------------------------------ ------------------------------ ---------- ---------- ---------- ----------- --- -------------
sample_DATA_DATA 235825577 0 0 11-NOV-2012 NO 3
test_DATA_DATA 811618472 0 0 11-NOV-2012 NO 12
sample_DATA_DATA SYS_P2665099 3005966 0 0 11-NOV-2012 NO 0
sample_DATA_DATA SYS_P2665119 3873671 0 0 11-NOV-2012 NO 0

[code].....

View 6 Replies View Related

SQL & PL/SQL :: Two Partitions Based On Gender Male And Female

Mar 27, 2010

I have a table with 1 million rows,all rows are based on the gender male and female.

So that i have done two partitions based on the gender Male and Female.

After that i performed the query

SELECT COUNT(*) FROM student WHERE gender='MALE';

In that case performance is improved,because oracle scans a single partition instead of scanning entire table.

Suppose i have partitioned according to the date column and i performed the query

SELECT COUNT(*) FROM student WHERE gender='MALE';

In that case performance will be improved or not

View 3 Replies View Related

PL/SQL :: Use Securefile For New Partitions Made By Interval Partitioning

Oct 19, 2012

I am using Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production.I have a range partitioned table having lobs as basicfile. Due to storage issue and other business constraints , it is determined not to change existing lobs to securefile.

However ,we want new lobs to be in securefile and alter table to have  interval partition+.While researching, I found sql to change lob in range partition to securefile by using

alter table t1 add partition t1_p2 value less than (10000) lob (col3) store as securefile (tablespace tbs_sf1)

What to do similar  in case of interval partition.

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved