FK reference PK in same table
Hello,
I have a table defined as follows
create table MATABLE (
ID INTEGER not null,
FK INTEGER not null,
constraint PK_MATABLE primary key (ID)
alter table MATABLE
add constraint FK_MATABLE_REFERENCE_MATABLE foreign key (FK)
references MATABLE (ID);*********************************************
I understand the FK reference the PK in the same table. My first question is can anybody give me a practical example of having the above architecture/relation. A sample of a few lines together with a short explanation of a business logic example would be great.
I am assuming that this is one of the posts that had the wrong date applied between September 3rd and 7th, 2004.
The following is an example of a practical application. In this example, using the Oracle emp demo table, a constraint is placed such that any manager (mgr)entered must already be an employee (empno). This prevents entry of a manager, who is not an employee.
scott@ORA92> -- emp data:
scott@ORA92> select empno, mgr, deptno from emp
2 /
EMPNO MGR DEPTNO
7369 7902 20
7499 7698 30
7521 7698 30
7566 7839 20
7654 7698 30
7698 7839 30
7782 7839 10
7788 7566 20
7839 10
7844 7698 30
7876 7788 20
7900 7698 30
7902 7566 20
7934 7782 10
14 rows selected.
scott@ORA92> -- add constraint:
scott@ORA92> alter table emp
2 add constraint emp_fk_emp foreign key (mgr)
3 references emp (empno)
4 /
Table altered.
scott@ORA92> -- will not allow insert of manager (mgr) who is not an employee (empno):
scott@ORA92> insert into emp (empno, mgr, deptno) values (1111, 9999, 10)
2 /
insert into emp (empno, mgr, deptno) values (1111, 9999, 10)
ERROR at line 1:
ORA-02291: integrity constraint (SCOTT.EMP_FK_EMP) violated - parent key not found
scott@ORA92> -- will allow insert of manager (mgr) who is an employee (empno):
scott@ORA92> insert into emp (empno, mgr, deptno) values (1111, 7934, 10)
2 /
1 row created.
Similar Messages
-
Mapping to the same table through multiple references
Hello,
I'm trying to map aggregate fields (from my target) to mutlitple tables (back on my source), but am hung up because I need multiple references to the same table (basically a lookup values table) in my target. I believe that the problem lies in not being able to reference (in the mapping workbench at least) the same table more than once (such as through an alias, or otherwise defining multiple references) in the multi-tables tab. Is there a way around this, or some other approach to mapping it that I can take?
Thank you,
JohnNot exactly sure what you are trying to do, perhaps listing the object model and data model would help.
If you are having trouble mapping the aggregate in the Mapping Workbench you may be able to workaround the problem through using a descriptor or project amendment method and defining the mapping through the code API. -
One Table more than one Relationship to same Table
Hello,
I have the following scenario.
One Table called Hotel and one Table Called Competitor. Each hotel can have several competitors. So i structured the tables in my Azure SQL database like this:
Hotel:
HotelID (int, Primary Key)
Name (String)
etc.
Competitor Table:
ComeptitorID (int identity Primary Key)
HotelID int
CompetitorHotelID int
When i import the tables in my LS Project i get some issues, like the autocomplete box are not filled up.
Is there a problem if a table has two references to the same table.
Thank you so much for amy helpHi, this setup works in LightSwitch built in the intrinsic data source.
Hotel <Zero_or_1-to-Many> Competitor <Many-to-Zero_or_1> Hotel
So a hotel can have many competitors and a competitor can compete with many hotels.
Is it possible for you to switch to this?
Cheers
Dave
Dave Baker | AIDE for LightSwitch | Xpert360 blog | twitter : @xpert360 | Xpert360 website | Opinions are my own. For better forums, remember to mark posts as helpful/answer. -
SQL error msg - The DELETE statement conflicted with the SAME TABLE REFERENCE constraint
Executed as user: ****. The DELETE statement
conflicted with the SAME TABLE REFERENCE constraint "FK_PARENT_TASK_REF".
The conflict occurred in database "****", table "****", column
'PARENT_TASK_ID'. [SQLSTATE 23000] (Error 547) The statement has been
terminated. [SQLSTATE 01000] (Error 3621). The step failed.
Does this error msg indicate the whole script failed to execute or was it just a single step/task that failed ?
What does error msg mean ?
Anyway to prevent this error msg and ensure script runs successfullyHi mdavidh,
This error occurs because the record 'PARENT_TASK_ID' was referenced by 'FK_PARENT_TASK_REF'.
Please refer below codes:
CREATE TABLE MyTable (
ID INT, primary key(ID), -- primary key
ID_Parent INT foreign key(ID_Parent) references MyTable(ID), -- foreign key reference the same table
insert into MyTable(ID,ID_Parent)
values(0,0);
insert into MyTable(ID,ID_Parent)
values(1,0);
insert into MyTable(ID,ID_Parent)
values(2,0);
insert into MyTable(ID,ID_Parent)
values(3,1);
insert into MyTable(ID,ID_Parent)
values(4,3);
insert into MyTable(ID,ID_Parent)
values(5,4);
CREATE TRIGGER MyTrigger
on MyTable
instead of delete
as
set nocount on
update MyTable set ID_Parent = null where ID_Parent in (select ID from deleted)
delete from MyTable where ID in (select ID from deleted)
Now we could delete records.
delete from MyTable where ID_Parent=0
Thanks,
Candy Zhou -
How do I sum across the same table in multiple sheets?
So I'm trying to figure out an annoying problem.
I have a largish (100's) amount of data with each collection being a table in a sheet, one sheet per data collection. This means I have 100's of sheets, each with the same table name and layout. Each sheet has several hundred data points in it.
How do I do a sum across all of the same table in all the sheets?
For example I want to do Sum('Data Sheet Number *'::'Table 1'::A1) to get a sum of everything in all the A1 cells of all the sheets named 'Data Sheet Number ' followed by anything (I'm using the star in the same way one would do it in a shell...)
Thanks!
Message was edited by: unusedusername
Message was edited by: unusedusernameTo respond to WWJD: I was handed the data and I don't have any control over it's format...
I found the answer in the forums though, so I guess I'm answering my own question
http://discussions.apple.com/thread.jspa?messageID=6203991�
The auto-filling INDIRECT reference worked very well for me. -
Power Query; How do I reference a Power Pivot table from a Power Query query
Hi,
It's pretty awesome how you can define Extract Transform and Load processes within Power Query without having to type in a single line of code. However how do I reference a Power Pivot table from a Power Query query to avoid me repeatedly accessing
the same data source (CSV) file with a view to increasing performance?
We are aware of the reference sub menu option with Power Query. However the new query created by the "reference" option still seems to refresh data from the data source (CSV) rather than just referencing the base query. Is this understanding
correct? There does seem to be a lot of hard disk activity when re-running the new query which is based on a base query rather than a data source. So we were hoping the new query would just need to reference the base query in memory rather than rescanning
the hard disk. Is there any way to ensure that the reference query just rescans the base query in memory?
Kind Regards,
Kieran.
Kieran Patrick Wood http://www.innovativebusinessintelligence.com http://uk.linkedin.com/in/kieranpatrickwood http://kieranwood.wordpress.com/Hi Kieran,
This sounds like something to be suggested for a future release. At the present time, Power Query will always re-run the entire Power Query query when refreshed. The Reference feature is analogous to a SQL view whereby the underlying query is always re-executed
when it's queried, or in this case refreshed. Even something like using the Power Query cache to minimise the amount of data re-read from the disk would be helpful for performance but the cache is only used for the preview data and stored locally.
It would be a good idea to suggest this feature to the Power BI team via the feedback smiley face.
Regards,
Michael Amadi
Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to vote it as helpful :)
Website: http://www.nimblelearn.com, Twitter:
@nimblelearn
Hi Michael,
Glad to hear from you about this. And thanks to Kieran for bringing a very good valid point to debate. Will be glad to see this in future release.
- please mark correct answers -
Parent/child records from same table
I want to create a query that is a union such that the 2nd resultset is based on the 1st resultset. I have a table that has parent/child records in the same table.
Table: EVENTS
EVENT_ID
PARENT_EVENT_ID
CREATED_DATE
(other columns)
if PARENT_EVENT_ID is null then it is a parent record, else it is a child record. I want to select all parent records then union them with all the associated child records...something like this:
select * from EVENTS where CREATED_DATE < sysdate - 90 and PARENT_EVENT_ID is null -- All parents
union
select * from EVENTS where PARENT_EVENT_ID in (select EVENT_ID from EVENTS where CREATED_DATE < sysdate - 90 and PARENT_EVENT_ID is null) -- include any children of parents selected from above
This works but it's kind of ugly, I want to avoid using the sub-select in the 2nd because it is a repeat of the 1st statement, is there a way to alias the first statement and just refer to it in the 2nd query?Hi,
kev374 wrote:
Thanks, one question...
I did a test and it seems the child rows have to also satisfy the parent row's where clause, take this example:
EVENT_ID|PARENT_EVENT_ID|CREATED_DATE
2438 | (null) | April 9 2013
2439 | 2438 | April 11 2013
2440 | 2438 | April 11 2013
select * from EVENTS where CREATED_DATE < sysdate - 9
start with EVENT_ID = 2438
connect by PARENT_EVENT_ID = prior EVENT_IDSo you've changed the condition about only wanting roots and their children, and now you want descendants at all levels.
This pulls in record #2438 (per the sysdate - 9 condition) but 2439 and 2440 are not connected. Is there a way to supress the where clause evaluation for the child records? I just want to pull ALL child records associated with the parent and only want to do the date check on the parent.Since the roots (the only rows you want to exclude) have LEVEL=1, you can get the results you requested like this:
WHERE created_date < SYSDATE - 9
OR LEVEL > 1However, since you're not ruling out the grandchildren and great-grandchildren any more, why wouldn't you just say:
SELECT *
FROM events
WHERE created_date < SYSDATE - 9
OR parent_event_id IS NOT NULL;?
CONNECT BY is slow. Don't use it if you don't need it.
If you x-reference my original query:
select * from EVENTS where CREATED_DATE < sysdate - 90 and PARENT_EVENT_ID is null -- All parents
union
select * from EVENTS where PARENT_EVENT_ID in (select EVENT_ID from EVENTS where CREATED_DATE < sysdate - 90 and PARENT_EVENT_ID is null) -- include any children of parents selected from above
The 2nd select does not apply the created_date < sysdate - 90 on the children but rather pulls in all related children :)Sorry; my mistake. That's what happens when you don't post sample data, and desired results; people can't test their solutions and find mistakes like that. -
SUM two fileds from different rows from the same table
I would like to SUM two fileds from different rows from the same table but I don't know how to do that.
E.g.
BillingTransactionsIndex CreateDate UserType UserIndex TransType Reference Total Balance
2 6/5/2008 15:02 1 51 1 150 -288.2 -288.2
5 6/8/2008 11:55 1 51 1 157 -1.58674 -289.787
In the table above I want SUM fields Total and Balance for the first row and the the next row SUM 2nd row Total with 1st row Balance
Please help
ThanksSQL> with tbl as
2 (select 1 as ID, 90 as total from dual
3 union all
4 select 2 as ID, 23 as total from dual
5 union all
6 select 3 as ID, 15 as total from dual
7 union all
8 select 4 as ID, 20 as total from dual)
9 select id , total, sum(total) over (order by ID) as balance from tbl
10 /
ID TOTAL BALANCE
1 90 90
2 23 113
3 15 128
4 20 148
SQL> -
Hello,
I have a master table with several Forign Keys all of them to the same table. In order to display a column from the lookup table I'm using a select like:
select m.code,
m.lcode1, f1.label,
m.lcode2, f2.label,
m.lcode6, f6.label
from MTABLE m,
FTABLE f1,
FTABLE f2,
FTABLE f6
Where m.lcode1 = f1.code and
m.lcode2 = f1.code and
m.lcode6 = f6.codeIs this the correct and optimal way of doing it?
Thanks for the help,
Arie.Arie,
It sounds like perhaps the best way might be to create your forms/reports based upon a view instead of the underlying tables (especially if you are running 10gR1 or 10gR2).
I say this because:
1. With 10g (maybe even back in 9i?), you can create INSTEAD_OF triggers, so instead of manipulating (insert, update or delete) the view, the trigger has the code to perform the action to the underlying base tables instead.
2. This makes development easier, since all your joins are pre-defined in one place instead of re-creating them in numerous places.
3. Grants can be issued to the views, instead of the various tables, with just select privs to the lookup tables.
4. Change your join conditions to use the JOIN syntax, LEFT OUTER JOIN, etc., whatever is appropriate for your query. It's much easier to (eventually) figure out and maintain when you have multiple join conditions (especially against multiple tables), when any or all of them could null.
For details on the JOIN syntax or the INSTEAD_OF triggers, try the on-line Oracle documentation (I'm at home today and don't have all my reference material handy).
I'm using the above with great success (so far). I'm swamped with different work projects and different bosses and different priorities, so anything that makes my life easier is worth a couple hours of research, even if I have to do it from home in my off-time (if I can fit it into my schedule). I've been working on an HTMLDB (AppEx) application for over a year now, but I've probably only spent about 40-60 hours actually working on it, so I'm always forgetting most of what I've previously learned and done.
Bill Ferguson -
Update Rows with info from other Rows in Same Table.
I'm trying to update rows with information from the same table. The table gets loaded with info from a report that runs and it has to be a new entry every month but I would like to carry over some of the info from last month. This statement below runs but updates all rows in the new table load and in my test cases I only made a few match so only like 5 records should get updated. This is an example of what I'm trying to do. If I add this(C2.COL_INVC_ID = C1.COL_INVC_ID) to the last "*Where*" statement I get an invalid identifier for "C2.COL_INVC_ID". So what am I doing wrong here??? How can I update only the rows that where also in last months run???
Thanks in advance for any help!
Update OpenIssues OI1
Set(OI1.Num, OI1.Status, OI1.Code, OI1.LastModifiedDate) =
(Select OI2.Num, OI2.Status, OI2.Code, OI2.LastModifiedDate
From OpenIssues OI2
Where OI2.num = OI1.num and OI2.TableLoadDate = TO_DATE('01/31/2012 00:00:00', 'MM/DD/YYYY HH24:MI:SS')
Where and OI1.TableLoadDate = TO_DATE('02/29/2012 00:00:00', 'MM/DD/YYYY HH24:MI:SS')
SQLMeHi,
Welcome to the forum!
SQLMe wrote:
I'm trying to update rows with information from the same table. The table gets loaded with info from a report that runs and it has to be a new entry every month but I would like to carry over some of the info from last month. This statement below runs but updates all rows in the new table load and in my test cases I only made a few match so only like 5 records should get updated. This is an example of what I'm trying to do. If I add this(C2.COL_INVC_ID = C1.COL_INVC_ID) to the last "*Where*" statement I get an invalid identifier for "C2.COL_INVC_ID". If the aliases c1 and c2 aren't defined anywhere, then you can't use them anywhere.
The WHERE clause of the UPDATE statement can only reference the table being updated, ot1 in this case.
So what am I doing wrong here??? How can I update only the rows that where also in last months run???
Thanks in advance for any help!
Update OpenIssues OI1
Set(OI1.Num, OI1.Status, OI1.Code, OI1.LastModifiedDate) =
(Select OI2.Num, OI2.Status, OI2.Code, OI2.LastModifiedDate
From OpenIssues OI2
Where OI2.num = OI1.num and OI2.TableLoadDate = TO_DATE('01/31/2012 00:00:00', 'MM/DD/YYYY HH24:MI:SS')
Where and OI1.TableLoadDate = TO_DATE('02/29/2012 00:00:00', 'MM/DD/YYYY HH24:MI:SS')
------------There's a syntax error in the last line. Either something got lost when you posted the code, or you just don't want the keyword AND. You certainly don't want AND immediately after WHERE.
In general, if it's not obvious how to do an UPDATE, then UPDATE is the wrong tool: you want MERGE instead.
Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved.
Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
Simplify the problem as much as possible. Remove all tables and columns that play no role in this problem.
If you're asking about a DML statement, such as UPDATE, the CREATE TABLE and INSERT statements should re-create the tables as they are before the DML, and the results will be the contents of the changed table(s) when everything is finished.
Always say which version of Oracle you're using.
See the forum FAQ {message:id=9360002} -
Master and Detail records in the same table
Hi Steve,
I have master and detail address records in the same table (self-reference). The master addresses are used as templates for detail addresses. Master addresses do not have any masters. Detail addresses have three masters: a master address, a calendar reference and a department. Addresses change from time to time and every department has its own email-account, but they refer to the same master to pre-fill some common values.
Now I need to edit the master and detail address records on the same web page simultaneously.
My question is: Can I implement a Master-View and Detail-View which refer to the same Entity-Object? Or should I implement a second Entity-Object? Or can it be done in a single Master-Detail-View?
Thanks a lot.
Kai.At a high level, wouldn't this be similar to an Emp entity based on the familiar EMP table that has an association from Emp to itself for the Emp.Mgr attribute?
You can definitely build a view object that references two entity usages of the same entity like this to show, say, an employee's ENAME and at the same time their manager's ENAME.
If there are multiple details for a given master, you can also do that with separate VO's both based on the same entity, sure. Again, just like a VO that shows a manager, and a view-linked VO of all the employees that report to him/her. -
Foreign keys to same table / Who columns in User table???
Hi All,
We are designing a database for our client and we are using common columns in all tables like CreatedBy and UpdatedBy which are foreign keys to USER table. My question is can we use these two columns in USER table and have the foreign key constraints to the same tables?
USER table script will look like following..
CREATE TABLE XX_USER
User_ID VARCHAR2(10)
, CreatedBy NUMBER(10)
, UpdatedBy NUMBER(10)
, User_Name VARCHAR2(100) NOT NULL
, Designation VARCHAR2(100) NOT NULL
, CONSTRAINT USER_ISACTIVE_CHECK CHECK (Is_Active in ('Y', 'N'))
, CONSTRAINT USER_KEY PRIMARY KEY (User_ID),
, CONSTRAINT USER_CREATED_BY FOREIGN KEY (CREATED_BY)
REFERENCES XX_USER (USER_ID)
, CONSTRAINT USER_UPDATED_BY FOREIGN KEY (UPDATED_BY)
REFERENCES XX_USER (USER_ID)
);I think what I am doing (the above script) is not correct. Could someone please suggest me how can solve this issue?
Thanks in advance,
Oraebsuser8644385 wrote:
We are designing a database for our client and we are using common columns in all tables like CreatedBy and UpdatedBy which are foreign keys to USER table. My question is can we use these two columns in USER table and have the foreign key constraints to the same tables?You can. After fixing synatx errors:
SQL> CREATE TABLE XX_USER
2 (
3 User_ID VARCHAR2(10)
4 , CreatedBy NUMBER(10)
5 , UpdatedBy NUMBER(10)
6 , User_Name VARCHAR2(100) NOT NULL
7 , Designation VARCHAR2(100) NOT NULL
8 , Is_Active VARCHAR2(1)
9 , CONSTRAINT USER_ISACTIVE_CHECK CHECK (Is_Active in ('Y', 'N'))
10 , CONSTRAINT USER_KEY PRIMARY KEY (User_ID)
11 , CONSTRAINT USER_CREATED_BY FOREIGN KEY (CreatedBy)
12 REFERENCES XX_USER(USER_ID)
13 , CONSTRAINT USER_UPDATED_BY FOREIGN KEY (UpdatedBy)
14 REFERENCES XX_USER(USER_ID)
15 )
16 /
Table created.
SQL> Now USER_ID is a string while CreatedBy/UpdatedBy is a number. Even though it is allowed, it limits USER_ID to numeric strings and causes implicit conversions while validating. So I would change CreatedBy/UpdatedBy data type to VARCHAR2(10).
SY. -
Query Builder - 2 occurrences of same table and Show Related Tables
In SQL Developer 1.5 the Query Builder still does not allow you to drag two copies of the same table onto the canvas. Additionally the Show Related Tables does not appear to do anything even after Hide Related Tables. Both of these operations sets the cursor to the hourglass although you can continue working as if the commands completed OK. Query Builder is a great time saver but with limitations like this it is really hobbled.
Additionally, in order to get join conditions you have to double-click the join in the diagram before the appropriate WHERE clause appears. I have not found any reference to how to use the Query Builder in any documentation. This forum has stated that the Query Builder is supposed to be intuitive and easy to use but this is not the case so far.
The rest of SQL Developer is a pleasure to use!Thanks for your feedback. There are a number of things we want to do to the Query Builder. The issue about dragging 2 copies of a table onto the work surface is a logged enhancement request that we want to address. The Show Related tables and hourglass issues are bugs and need to be addressed. I'll document those.
Better documentation is also important and we can add that into the product for a future release.
In the short term, I have on previous occasion said I'd do a demo for using the Query Builder, so I'll make that a priority.
Sue -
Same table, Oracle 5 times slower than MySQL
Hi
I have several sites with the same aplication using a database as a log device and to later retrieve reports from. Some tables are for setup and one are for all the log data. The log data table has the following columns: LINEID, TAG, DATE_, HOUR_, VALUE, TIME_ and CHANGED. Typical data is: 122345, PA01_FT1_ACC, 2008-08-01, 10, 985642, "", 0.
Index (TAG,DATE_)
When calling a report the software querys for typical 3-5 select querys like the following, only different TAG: SELECT * FROM table WHERE TAG='PA01_FT1_ACC' AND DATE_ BETWEEN '2008-08-01' AND '2008-08-31' AND HOUR_=24
Since our customers have different preferences some sites have Oracle and some have MySQL. And I have registered that the sites running Oracle uses 24-30 sec on the report, MySQL uses 3-6 sec on a similar report with the same tables and querying software.
How is this?
Is there anything I can do to make Oracle work faster?
Should HOUR_ also be in the index?
Since I guess this slowness is not something consistant in Oracle, there must be something to do.
Thanks for any help.Histograms on varchar2 columns are based on the
first 6 bytes of the column. If the database is using
a character set that uses 1 byte per character, every
entry in the DATE_ column since the beginning of the
year looks like '2008-0' to the optimizer when
determining cardinality to produce the "best"
execution plan. For character sets that require
multiple bytes per character, the situation is worse
- every entry in the column representing this century
appears to be the same value to the optimizer when
determining cardinality
That's a very good point and I didnt know about it
before, about first 6 bytes being used. Can you point
me in the docs where it is listed if its there or
some other document/s which has this detail?Aman,
I am having a bit of trouble finding the information in the documentation about the number of bytes used by a histogram on a VARCHAR2 column.
References:
http://www.freelists.org/archives/oracle-l/08-2006/msg00199.html
"Cost-Based Oracle Fundamentals" page 117 shows a demonstration, and describes the use of ENDPOINT_ACTUAL_VALUE starting on Oracle 9i.
"Cost-Based Oracle Fundamentals" page 118-120 describes selectivity problems when histograms are not used and a date is placed into a VARCHAR2 column.
"Troubleshooting Oracle Performance", likely around page 130-140 also indicates that histograms only use the first 6 bytes.
See section "Followup November 12, 2005 - 4pm US/Eastern"
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:707586567563
An interesting test setup that almost shows what I intended - but Oracle 10.2.0.2 was a little smarter than I expected, even though it selected to use an index to retrieve more than 50% of a table... Take a look at the TO_CHAR representation of the ENDPOINT_VALUE from DBA_TAB_HISTOGRAMS to understand what I was trying to decribe in my original post in this thread.
CREATE TABLE T1 (DATE_ VARCHAR2(10));
INSERT INTO T1
SELECT
TO_CHAR(TO_DATE('2008-01-01','YYYY-MM-DD')+ROWNUM-1,'YYYY-MM-DD')
FROM
DUAL
CONNECT BY
LEVEL<=250;
250 rows created.
COMMIT;
CREATE INDEX IND_T1 ON T1(DATE_);
SELECT
MIN(DATE_),
MAX(DATE_)
FROM
T1;
MIN(DATE_) MAX(DATE_)
2008-01-01 2008-09-06
SELECT
COLUMN_NAME,
NUM_DISTINCT,
NUM_BUCKETS,
HISTOGRAM
FROM
DBA_TAB_COL_STATISTICS
WHERE
OWNER=USER
AND TABLE_NAME='T1';
no rows selected
SELECT
SUBSTR(COLUMN_NAME,1,10) COLUMN_NAME,
ENDPOINT_NUMBER,
ENDPOINT_VALUE,
SUBSTR(ENDPOINT_ACTUAL_VALUE,1,10) ENDPOINT_ACTUAL_VALUE
FROM
DBA_TAB_HISTOGRAMS
WHERE
OWNER=USER
AND TABLE_NAME='T1';
no rows selected
EXEC DBMS_STATS.GATHER_TABLE_STATS(OWNNAME=>USER,TABNAME=>'T1',METHOD_OPT=>'FOR COLUMNS SIZE 254 DATE_',CASCADE=>TRUE);
PL/SQL procedure successfully completed.
SELECT
COLUMN_NAME,
NUM_DISTINCT,
NUM_BUCKETS,
HISTOGRAM
FROM
DBA_TAB_COL_STATISTICS
WHERE
OWNER=USER
AND TABLE_NAME='T1';
COLUMN_NAME NUM_DISTINCT NUM_BUCKETS HISTOGRAM
DATE_ 250 250 HEIGHT BALANCED
SELECT
SUBSTR(COLUMN_NAME,1,10) COLUMN_NAME,
ENDPOINT_NUMBER,
ENDPOINT_VALUE,
SUBSTR(ENDPOINT_ACTUAL_VALUE,1,10) ENDPOINT_ACTUAL_VALUE
FROM
DBA_TAB_HISTOGRAMS
WHERE
OWNER=USER
AND TABLE_NAME='T1'
ORDER BY
ENDPOINT_NUMBER;
COLUMN_NAM ENDPOINT_NUMBER ENDPOINT_VALUE ENDPOINT_A
DATE_ 1 2.6059E+35 2008-01-01
DATE_ 2 2.6059E+35 2008-01-02
DATE_ 3 2.6059E+35 2008-01-03
DATE_ 4 2.6059E+35 2008-01-04
DATE_ 5 2.6059E+35 2008-01-05
DATE_ 6 2.6059E+35 2008-01-06
DATE_ 7 2.6059E+35 2008-01-07
DATE_ 8 2.6059E+35 2008-01-08
DATE_ 9 2.6059E+35 2008-01-09
DATE_ 10 2.6059E+35 2008-01-10
DATE_ 243 2.6059E+35 2008-08-30
DATE_ 244 2.6059E+35 2008-08-31
DATE_ 245 2.6059E+35 2008-09-01
DATE_ 246 2.6059E+35 2008-09-02
DATE_ 247 2.6059E+35 2008-09-03
DATE_ 248 2.6059E+35 2008-09-04
DATE_ 249 2.6059E+35 2008-09-05
DATE_ 250 2.6059E+35 2008-09-06
ALTER SESSION SET EVENTS '10053 TRACE NAME CONTEXT FOREVER, LEVEL 1';
SELECT
DATE_
FROM
T1
WHERE
DATE_<='2008-01-15';
15 rows selected.
From the 10053 trace:
BASE STATISTICAL INFORMATION
Table Stats::
Table: T1 Alias: T1
#Rows: 250 #Blks: 5 AvgRowLen: 11.00
Index Stats::
Index: IND_T1 Col#: 1
LVLS: 0 #LB: 1 #DK: 250 LB/K: 1.00 DB/K: 1.00 CLUF: 1.00
SINGLE TABLE ACCESS PATH
Column (#1): DATE_(VARCHAR2)
AvgLen: 11.00 NDV: 250 Nulls: 0 Density: 0.002
Histogram: HtBal #Bkts: 250 UncompBkts: 250 EndPtVals: 250
Table: T1 Alias: T1
Card: Original: 250 Rounded: 15 Computed: 15.00 Non Adjusted: 15.00
Access Path: TableScan
Cost: 3.01 Resp: 3.01 Degree: 0
Cost_io: 3.00 Cost_cpu: 85607
Resp_io: 3.00 Resp_cpu: 85607
Access Path: index (index (FFS))
Index: IND_T1
resc_io: 2.00 resc_cpu: 49621
ix_sel: 0.0000e+000 ix_sel_with_filters: 1
Access Path: index (FFS)
Cost: 2.00 Resp: 2.00 Degree: 1
Cost_io: 2.00 Cost_cpu: 49621
Resp_io: 2.00 Resp_cpu: 49621
Access Path: index (IndexOnly)
Index: IND_T1
resc_io: 1.00 resc_cpu: 10121
ix_sel: 0.06 ix_sel_with_filters: 0.06
Cost: 1.00 Resp: 1.00 Degree: 1
Best:: AccessPath: IndexRange Index: IND_T1
Cost: 1.00 Degree: 1 Resp: 1.00 Card: 15.00 Bytes: 0
============
Plan Table
============
| Id | Operation | Name | Rows | Bytes | Cost | Time |
| 0 | SELECT STATEMENT | | | | 1 | |
| 1 | INDEX RANGE SCAN | IND_T1 | 15 | 165 | 1 | 00:00:01 |
Predicate Information:
1 - access("DATE_"<='2008-01-15')
INSERT INTO T1
SELECT
TO_CHAR(TO_DATE('2008-09-07','YYYY-MM-DD')+ROWNUM-1,'YYYY-MM-DD')
FROM
DUAL
CONNECT BY
LEVEL<=250;
COMMIT;
EXEC DBMS_STATS.GATHER_TABLE_STATS(OWNNAME=>USER,TABNAME=>'T1',METHOD_OPT=>'FOR COLUMNS SIZE 254 DATE_',CASCADE=>TRUE);
PL/SQL procedure successfully completed.
SELECT
COLUMN_NAME,
NUM_DISTINCT,
NUM_BUCKETS,
HISTOGRAM
FROM
DBA_TAB_COL_STATISTICS
WHERE
OWNER=USER
AND TABLE_NAME='T1';
COLUMN_NAME NUM_DISTINCT NUM_BUCKETS HISTOGRAM
DATE_ 500 254 HEIGHT BALANCED
SELECT
SUBSTR(COLUMN_NAME,1,10) COLUMN_NAME,
ENDPOINT_NUMBER,
TO_CHAR(ENDPOINT_VALUE) ENDPOINT_VALUE,
SUBSTR(ENDPOINT_ACTUAL_VALUE,1,10) ENDPOINT_ACTUAL_VALUE
FROM
DBA_TAB_HISTOGRAMS
WHERE
OWNER=USER
AND TABLE_NAME='T1'
ORDER BY
ENDPOINT_NUMBER;
COLUMN_NAM ENDPOINT_NUMBER ENDPOINT_VALUE ENDPOINT_A
DATE_ 0 260592218925307000000000000000000000 2008-01-01
DATE_ 1 260592218925307000000000000000000000 2008-01-02
DATE_ 2 260592218925307000000000000000000000 2008-01-04
DATE_ 3 260592218925307000000000000000000000 2008-01-06
DATE_ 4 260592218925307000000000000000000000 2008-01-08
DATE_ 5 260592218925307000000000000000000000 2008-01-10
DATE_ 6 260592218925307000000000000000000000 2008-01-12
DATE_ 7 260592218925307000000000000000000000 2008-01-14
DATE_ 8 260592218925307000000000000000000000 2008-01-16
DATE_ 9 260592218925307000000000000000000000 2008-01-18
DATE_ 10 260592218925307000000000000000000000 2008-01-20
DATE_ 242 260592219234792000000000000000000000 2009-04-26
DATE_ 243 260592219234792000000000000000000000 2009-04-28
DATE_ 244 260592219234792000000000000000000000 2009-04-29
DATE_ 245 260592219234792000000000000000000000 2009-05-01
DATE_ 246 260592219234792000000000000000000000 2009-05-02
DATE_ 247 260592219234792000000000000000000000 2009-05-04
DATE_ 248 260592219234792000000000000000000000 2009-05-05
DATE_ 249 260592219234792000000000000000000000 2009-05-07
DATE_ 250 260592219234792000000000000000000000 2009-05-08
DATE_ 251 260592219234792000000000000000000000 2009-05-10
DATE_ 252 260592219234792000000000000000000000 2009-05-11
DATE_ 253 260592219234792000000000000000000000 2009-05-13
DATE_ 254 260592219234792000000000000000000000 2009-05-14
SELECT
DATE_
FROM
T1
WHERE
DATE_ BETWEEN '2008-01-15' AND '2008-09-15';
245 rows selected.
From the 10053 trace:
BASE STATISTICAL INFORMATION
Table Stats::
Table: T1 Alias: T1
#Rows: 500 #Blks: 5 AvgRowLen: 11.00
Index Stats::
Index: IND_T1 Col#: 1
LVLS: 1 #LB: 2 #DK: 500 LB/K: 1.00 DB/K: 1.00 CLUF: 2.00
SINGLE TABLE ACCESS PATH
Column (#1): DATE_(VARCHAR2)
AvgLen: 11.00 NDV: 500 Nulls: 0 Density: 0.002
Histogram: HtBal #Bkts: 254 UncompBkts: 254 EndPtVals: 255
Table: T1 Alias: T1
Card: Original: 500 Rounded: 240 Computed: 240.16 Non Adjusted: 240.16
Access Path: TableScan
Cost: 3.01 Resp: 3.01 Degree: 0
Cost_io: 3.00 Cost_cpu: 148353
Resp_io: 3.00 Resp_cpu: 148353
Access Path: index (index (FFS))
Index: IND_T1
resc_io: 2.00 resc_cpu: 111989
ix_sel: 0.0000e+000 ix_sel_with_filters: 1
Access Path: index (FFS)
Cost: 2.01 Resp: 2.01 Degree: 1
Cost_io: 2.00 Cost_cpu: 111989
Resp_io: 2.00 Resp_cpu: 111989
Access Path: index (IndexOnly)
Index: IND_T1
resc_io: 2.00 resc_cpu: 62443
ix_sel: 0.48031 ix_sel_with_filters: 0.48031
Cost: 2.00 Resp: 2.00 Degree: 1
Best:: AccessPath: IndexRange Index: IND_T1
Cost: 2.00 Degree: 1 Resp: 2.00 Card: 240.16 Bytes: 0
============
Plan Table
============
| Id | Operation | Name | Rows | Bytes | Cost | Time |
| 0 | SELECT STATEMENT | | | | 2 | |
| 1 | INDEX RANGE SCAN | IND_T1 | 240 | 2640 | 2 | 00:00:01 |
Predicate Information:
1 - access("DATE_">='2008-01-15' AND "DATE_"<='2008-09-15')I am sure that there are much better examples than the above, as the above generates a very small data set, and is still an incomplete test setup.
Charles Hooper
IT Manager/Oracle DBA
K&M Machine-Fabricating, Inc. -
Same table in 3 pages without some lines
hi everybody!
i have a form with a master page (containing the invoice fields) and 3 body pages that reference the master page.
in each one of these 3 pages there is a table with one header row, 7 body rows and a footer row.
the table was copied and pasted from page 1 to page 2 and page 3.
between the body rows there are two that are bound with table data, one for invoice details and one for tax details.
my problem is that in the 2nd and 3rd page in pdf output invoice and tax details are empty, while the other lines are present.
my question is: how can i get the same complete table in three form pages?
thanks in advance
ps: here is my form http://www.scribd.com/doc/25198885/esempio-fattura-dati-inventatiNot sure I follow .....are you asking for Page 2 and 3 to have the same table and values in the table as on Page1 or does each page have unique data?
Where is the data coming from? Is the user typing it in or is there a separate data source somewhere?
Paul
Maybe you are looking for
-
Help ! How do I get a sheet of wallet size of the same picture to print
Hi, I have tried everything to get wallet size pictures to print. Can anyone please tell me how to get a sheet of the same picture in wallet size? I'm looking for a whole sheet of the same picture that I can cut and give away. I have iPhoto 09. I can
-
ipad with this new laptop (Winows 8), but can't see the ipad under devices
-
UCM 10gR3 - handling metadata on check-in action
Hi, I've started on UCM and I've been playing with Java custom components to alter the behavior of some services...I used for guidance the book: "The Definitive Guide to Stellent Content Server Development". I want to alter some metadatas of a docume
-
Where are my Audio/MIDI Setup custom icons hiding?
I was attempting to add a custom icon to my Audio/MIDI Setup collection when I realized they're nowhere to be found. My custom icons are currently being used, so they are somewhere. I can readily locate "/Library/Audio/MIDI Devices/Generic/Images/" b
-
Panasonic SDR-H21 HDD device --- error in setup
hi there - please help ---- I just bought Final Cut Express 4 - I use a Panasonic SDR-H21 HDD& SD Card in my Final Cut setup I choose all-formats or DV/Panasonic DVCPRO ---- I choose PAL (we use PAL) as soon as I switch on my Panasonic it opens IPHOT