JOINing on tables with missing rows
Given this DDL:
CREATE TABLE #Events
EventID INT,
BallroomCharge NUMERIC(10,2)
INSERT INTO #Events VALUES (1001, 10)
INSERT INTO #Events VALUES (1002, 25)
CREATE TABLE #EventFacility
EventID INT,
FacilityID int,
ServiceCharge NUMERIC(10,2)
INSERT INTO #EventFacility VALUES (1001, 1, 100)
INSERT INTO #EventFacility VALUES (1001, 2, 110)
INSERT INTO #EventFacility VALUES (1001, 3, 120)
INSERT INTO #EventFacility VALUES (1002, 1, 200)
INSERT INTO #EventFacility VALUES (1002, 2, 210)
CREATE TABLE #Facility
FacilityID int,
FacilityName VARCHAR(10)
INSERT INTO #Facility VALUES (1, 'Main Hall')
INSERT INTO #Facility VALUES (2, 'Theatre')
INSERT INTO #Facility VALUES (3, 'BallRoom')
For each event, there may be multiple related facilities. However, not all events will have all facilities. However, one of the facilities (Ballroom) has a charge which must be applied whether a Ballroom is attached to the event or not. The data set returned
should look like this:
EventID FacilityID Total
1001 1 100
1001 2 110
1001 3 130 (120 + 10 from the Events.Ballroom charge)
1002 1 200
1002 2 210
1002 3 25 (No Ballroom entry but 25 from the Events.Ballroom charge)
The problem is that I can't get the last row to appear as there is no matching entry in the EventFacility table.
My SQL so far (which doesn't work) is here:
WITH MyCTE(EventID, FacilityID, ServiceCharge, FacilityName)
AS
SELECT ef.EventID, f.FacilityID, ef.ServiceCharge, f.FacilityName
FROM #EventFacility ef
INNER JOIN #Facility f ON ef.FacilityID = f.FacilityID
SELECT e.EventID,
c.FacilityID,
c.FacilityName,
ISNULL(c.ServiceCharge, 0) + e.BallroomCharge AS Total
FROM #Events e
LEFT OUTER JOIN MyCTE c ON c.EventID = c.EventID
WHERE e.EventID IN (1001, 1002)
AND c.FacilityID = 3
Any ideas as to how I would go about doing this?
a Very small change to the query if you want to add the BallroomCharge column, only for the BallRoom and not to all rows:
select E.EventID, F.FacilityID, (case when F.FacilityID = 3 then E.BallroomCharge else 0 end) + ISNULL(EF.ServiceCharge,0)
from #Events E
CROSS JOIN #Facility F
left JOIN #EventFacility EF ON E.EventID = EF.EventID and F.FacilityID = EF.FacilityID
Ronen Ariely
[Personal Site] [Blog] [Facebook]
Similar Messages
-
How to join 2 tables with unequal rows without resulting in a cartesian join
Hello,
This is the first time I have ever posted in any forum so please tell me if I should be doing this better.
Basically I have 2 tables with an unequal number of rows. For demonstration purposes, assume these are my 2 tables:
Table 1:
BaseKey
Letters
A
A
A
B
A
C
B
A
B
B
Table 2:
BaseKey
Numbers
A
1
A
2
B
1
B
2
B
3
I need to join them so that the data would appear like this
BaseKey
Letters
Numbers
A
A
1
A
B
2
A
C
null
B
A
1
B
B
2
B
null
3
Does anyone have any ideas how to do this using T-SQL without creating a cartesian join of 12 rows?
Thanks.>> This is the first time I have ever posted in any forum so please tell me if I should be doing this better. <<
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 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. What you did post is useless! Can you program from it? Neither can we. And we have to do all the extra typing for you.
CREATE TABLE Foo
(base_something CHAR(1) NOT NULL,
something_letter CHAR(1) NOT NULL,
PRIMARY KEY (base_something, something_letter));
INSERT INTO Foo
VALUES ('A', 'A'),
('A', 'B'),
('A', 'C'),
('B', 'A'),
('B', 'B');
CREATE TABLE Bar
(CHAR(1) NOT NULL,
something_digit CHAR(1) NOT NULL,
PRIMARY KEY (base_something, something_digit));
INSERT INTO Foo
VALUES ('A', '1'),
('A', '2'),
('B', '1'),
('B', '2'),
('B', '3');
>> I need to join them so that the data would appear like this
base_something Letters Numbers <<
This looks like you are taking two decks of punch cards and merging them together, without any logical rules, just physical position in their decks relative to the base_something groups.
WITH Foo_Deck
AS
(SELECT base_something, something_letter,
ROW_NUMBER()
OVER (PARTITION BY base_something
ORDER BY something_letter) AS card),
Bar_Deck
AS
(SELECT base_something, something_digit,
ROW_NUMBER()
OVER (PARTITION BY base_something
ORDER BY something_digit) AS card),
SELECT F.base_something, F.something_digit, B.something_letter
FROM Foo_Deck AS F
LEFT OUTER JOIN
Bar_Deck AS B
ON B.base_something = F.base_something
AND B.card = F.card;
--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 -
Select on table with 1800 rows is slow
I have a table with 1800 rows. Each entry has a geometry position and a geometry polygon around the position. I am using the polygon to detect which (other) entries are near the current entry.
In the following testdata and the subsequent query, i am filtering on 625 (of 1865) rows, and then using the .STContains-method to finding other rows (the testdata is fully found by this query, in the live database the values are not so regular as in the testdata.
The query take 6500 ms. In the live database, only 800 records are (yet) in the table, and it takes 2200 ms.
select SlowQueryTable.id
from SlowQueryTable
inner join dbo.SlowQueryTable as SlowQueryTableSeen
on SlowQueryTable.[box].STContains(SlowQueryTableSeen.position) = 1
where SlowQueryTable.userId = 2
(The query in the live system is even more complex, but this is main part of it and even simplified as it is just takes too long).
This script generates test data and runs the query:
-- The number table is just needed to generate test data
CREATE TABLE [dbo].[numbers](
[number] [int] NOT NULL
go
declare @t table (number int)
insert into @t select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9
insert into numbers
select * from
select
t1.number + t2.number*10 + t3.number*100 + t4.number*1000 as x
from
@t as t1,
@t as t2,
@t as t3,
@t as t4
) as t1
order by x
go
-- this is the table which has the slow query. The Columns [userId], [position] and [box] are the relevant ones
CREATE TABLE [dbo].SlowQueryTable(
[id] [int] IDENTITY(1,1) NOT NULL,
[userId] [int] NOT NULL,
[position] [geometry] NOT NULL,
[box] [geometry] NULL,
constraint SlowQueryTable_primary primary key clustered (id)
create nonclustered index SlowQueryTable_UserIdKey on [dbo].SlowQueryTable(userId);
--insert testdata: three users with each 625 entries. Each entry per user has its unique position, and a rectangle (box) around it.
-- In the database in question, the positions are a bit more random, often tens of entries have the same position. The slow query is nevertheless visible with these testdata
declare @range int;
set @range = 5;
INSERT INTO [dbo].SlowQueryTable (userId,position,box)
select
users.number,
geometry::STGeomFromText('POINT (' + convert(varchar(15), X) + ' ' + convert(varchar(15), Y) + ')',0),
geometry::STPolyFromText('POLYGON ((' + convert(varchar(15), X - @range) + ' ' + convert(varchar(15), Y - @range) + ', '
+ convert(varchar(15), X + @range) + ' ' + convert(varchar(15), Y - @range) + ', '
+ convert(varchar(15), X + @range) + ' ' + convert(varchar(15), Y + @range) + ', '
+ convert(varchar(15), X - @range) + ' ' + convert(varchar(15), Y + @range) + ','
+ convert(varchar(15), X - @range) + ' ' + convert(varchar(15), Y - @range) + '))', 0)
from (
select
(numberX.number * 40) + 4520 as X
,(numberY.number * 40) + 4520 as Y
from numbers as numberX
cross apply numbers as numberY
where numberX.number < (1000 / 40)
and numberY.number < (1000 / 40)) as positions
cross apply numbers as users
where users.number < 3
CREATE SPATIAL INDEX [SlowQueryTable_position]
ON [dbo].SlowQueryTable([position])
USING GEOMETRY_GRID
WITH (
BOUNDING_BOX = ( 4500, 4500, 5500, 5500 ),
GRIDS =(LEVEL_1 = HIGH,LEVEL_2 = HIGH,LEVEL_3 = HIGH,LEVEL_4 = HIGH),
CELLS_PER_OBJECT = 64, PAD_INDEX = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
go
ALTER INDEX [SlowQueryTable_position] ON [dbo].SlowQueryTable
REBUILD;
go
CREATE SPATIAL INDEX [SlowQueryTable_box]
ON [dbo].SlowQueryTable(box)
USING GEOMETRY_GRID
WITH ( BOUNDING_BOX = ( 4500, 4500, 5500, 5500 ) ,
GRIDS =(LEVEL_1 = HIGH,LEVEL_2 = HIGH,LEVEL_3 = HIGH,LEVEL_4 = HIGH),
CELLS_PER_OBJECT = 64, PAD_INDEX = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
go
ALTER INDEX [SlowQueryTable_box] ON [dbo].SlowQueryTable
REBUILD;
go
SET STATISTICS IO ON
SET STATSTICS TIME ON
-- this is finally the query. it takes about 6500 ms
select SlowQueryTable.id
into #t1
from SlowQueryTable
inner join dbo.SlowQueryTable as SlowQueryTableSeen
on SlowQueryTable.[box].STContains(SlowQueryTableSeen.position) = 1
--on SlowQueryTable.position.STDistance(SlowQueryTableSeen.position) < 5
where SlowQueryTable.userId = 2
drop table #t1
drop table SlowQueryTable
drop table numbers
Using an explicit index hint does do the job, but then the query gets slow if i change the where clause:
select SlowQueryTable.id
into #t1
from SlowQueryTable
with (index([SlowQueryTable_box]))
inner join dbo.SlowQueryTable as SlowQueryTableSeen
on SlowQueryTable.[box].STContains(SlowQueryTableSeen.position) = 1
where SlowQueryTable.userId = 2
leads to 600ms, and changing the where clause
where SlowQueryTable.id = 100
slows it again down to 1200ms. Filtering on ID get massively slowed down when using index hint on the spatial index.
Since the table in the live system will grow to 10000+ rows, and the query is called often by users, I badly need a more efficient query.
Do I have to create a different queries for each use-case, some with index hints and some without?I've run your example and can confirm your results. There's a couple of things that I noticed though.
After looking at query plans, it's not a matter of "with spatial index" vs. "without spatial index". You have two spatial indexes, one on each column (position and box). When you don't hint the "box" spatial index, the query
uses the "position" spatial index. Because of what they are indexing (points vs. polygons), the "box" spatial index requires a lot more IO. With some (non-spatial) predicates, the "box" spatial index gives better performance,
with others the "position" one does. I've yet to figure out exactly why (short on time, I might get back to it in future), but you can examine query plans and use the spatial index diagnostic procs (e.g. sp_help_spatial_geometry_index_xml ) in
addition to the diagnostics you're running to see why and if you can find a better performing plan/index.
Bear this in mind. Given a choice of multiple spatial indexes, the SQL Server query optimizer is not able to choose (for the most part, IO etc. aside), which one is best. Also, there is usually only one choice of spatial query plan shape, in general. If
your query is more complex than the one in your example, you might benefit by breaking it in two: one query to filter out all the rows and predicates that don't use a spatial index and one query that uses the spatial index on the subset. I've had good
luck with this other situations with complex queries involving spatial predicates. This method may not be applicable to a spatial query as simple as the one in your example, however.
Hope this helps, Bob -
Joining 3 tables with null values
Hi,
I have three tables that have varying data in. I want to write a query which will list all three in the result set, but when one of the tables doesn't have a row, write in No Value.
I will be intending on joining the tables with account numbers. What will be the syntax of a join with three tables where I am not sure which table will have null values?
Thanks...Something like
select nvl(a.id,'No Value'), nvl(b.id, 'No Value'), nvl(C.id, 'No Value')
from (select id from t1) a,
(select id from t2) b,
(select id from t3) c
where a.id = b.id(+)
and a.id = c.id(+)
Hi,
I have three tables that have varying data in. I want to write a query which will list all three in the result set, but when one of the tables doesn't have a row, write in No Value.
I will be intending on joining the tables with account numbers. What will be the syntax of a join with three tables where I am not sure which table will have null values?
Thanks... -
Join fact table with higher dimension level
how do i join fact tables with higher dimension levels with discoverer?
fact with detail at level C
measure X
dimension with
D->C->B->A
E->C
level
A B C
1------1------1
2------2------1
3------2------1
join between fact X and dimension level C
X=3*C because of sum(X) in discoverer and 3xC in dimension
is there a way to get correct values for X without creating a dimension like
D->C
E->another way of asking this is whether you can create a summary table in Discoverer at a higher level than a dimension's fundamental grain. In other words - the summary examples in the documentation all describe leaving out one or more of your dimensions... they are either left in or completely taken out. But, some of the most effective summarization occurs when you summarize daily data to a monthly level. Assuming that I have a sales table (at a daily level, and a key value sales_date), and a table date_dim (primary key sales_date), I would like to create a summary sales_month_summary where the sales are grouped on month_year (which is a field in the sales_date table).
How is this done? I suspect that we can't use the date_dim table with the summary (due to the problems noted by the poster above). Do we have to create another table "month_dim"? Do we have to fold all of the desired date attributes (month, quarter, year) into the summary? Obviously we'd like to re-use all of the pertinent already existing date items (quarter, month, year, etc.), not recreate them over again, which would result in essentially two sets of items in the EUL. [One used for this month summary, and another used for the detail.]
I searched the forum - someone asked this same question back in 2000 - there was no answer provided.
The only other thought I have is to "snowflake" the date_dim into two tables and two folders, one at a date level, another at the month level. Then the detail tables can connect to date_dim (which is linked to month_dim), while the summary data can connect directly to month_dim. -
Left outer join 3 tables with where-statement
Hi folks,
I hope you can understand (and maybe solve) my problem.
Generally I try to left outer join three tables. The third table is used for a WHERE-statement.
The three table structures are the following:
table 1 (user)
user1 | key
table 2 (detail)
key | ID
table 3 (header)
ID | user2
...and I want to achieve the following structure (as example filled with data):
user | key | ID
|-----|----
xy | a | 001
xy | b | #
z | b | #
The clue ist the usage of the third table. I need the table to set user1 and user2 equal (WHERE) but there are two problems:
1) Obviously I can't left outer join two tables with each other. In this case I already used the 'key' of table 1 to join it with the 'key' of table 2. So I can't left outer join the 'ID' of table 2 with the 'ID' of table 3. Error message that I can only left outer join a table once. Any proposals?
2) I have to include a WHERE to equal user1 with user2. But I am not allowed to use the user2 from table 3 because of the left outer join.
I tried this coding:
SELECT auser1 akey b~id INTO TABLE itab FROM ( table1 AS a
LEFT OUTER JOIN table2 AS b ON akey = bkey )
LEFT OUTER JOIN table3 AS c ON bID = cID )
WHERE auser1 = cuser2.
I would really appreciate your help.
Regards
MrclSpdlIF you want to join a DB table with an internal table, you need to use the 'FOR ALL ENTRIES' statement.
select dbfields
into table itab2
from dbtab
for all entries in itab
where dbfield1 = itab-field1.
This will get you a second internal table with all the corresponding data for the first selection. You can then join them with a loop through the first table and a read table on the second table (for 1 - 1 relation) or a nested loop statement on both tables (for 1 - N relation). Make itab a hashed table when using read table with key, use a sorted table if you need to loop without key access.
Regards,
Freek -
TO DRAW A TABLE WITH MULTIPLE ROWS AND MULTIPLE COLOUMNS IN FORM
Hi,
How to draw a table with multiple rows and columns seperated by lines in form printing?check this
http://sap-img.com/ts003.htm
Regards
Prabhu -
How to insert a table with variable rows in smart form
Hi all,
How to insert a table with variable rows in smart form?
Any help would be appreciated.
Regards,
Mahesh.Hi,
Right click the mouse->create->table
If you want 5 columns, you need to declare 5 cells in one line type of the table
Click on Table -> Details, then do the following
Line Type 1 2 3 4 5
L1 2mm 3mm etc
Here specify the width of the columns as many as you want..
then in the header/main area of the table, click create Table Line, Rowtype is L1, automatically 5 cells will come,In each cell create a text element, display the variable to be printed there. -
Joining a table with all_tab_columns
How is it possible to join a table with the tab_columns?
The query im trying to establish is that in my table they are 12 columns with months names. So under an input variable im trying to return the required values with the selected months. The only way i could think of to get the months to connect with the tab_columns table.
Any suggestion is really appreciated
SELECT bust,
Sum(jan) JAN,
Sum(feb) FEB,
Sum(mar) MAR,
Sum(apr) APR,
Sum(may) MAY,
Sum(jun) JUN,
Sum(jul) JUL,
Sum(aug) AUG,
Sum(sep) SEP,
Sum(oct) OCT,
Sum(nov) NOV,
Sum(DEC) DECC
FROM budget a,all_tab_columns b
WHERE vsl_code = 4602
AND code = 1
AND year=2013
AND account_code='30'
AND b.table_name='BUDGET'
AND b.column_name IN
(SELECT column_name
FROM (SELECT Column_name, ROWNUM r
FROM all_tab_columns b
WHERE table_name = 'BUDGET'
AND Column_id BETWEEN 3 AND 14
ORDER BY column_id)
WHERE r BETWEEN 2 AND 3 ) --Returns February,March
group by bust;Sorry, I don't understand what you're trying to do or why you think you need to join to all_tab_columns. Perhaps you could post the definition of the budget table, some sample data, and the results you're hoping to see.
Without that, I don't see why you can't just do this:
SELECT bust,
Sum(jan) JAN,
Sum(feb) FEB,
Sum(mar) MAR,
Sum(apr) APR,
Sum(may) MAY,
Sum(jun) JUN,
Sum(jul) JUL,
Sum(aug) AUG,
Sum(sep) SEP,
Sum(oct) OCT,
Sum(nov) NOV,
Sum(DEC) DECC
FROM budget a
WHERE vsl_code = 4602
AND code = 1
AND year=2013
AND account_code='30'
group by bust; -
Hi,
My doubt is can I join the table with view in the below where clause condition in the query. If yes, the below query will take 4 hrs to execute it. Can I do the below query to write as simplest?
SELECT *
FROM uabpymt p, uavlsum l
WHERE uabpymt_appl_ind = 'N'
AND uabpymt_amount > 5
AND l.uavlsum_balance < 0
AND l.uavlsum_cust_code = p.uabpymt_cust_code
AND l.uavlsum_prem_code = p.uabpymt_prem_codeuavlsum ---view
uabpymt ---table
The view script below:
CREATE OR REPLACE VIEW UAVLSUM
(UAVLSUM_CUST_CODE, UAVLSUM_PREM_CODE, UAVLSUM_AMOUNT, UAVLSUM_BALANCE)
AS
SELECT cust_code,
prem_code,
SUM(amount),
SUM(balance)
FROM (
SELECT uabopen_cust_code cust_code,
uabopen_prem_code prem_code,
uabopen_billed_chg amount,
uabopen_balance balance
FROM uimsmgr.uabopen
UNION ALL
SELECT uabpymt_cust_code,
uabpymt_prem_code,
uabpymt_amount * -1,
uabpymt_balance * -1
FROM uimsmgr.uabpymt
UNION ALL
SELECT uabadje_cust_code,
uabadje_prem_code,
uabadje_balance,
to_number(0)
FROM uimsmgr.uabadje
WHERE uabadje_balance <> 0)
GROUP BY cust_code,
prem_codeFind the below explain plan output which we get from the execute the query
STATEMENT_ID TIMESTAMP REMARKS OPERATION OPTIONS OBJECT_NODE OBJECT_OWNER OBJECT_NAME OBJECT_INSTANCE OBJECT_TYPE OPTIMIZER
16/01/2009 05:57:24 SELECT STATEMENT RULE
16/01/2009 05:57:24 FILTER
16/01/2009 05:57:24 SORT GROUP BY
16/01/2009 05:57:24 TABLE ACCESS BY INDEX ROWID UIMSMGR UABPYMT 1
16/01/2009 05:57:24 NESTED LOOPS
16/01/2009 05:57:24 VIEW UIMSMGR 3
16/01/2009 05:57:24 UNION-ALL
16/01/2009 05:57:24 TABLE ACCESS FULL UIMSMGR UABOPEN 4
16/01/2009 05:57:24 TABLE ACCESS FULL UIMSMGR UABPYMT 5
16/01/2009 05:57:24 TABLE ACCESS FULL UIMSMGR UABADJE 6
16/01/2009 05:57:24 INDEX RANGE SCAN UIMSMGR UABPYMT_CUST_PREM_INDEX NON-UNIQUE
Index column:
Table name :UABPYMT
Column Name
UABPYMT_APPL_IND
UABPYMT_APPROVED_IND
UABPYMT_PYMT_DATE
UABPYMT_SOURCE
UABPYMT_ORIGIN
UABPYMT_CUST_CODE
UABPYMT_PREM_CODE
UABPYMT_PYMT_DATE
UABPYMT_AR_TRANS
UABPYMT_GL_IND
UABPYMT_GL_POST_DATE
UABPYMT_AR_TRANS -
Hi
I have a problem to import a dump that contains the tables with 0 rows.
When i exported from ORACLE 11.2 64 bit on SERVER 2008 i noticed that log didn't confirm the tables with 0 rows.
When i want to import to ORACLE 11.2 64 bit on other SERVER 2008 i have a lot of errors on this tables with 0 rows.
In the log i get the same tables with 1 row at least, but no one with 0 rows.
I open my dump in TEXTPAD and i see it contains "CREATE ....." these tables.
I don't understand why it happens. I used FUll DUMP by SYS, it didn't help.
This is not first time when i export and import dumps,no errors.
I'm using command "EXP" and "IMP" and every time it's ok.(IF it's a releavent)
Why it happens? any solutions for this issue?
ThanksI've found (i guess so) solution to this issue
here are two links to this new feature that is called deffered segment creation
The reason for this behavior is 11.2 new feature ‘Deferred Segment Creation‘ – the creation of a table sent is deferred until the first row is inserted.
As a result, empty tables are not listed in dba_segments and are not exported by exp utility
http://www.nativeread.com/2010/04/09/11gr2-empty-tables-skipped-by-export-deferred-segment-creation/
http://antognini.ch/2010/10/deferred-segment-creation-as-of-11-2-0-2/
And this is i've found in official documentation from oracle
Beginning in Oracle Database 11g Release 2, when creating a non-partitioned heap-organized table in a locally managed tablespace, table segment creation is deferred until the first row is inserted. In addition, creation of segments is deferred for any LOB columns of the table, any indexes created implicitly as part of table creation, and any indexes subsequently explicitly created on the table.The advantages of this space allocation method are the following:A significant amount of disk space can be saved for applications that create hundreds or thousands of tables upon installation, many of which might never be populated.Application installation time is reduced.There is a small performance penalty when the first row is inserted, because the new segment must be created at that time.
To enable deferred segment creation, compatibility must be set to '11.2.0' or higher. You can disable deferred segment creation by setting the initialization parameter DEFERRED_SEGMENT_CREATION to FALSE. The new clauses SEGMENT CREATION DEFERRED and SEGMENT CREATION IMMEDIATE are available for the CREATE TABLE statement. These clauses override the setting of the DEFERRED_SEGMENT_CREATION initialization parameter.
+Note that when you create a table with deferred segment creation (the default), the new table appears in the _TABLES views, but no entry for it appears in the SEGMENTS views until you insert the first row. There is a new SEGMENTCREATED column in _TABLES, _INDEXES, and _LOBS that can be used to verify deferred segment creation+
Note:
The original Export utility does not export any table that was created with deferred segment creation and has not had a segment created for it. The most common way for a segment to be created is to store a row into the table, though other operations such as ALTER TABLE ALLOCATE EXTENTS will also create a segment. If a segment does exist for the table and the table is exported, the SEGMENT CREATION DEFERRED clause will not be included in the CREATE TABLE statement that is executed by the original Import utility. -
How to create table with 1 row 1MB in size?
Hello,
I am doing some R&D and want to create a Table with 1 row, which is 1 MB in size.
i.e. I want to create a row which is 1 MB in size.
I am using a 11g DB.
I do this in SQL*Plus:
(1.) CREATE TABLE onembrow (pk NUMBER PRIMARY KEY, onembcolumn CLOB);
(2.) Since 1MB is 1024*1024 bytes (i.e. 1048576 bytes) and since in English 1 letter = 1 byte, I do this
SQL> INSERT INTO onembrow VALUES (1, RPAD('A', 1048576, 'B'));
1 row created.
(3.) Now, after committing, I do an analyze table.
SQL> ANALYZE TABLE onembrow COMPUTE STATISTICS;
Table analyzed.
(4.) Now, I check the actual size of the table using this query.
select segment_name,segment_type,bytes/1024/1024 MB
from user_segments where segment_type='TABLE' and segment_name='ONEMBROW';
SEGMENT_NAME
SEGMENT_TYPE
MB
ONEMBROW
TABLE
.0625
Why is the size only .0625 MB, when it should be 1 MB?
Here is the DB Block related parameters:
SELECT * FROM v$parameter WHERE upper(name) LIKE '%BLOCK%';
NUM NAME TYPE VALUE
478 db_block_buffers 3 0
482 db_block_checksum 2 TYPICAL
484 db_block_size 3 8192
682 db_file_multiblock_read_count 3 128
942 db_block_checking 2 FALSE
What am I doing wrong here???When testing it is necessary to do something that is a reasonably realistic model of a problem you might anticipate appearing in a production system - a row of 1MB doesn't seem likely to be a useful source of information for "R&D on performance tuning"
What's wrong with creating millions of rows ?
Here's a cut and paste from a windows system running 11.2.0.3
SQL> set timing on
SQL>
SQL> drop table t1 purge;
Table dropped.
Elapsed: 00:00:00.04
SQL>
SQL> create table t1
2 nologging
3 as
4 with generator as (
5 select
6 rownum id
7 from dual
8 connect by
9 level <= 50
10 ),
11 ao as (
12 select
13 *
14 from
15 all_objects
16 where rownum <= 50000
17 )
18 select
19 rownum id,
20 ao.*
21 from
22 generator v1,
23 ao
24 ;
Table created.
Elapsed: 00:00:07.09
7 seconds to generate 2.5M rows doesn't seem like a problem. For a modelling example I have one script that generates 6.5M (carefully engineered) rows, with a couple of indexes and a foreign key or two, then collects stats (no histograms) in 3.5 minutes.
Regards
Jonathan Lewis
http://jonathanlewis.wordpress.com
Now on Twitter: @jloracle -
Filtering a table with 19699 rows
Hello
I am new to Xcelsisu and I am trying to aply filter component to a table with 19699 rows. I is suppose to show in the filter 45 diferent clasifications. I seems to be using only the first 500 rows to aply the filter. I changed the maximum number of rows in the preferences. What should i do ?a component cannot handle 20.000 rows you should filter these in the database by using quries when getting the data in the dashboard. If there is no database connection available, you can use pivot tables to create list for the different dimensions and then use lookup formulas like match and index o display the data for your chart.
-
hello
i'm trying to join 2 tables with 2 criteria
one criteria is "numero de matricule" and the other is "date"
in one table i have many times the same "matricule" it depends of "date de validité" validity date
ex table 1
n°mat - periode - montant
1 -31-12-2013 - 100
table2
n°mat -periode - nom - adresse
1 -
31-12-2013 - gerard - 12 RUE X
1- 31/12/2012-GERARD - 2AVENUE Z
how can i join those tow table
thak you for your help, i'm a french beginnerselect *
from table1 as a
join table2 as b
on a.n°mat = b.n°mat
and a.periode = b.periode
sqldevelop.wordpress.com
Saeid, check this out and reply there if you're interested:
http://social.technet.microsoft.com/Forums/en-US/a2e22d61-7c32-43f2-900e-d9d6325fa26d/needed-more-power-pivot-answerers?forum=sqlkjpowerpivotforexcel
Thank you for all your contributions!
Ed Price, Azure & Power BI Customer Program Manager (Blog,
Small Basic,
Wiki Ninjas,
Wiki)
Answer an interesting question?
Create a wiki article about it! -
Join Istore table with AR tables
Hi Gurus,
How to join ibe_msites_b table with AR table. I am trying to get list of all customers from different mini sites. These are the AR tables i am using
HZ_Cust_Accounts
HZ_Parties
Regards,The following query should give you resullts for B2C. Change the query based on your requirement incase if you want it for B2B. Please note that I haven't added alll the conditions. This should be your starting point.
Hope this helps,
RK
SELECT imt.msite_name,
hp.party_name
FROM jtf_um_subscription_reg jusr,
jtf_um_subscription_resp jure,
fnd_responsibility fr,
ibe_msite_resps_b imrb,
ibe_msites_tl imt,
fnd_user fu,
hz_parties hp
WHERE jusr.subscription_id = jure.subscription_id
AND jure.responsibility_key = fr.responsibility_key
AND fr.responsibility_id = imrb.responsibility_id
AND imrb.msite_id = imt.msite_id
AND imt.language = USERENV('LANG')
AND fu.user_id =jusr.user_id
AND fu.person_party_id = hp.party_id
Maybe you are looking for
-
Hi, Can anybody direct me to the easiest way to do this in sql? select from table where if :condition = 1 then fieldA = 'Yes' else if :condition = 2 the fieldB = 'Yes'; I tried to use the CASE statement, but I don't think I have the syntax correct. I
-
Can't send mail... after 4 months of using it
I'm stumped... help me out please. When i send a mail out, this message pops up, "Error : This Message could not be delivered and will remain in your Outbox until it can be delivered. Sending the message content to the server failed." So it's still i
-
I just bought a d2 Lacie external hd for my powerbook so that i can fit all those videos... i wanted to know what format i should put the external hd in... i would like to be able to use it with windows computers but if there is a big differance then
-
I need Technical Presentation For WSA
Dear all i need technical presentation for cisco Web Security appliance only to show the benefit , deployment type , Competitor i need this presentation because the audiences and speaker are technical engineer
-
hi, i read that rosettanet pip's or(partner interface process) are provided in the IR .. please tell me what is it (pip) used for & where it can be found in IR ( Like idocs & rfc's r present in imported objects where r they )? thanking you