Partition by virtual column, select - sinlgle partition on two columns
Pls, I have a question - we have table with COLUMNs:
-- TIME_KEY - julian - date value (to_char(sysdate, 'J')) - we would like to have virtual date value:
-- TIME_ID - virtual column with interval partitioning (great!)
CREATE TABLE lsd_cntr_pokus
( time_key NUMBER not NULL
, time_ID AS (to_date(time_key,'J'))
, cntr_key NUMBER not NULL
---...etc
PARTITION BY RANGE (time_ID) INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(PARTITION part_2007 VALUES LESS THAN
(TO_DATE('01-JAN-2007','dd-MON-yyyy'))
But then - is it possible to somehow define this table,
so both selects:
SELECT * FROM lsd_cntr_pokus
WHERE time_key = to_char(TO_DATE('01.01.2007', 'DD.MM.YYYY'),'j') ;
SELECT * FROM lsd_cntr_pokus
WHERE time_id = TO_DATE('01.01.2007', 'DD.MM.YYYY') ;
use PARTITION RANGE SINGLE?
Thanks for any help,
Regards
Edited by: vrbcik on Dec 10, 2012 3:39 PM
vrbcik wrote:
Pls, I have a question - we have table with COLUMNs:
-- TIME_KEY - julian - date value (to_char(sysdate, 'J')) - we would like to have virtual date value:
-- TIME_ID - virtual column with interval partitioning (great!)
CREATE TABLE lsd_cntr_pokus
( time_key NUMBER not NULL
, time_ID AS (to_date(time_key,'J'))
, cntr_key NUMBER not NULL
---...etc
PARTITION BY RANGE (time_ID) INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(PARTITION part_2007 VALUES LESS THAN
(TO_DATE('01-JAN-2007','dd-MON-yyyy'))
But then - is it possible to somehow define this table,
so both selects:
SELECT * FROM lsd_cntr_pokus
WHERE time_key = to_char(TO_DATE('01.01.2007', 'DD.MM.YYYY'),'j') ;
SELECT * FROM lsd_cntr_pokus
WHERE time_id = TO_DATE('01.01.2007', 'DD.MM.YYYY') ;
use PARTITION RANGE SINGLE?
Thanks for any help,
Regards
Edited by: vrbcik on Dec 10, 2012 3:39 PMHi,
I'm afraid that, with this partition definition, partition pruning is working only when you use your virtual column time_id in your query.
According to documentation Information That Can Be Used for Partition Pruning:
Virtual column-based partitioned tables benefit from partition pruning for statements that use the virtual column-defining expression in the SQL statement.Maybe some tuning expert can confirm this or give another advice.
Regards.
Al
Similar Messages
-
How to partition one column of the resultset into two columns
Step 1
Row_Num | Col1 | Col2
1 52 100
1 52 101
1 52 102
1 52 103
2 52 200
2 52 201
2 52 202
2 52 203
2 52 204
2 52 205
Step 2
Row_Num, Decode(Row_Num,1,Col1,Null) Col1_1, Decode(Row_Num,2,Col1,Null) Col1_2,Decode(Row_Num,1,Col2,Null) Col2_1, Decode(Row_Num,2,Col2,Null) Col2_2
Result
Row_Num | Col1_1 | Col2_1 | Col1_2 | Col2_2
1 52 100 Null Null
2 Null Null 52 200
1 52 101 Null Null
2 Null Null 52 201
1 52 102 Null Null
2 Null Null 52 202
1 52 103 Null Null
2 Null Null 52 203
2 Null Null 52 204
2 Null Null 52 205
What i want it is something as below.
Row_Num | Col1_1 | Col2_1 | Col1_2 | Col2_2
52 100 52 200
52 101 52 201
52 102 52 202
52 103 52 203
Null Null 52 204
Null Null 52 205
Null Null Null Null
Null Null Null Null
Null Null Null Null
Null Null Null Null
Which means move nulls to the last in a group
I don't need Nulls at the end. I have added that just to show all rows.
I would also like to know whether any analytic functions can be used to bring the desired result.
please consider the columns as varchar type even though it has numeric values.
thanks,
renga
Edited by: user12367921 on Dec 18, 2009 5:25 PMBoth Solomon's solution and Frank's one are based on the sequence of the row. Let's delete the (1 52 102) row from the table, the two queryes will behave the following way:
Solomon
SQL >with t1 as (
2 select 1 row_num,52 col1,100 col2 from dual union all
3 select 1,52,101 from dual union all
4 select 1,52,103 from dual union all
5 select 2,52,200 from dual union all
6 select 2,52,201 from dual union all
7 select 2,52,202 from dual union all
8 select 2,52,203 from dual union all
9 select 2,52,204 from dual union all
10 select 2,52,205 from dual
11 ),
12 t2 as (
13 select row_number() over(partition by row_num order by col2)
14 dense_rank() over(order by row_num) rnk,
15 col1,
16 col2
17 from t1
18 )
19 select distinct case rnk
20 when 1 then col1
21 else lag(col1) over(partition by rn order by rnk)
22 end col1_a,
23 case rnk
24 when 1 then col2
25 else lag(col2) over(partition by rn order by rnk)
26 end col2_a,
27 case rnk
28 when 2 then col1
29 else lead(col1) over(partition by rn order by rnk)
30 end col1_b,
31 case rnk
32 when 2 then col2
33 else lead(col2) over(partition by rn order by rnk)
34 end col2_b
35 from t2
36 order by col2_a nulls last,
37 col2_b nulls last
38 /
COL1_A COL2_A COL1_B COL2_B
52 100 52 200
52 101 52 201
52 103 52 202
52 203
52 204
52 205
Frank
with t1 as (
select 1 row_num,52 col1,100 col2 from dual union all
select 1,52,101 from dual union all
select 1,52,103 from dual union all
select 2,52,200 from dual union all
select 2,52,201 from dual union all
select 2,52,202 from dual union all
select 2,52,203 from dual union all
select 2,52,204 from dual union all
select 2,52,205 from dual
got_rs AS
SELECT row_num
, col1
, col2
, ROW_NUMBER () OVER ( PARTITION BY row_num
ORDER BY col2
) AS r_col2
FROM t1
SELECT MIN (DECODE (row_num, 1, col1)) AS col1_1
, MIN (DECODE (row_num, 1, col2)) AS col1_2
, MIN (DECODE (row_num, 2, col1)) AS col2_1
, MIN (DECODE (row_num, 2, col2)) AS col2_2
FROM got_rs
GROUP BY r_col2
ORDER BY r_col2
OL1_1 COL1_2 COL2_1 COL2_2
52 100 52 200
52 101 52 201
52 103 52 202
52 203
52 204
52 205In both resultsets the code 103 is now associated to the 202. Is it correct?
My query assumes (and is a strong assumption) that two rows of the source table can be associated only if they have the same last two digits of the col2 column.
SVIL>with t0 as (
2 select 1 row_num,52 col1,100 col2 from dual union all
3 select 1,52,101 from dual union all
4 select 1,52,103 from dual union all
5 select 2,52,200 from dual union all
6 select 2,52,201 from dual union all
7 select 2,52,202 from dual union all
8 select 2,52,203 from dual union all
9 select 2,52,204 from dual union all
10 select 2,52,205 from dual
11 ),
12 t1 as (select * from t0 where row_num=1),
13 t2 as (select * from t0 where row_num=2)
14 Select t1.col1 col1_1, t1.col2 col2_1,t2.col1 col1_2, t2.col2 col2_2
15 from t1 full outer join t2 on t1.col2+100=t2.col2;
COL1_1 COL2_1 COL1_2 COL2_2
52 100 52 200
52 101 52 201
52 103 52 203
52 205
52 202
52 204The results are quite different.
I don't know what is the correct approach (or whether both of them are wrong), hope Renga will clarify.
Max
[My Italian Oracle Blog|http://oracleitalia.wordpress.com/2009/12/19/totali-parziali-con-group-by-rollup/] -
I want a select statement to return two values, sum of one column and customer number
I have two columns one called invoice_number and the other invoice_amount. I want a select statement to return two columns.... invoice_number and then the sum of the invoice_amount(s) for each unique invoice number.
SELECT sum(invoice_amount) AS Totalinvoice_amount FROM InvoiceTB where invoice_number = 'INV102'
This is where I've started, which returns:
Totalinvoice_amount
500.00
Any help is appreciated.
Please mark my post as helpful or the answer or better yet.... both! :) Thanks!Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect.
This is minimal polite behavior on SQL forums.
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
Dreamweaver two column left nav
I am starting a new site. I am pretty familiar with web site
construction and many css features.
I have created a few pages using the sample css html pages
supplied with dreamweaver. I selected a site named "two columns
left nav".
I checked it out pretty thoroughly using a color code system
to identify the varies features. My main concern is to be able to
create a site that will fit most resolutions available. I tried it
out and it does expand and contract. I tried it on my 24 inch
monitor, my little laptop and a 21 inch Macintosh.
No problem with dreamweaver but there is a problem with me.
I can't seem to come up with a scheme in the header that will
expand and contract. I would like to use graphics. Is there any
instructions available to make these graphics get larger or smaller
so they will conform to different size monitors, resolutions etc?
Once I master this I will get started on my new site.
Thank you.
Maybe there is a little trick you can tell me about.> I can't seem to come up with a scheme in the header that
will expand and
> contract. I would like to use graphics. Is there any
instructions
> available to
> make these graphics get larger or smaller so they will
conform to
> different
> size monitors, resolutions etc? Once I master this I
will get started on
> my new
You can't expand and contract images. You can set a
background image
and have it repeat as necessary as long as the image will
tile correctly. -
Column having minimum value of two calculated columns
Hi All
Please help me out in the following scenario.
I have to get the data from two tables so whatever columns I need put it in the select statement but for two columns I have to do calculations and did assigned an alias name to those two calculated columns, lets say X & Y.
I have to show the data for column Z, the rule for this column is to take minimum value of columns X & Y.
I have to use purely a select statement and retrieve the data. Camnt do any changes or creating functions on database.
thnaks in advance.@Sven
First thought is using minimum function and throwed me error and then realized that min function can be used on a column and then searched for function to find minimum of calculated columns, could n't find out.
Then thought of using case or if statement to find out the minimum, felt thats not a good idea and also thought of using nested sub query, could n't achieve the desired.
Actually I didnt know about the least function, now I
Anyway thnak you all. -
How can I add a new column in compress partition table.
I have a compress partition table when I add a new column in that table it give me an error "ORA-22856: CANNOT ADD COLUMNS TO OBJECT TABLES". I had cretaed a table in this clause. How can I add a new column in compress partition table.
CREATE TABLE Employee
Empno Number,
Tr_Date Date
COMPRESS PARTITION BY RANGE (Tr_Date)
PARTITION FIRST Values LESS THAN (To_Date('01-JUL-2006','DD-MON-YYYY')),
PARTITION JUNK Values LESS THAN (MAXVALUE));
Note :
When I create table with this clause it will allow me to add a column.
CREATE TABLE Employee
Empno Number,
Tr_Date Date
PARTITION BY RANGE (Tr_Date)
PARTITION FIRST Values LESS THAN (To_Date('01-JUL-2006','DD-MON-YYYY')),
PARTITION JUNK Values LESS THAN (MAXVALUE));
But for this I have to drop and recreate the table and I dont want this becaue my table is in online state i cannot take a risk. Please give me best solution.Hi Fahed,
I guess, you are using Oracle 9i Database Release 9.2.0.2 and the Table which you need to alter is in OLTP environment where data is usually inserted using regular inserts. As a result, these tables generally do not get much benefit from using table compression. Table compression works best on read-only tables that are loaded once but read many times. Tables used in data warehousing applications, for example, are great candidates for table compression.
Reference : http://www.oracle.com/technology/oramag/oracle/04-mar/o24tech_data.html
Topic : When to Use Table Compression
Bug
Reference : http://dba.ipbhost.com/lofiversion/index.php/t147.html
BUG:<2421054>
Affects: RDBMS (9-A0)
NB: FIXED
Abstract: ENH: Allow ALTER TABLE to ADD/DROP columns for tables using COMPRESS feature
Details:
This is an enhancement to allow "ALTER TABLE" to ADD/DROP
columns for tables using the COMPRESS feature.
In 9i errors are reported for ADD/DROP but the text may
be misleading:
eg:
ADD column fails with "ORA-22856: cannot add columns to object tables"
DROP column fails with "ORA-12996: cannot drop system-generated virtual column"
Note that a table which was previously marked as compress which has
now been altered to NOCOMPRESS also signals such errors as the
underlying table could still contain COMPRESS format datablocks.
As of 10i ADD/SET UNUSED is allowed provided the ADD has no default value.
Best Regards,
Muhammad Waseem Haroon
[email protected] -
Does it makes sense to create an index on a column used for partitioning
I am new to using partitions along with index. Can someone help me with the situation below?
I have a table defined like below
CREATE TABLE FACT_MASTER
PERIODCODE NUMBER(8) NOT NULL,
PRODUCT_CD NUMBER(10) NOT NULL,
DPT_CD NUMBER(3),
FACT_VALUE1 NUMBER,
FACT_VALUE2 NUMBER,
FACT_VALUE3 NUMBER,
FACT_VALUE50 NUMBER
PARTITION BY RANGE (PERIODCODE)
partition P1 values less than (2002),
partition P2 values less than (2003),
partition P3 values less than (2004),
This table is partitioned by range on Period code.
In a select query on this table, period code and product code are being used. I am planning to create an index to boost the performance. Does it make sense to include the period code column also in the index? I am planning to create index only for the product code column. I am thinking that the partition itself will act like an index for periodcode. Can someone tell me if this is correct? I am using 10g.
Edited by: user6794035 on Jan 21, 2010 8:47 AM
Edited by: user6794035 on Jan 21, 2010 8:50 AMIn your scenario I think it's better not to create an index on PERIODCODE because this column probaly has a only few distinct values.
In other scenarios, when in the same partition there are many distinct values of the partitioning key, creating an index can be an advantage for query performances..
But it depends on the specific context...
Max
[My Italian Oracle blog|http://oracleitalia.wordpress.com/2010/01/17/supporto-di-xml-schema-in-oracle-xmldb/] -
Select for partitioned table, will this work with sign?
Hi,
I have partitioned table and select for it like :
PARTITION BY RANGE ( "INDATE" )
( PARTITION "PRT_20091201" VALUES LESS THAN (TO_DATE(' 2009-12-02 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')...
SELECT COLUMN_LIST FROM TABLE1 WHERE
( indate >= to_date(t_indate || t_timefrom, 'mm/dd/yyyy HH24:MI:SS')) AND
( indate <= to_date(t_indate || t_timeto, 'mm/dd/yyyy HH24:MI:SS')) AND... so selecting all info for the given date withing specifiied time period, and I'm using >= condition on partitioned column, do you think it will work correctly getting directly to the single partition, or Oralce requires me put strictly = sign for that column, and then additioanly I can probably select time period, something like:
SELECT COLUMN_LIST FROM TABLE1 WHERE
( indate = to_date(t_indate , 'mm/dd/yyyy')) AND
( trim_to_time(indate) >= to_char(t_timefrom, ' HH24:MI:SS')) AND
( trim_to_time(indate) <= to_char( t_timeto, ' HH24:MI:SS')) AND... Tx all
Trtrento wrote:
Hi,
I have partitioned table and select for it like :
PARTITION BY RANGE ( "INDATE" )
( PARTITION "PRT_20091201" VALUES LESS THAN (TO_DATE(' 2009-12-02 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')...
SELECT COLUMN_LIST FROM TABLE1 WHERE
( indate >= to_date(t_indate || t_timefrom, 'mm/dd/yyyy HH24:MI:SS')) AND
( indate <= to_date(t_indate || t_timeto, 'mm/dd/yyyy HH24:MI:SS')) AND... so selecting all info for the given date withing specifiied time period, and I'm using >= condition on partitioned column, do you think it will work correctly getting directly to the single partition, or Oralce requires me put strictly = sign for that column, and then additioanly I can probably select time period, something like:
SELECT COLUMN_LIST FROM TABLE1 WHERE
( indate = to_date(t_indate , 'mm/dd/yyyy')) AND
( trim_to_time(indate) >= to_char(t_timefrom, ' HH24:MI:SS')) AND
( trim_to_time(indate) <= to_char( t_timeto, ' HH24:MI:SS')) AND... Tx all
TrI agree with David that the first example looked okay, but you should test to make sure. You can check individual partition contents by executing a query using the PARTITION option to specifiy a specific partition to check the values there. -
VMware Fusion Performance: Bootcamp Partition or Virtual Machine?
I'd like to run ArcGIS 9.3 in Windows XP using VMware Fusion. Can anyone comment on the virtues/drawbacks of using a bootcamp partition versus creating a VMware "Virtual Machine"?
With bootcamp partition I can gradually increase the size of the partition as the partition becomes full using Drive Genius, correct?
What about performance?
Thanks!Visit MacTech.com and read their two benchmark reviews of Parallels, VM Fusion, and Boot Camp.
You cannot "gradually increase the size" of a Boot Camp partition. To change the size you must first delete the existing partition then create a new, larger partition. Doing so will delete the entire Windows system, so be sure to back it up beforehand. -
How to find the partition column in a partitioned table
Hi,
I have a partition table and I need to find out what column was used to partition the table. Range partition.
Thanks,
Maria Sanchezselect *
from dba_part_key_columns -
I have Boot Camp running on a separate HD (not a partition on my Mac drive). I would like to partition the PC HD to have a multi boot PC. What is the proper way to do this? How do I select which partition to start the PC?
I have Boot Camp running on a separate HD (not a partition on my Mac drive). I would like to partition the PC HD to have a multi boot PC. What is the proper way to do this? How do I select which partition to start the PC?
-
hi all,
hope i'm in the right forum. i have 2 databases sitting in 2 separate machines. 1 installed with Oracle 9i and 1 with Oracle 10g. I'm trying to select a partitioned table in 9i remotely (from the 10g db). In order to do that, I've created a synonym in 10g pointing to the partitioned table in 9i.
In 9i, if i do a select "select count(*) from tableA partition (p1)", i'm able to grab the correct count of the partition. But when i use the same select statement in 10g, it's grabbing all the data of the table, sum of all partitions. it looks like the partition qualifier specified in the select statement has no effect. Can i know what is the problem? hope to get some response a.s.a.p. tq
regards,
yklI did recreate your same situation, and actually the result is the same. I get that result when using a synonym. If I use <table name>@<db link> instead of synonym, then the result is different :
ORA-14100: partition extended table name cannot refer to a remote object
(internal unpublished bug 3076633, fixed in 10.2)
In my case I can solve the problem using partition key, instead of partition name, that is
SQL> select count(*) from <partition table synonym> where <partition key> = <value>;
instead of
SQL> select count(*) from <partition table synonym> partition(<partition name>);
Paul -
Select over partition compilation error
Forms [32 Bit] Version 10.1.2.0.2 (Production)!!
Is it possible that select over partition is all right in a Record group while it is giving error in to trigger?
Thanks in advanceTriggers are compiled in forms so need to use only the features available to forms, which doesn't include all the new stuff in the database.
Record groups are not compiled, they are parsed on the database so can include all database functionality. If you create a record group you can see immediately the source in v$sql, with bind variables replaced with :1, :2 etc. -
People,
I have a question regarding selecting from partitions.
For my internship I need to write a program with APEX to retrieve ad-hoc data from a data-warehouse.
The large tables are split into partitions of each about 500k records. Names are given according to the key they split(: partition_200912, as 2009 December).
This is also the main select criteria of the ad-hoc data, a period. What I want to is something like:
select * from table1 partition('partition_' || :PERIODSELECT), table2 partition('partition_' || :PERIODSELECT) where table1.id = table2.id
However oracle does not accept this kind of naming.
How can I make the selection of a partition dynamic?(Without hard-code it into a case statement since I don't want to add a case every month)
Greetings, OlafYour approach is wrong. Partitioning is a physical feature of the database. It has no place in SQL from the (logical) application layer.
Does the application layer know whether the table is a hash table or an index organised table? Perhaps a clustered table? No. There's absolutely no need for the application layer to know the physical storage structures used by the database. And partitioning is a physical storage structure feature.
Code plain normal application SQL - the Oracle CBO (Cost Based Optimiser) has all the intelligence and physical storage information required to make a proper decision on how to apply partition pruning to that application SQL. -
SQL statement for selecting multiple partitions
Hi All,
May i know how to Select data from a table having multiple partitions ?
Example : Owner = Scott, Table= Emp, Partitions (P1,P2,P3,P4,P5)
Thanksno...
SQL>
1 create table partition_test
2 (owner, object_name, object_id)
3 partition by list(owner)
4 (partition part_1 values ('SYS'),
5 partition part_2 values ('SYSTEM'),
6 partition part_3 values ('OUTLN')
7 ) as select owner, object_name, object_id from all_objects
8* where owner in ('SYS', 'SYSTEM', 'OUTLN')
9 /
Table created.
SQL> select count(*) from partition_test partition(part_1, part_2);
select count(*) from partition_test partition(part_1, part_2)
ERROR at line 1:
ORA-00933: SQL command not properly ended
SQL> select count(*) from partition_test partitions(part_1, part_2);
select count(*) from partition_test partitions(part_1, part_2)
ERROR at line 1:
ORA-00933: SQL command not properly ended
SQL> select count(*) from partition_test partitions(part_1 + part_2);
select count(*) from partition_test partitions(part_1 + part_2)
ERROR at line 1:
ORA-00933: SQL command not properly ended
SQL> select count(*) from partition_test partitions(part_1 between part_2
select count(*) from partition_test partitions(part_1 between part_2)
ERROR at line 1:
ORA-00933: SQL command not properly ended
SQL> select count(*) from partition_test partitions("part_1 part_2");
select count(*) from partition_test partitions("part_1 part_2")
ERROR at line 1:
ORA-00933: SQL command not properly endedand this is the documented behavior:
"partition_extension_clause
For PARTITION or SUBPARTITION, specify the name or key value of the partition or subpartition within table from which you want to retrieve data.
For range- and list-partitioned data, as an alternative to this clause, you can specify a condition in the WHERE clause that restricts the retrieval to one or more partitions of table. Oracle Database will interpret the condition and fetch data from only those partitions. It is not possible to formulate such a WHERE condition for hash-partitioned data."
from:
http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/statements_10002.htm#i2076542
Amiel
Maybe you are looking for
-
Hello, I have a transformation routine as follows: DATA:l_lifnr1 TYPE /BI0/MBATCH-VENDOR, l_greybatch TYPE /BI0/MBATCH-BATCH, oref TYPE REF TO cx_root, l_num type i, l_len type i, l_len1(2) type c.
-
Mail message viewer displays wrong message
Here's a strange one, started a couple of days ago: for most new messages, when I select the message in the upper pane, the message displayed in the viewing pane is not the one I selected. For example: a new message comes in from Joe, I click on it,
-
I just purchased a Treo 700p(Sprint), it seemed to work fine, no noted issues or problems, until I HotSynch'd it. Now... 1. HotSynch failed to backup PmTraceDatabase(handheld file could not be opened). 2. The Treo reboots when I try to do some things
-
What is fire fox and will it help/hurt my mac
The kid put fire fox on the mac just want to know what it is
-
Web-based filters that don't substitute words?(for sites safari can't go 2)
I haven't been able to get around a problem I addressed in another question, a site where I get an "Invalid IP used" message. I have found that I can visit the site using a web-based filter like: http://websmurfer.devnull.net/ There are two drawbacks