Unique index and "$SYS_NC00012".
Hi bolow is creating scritpt index that I created in on the tableCREATE UNIQUE INDEX TESTUK_05
ON TEST (COL1_NO,
COL2_NO,
COL3_DATE,
COL4_NO DESC)
PCTFREE 002
INITRANS 5
STORAGE (
INITIAL 200M
PCTINCREASE 0
)
TABLESPACE USERS;
but when I m running table user_ind_columns he shows me another column name instead of the last column that is "col4_no".select TABLE_NAME,INDEX_NAME,COLUMN_NAME from user_ind_columns where table_name='TEST' order by INDEX_NAME;
TEST TESTUK_05 COL3_DATE
TEST TESTUK_05 COL2_NO
TEST TESTUK_05 COL1_NO
TEST TESTUK_05 SYS_NC00012$
PLEASE TEL ME WHY IT GIVES NAME AS COLUMN "SYS_NC00012$" INSTEAD OF COL4_NO
See notes on "ASC | DESC' at http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_5010.htm#i2062403
'DESC' creates a function-based Index. Oracle creates a column for COL4_NO expression in descending order.
I would advise that you not misc mix ASC and DESC of columns in an index.
Hemant K Collette
Published by: Hemant K grapple on March 9, 2011 16:58
URL edited to CREATE INDEX Syntax
Published by: Hemant K grapple on March 9, 2011 17:09
Tags: Database
Similar Questions
-
What is the difference between primary key and unique indexes with forced not null?
Primary key is = unique index + not null?
The short answer is Yes.
However, even if the primary key, applying both uniquness and not null, there is a notion of "special".
You can only have one primary key in tables, but you can have multiple unique indexes and constraints not null.
See: https://asktom.oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:8743855576462
-
ORA-01502 error in the case of a unique index unusable and dml in bulk
Hi all.
The BP is 11.2.0.3 on a linux machine.
I did a unique index unusable and issued a dml on the table.
Howerver, oracle gave me the error ORA-01502.
In order to avoid the ORA-01502 error, should I drop the unique index and bulk make dml and rebuild the index?
Or is there another solution without recreating the unique index?
Thanks in advance.create table hoho.abcde as select level col1 from dual connect by level <=1000 10:09:55 HOHO@PD1MGD>create unique index hoho.abcde_dx1 on hoho.abcde (col1); Index created. 10:10:23 HOHO@PD1MGD>alter index hoho.abcde_dx1 unusable; Index altered. Elapsed: 00:00:00.03 10:11:27 HOHO@PD1MGD>delete from hoho.abcde where rownum < 11; delete from hoho.abcde where rownum < 11 * ERROR at line 1: ORA-01502: index 'HOHO.ABCDE_DX1' or partition of such index is in unusable state
Best regards.Do I have to accept the unique index maintenance workload(undo generation/redo for undo generation) when doing bulk dml?
I think so.
The amount of data you load compared to existing data in the table?
If say for example, you add 20%, and then to compare the retention of 20% adds data during the major part collect to create all of the index after insertion so
you choose the drop/recreate the unique indexBest regards
Mohamed Houri
www.hourim.WordPress.com -
Duplicate display of unique indexes on diagram - how to remove?
Hey people,
A little new for the Modeler and I have a problem with a table I did where a unique index appears twice on my diagram. I can't understand how to remove it.
Any ideas?
Thanks for the help!
Eric
In fact you need to look at the bitty little next to each icon and you will see that they are different. What you have is a unique index and a unique key constraint. Different objects in the database named but identical by the Data Modeler (which is automatically generated index when you declared the constraint). If you go to the properties of the table and click on the index node you will see. Now, click on the single key node and you will see the same name. Right-click on the table in the diagram and choose the DOF preview. After the create table code, you should see a create index command and create a unique alter constraint table.
Why do you need both - constraint and different index information give the optimizer. You can do without one or the other - maybe. Tom Kyte wrote a note on this subject a while back on AskTom. If you're really curious, go here (I don't remember the details).
-
Unique index constraint Vs Unique
Dear all,
I just want to understand what is the difference between a Unique Index and uniqueness constraint
I can create indexes like that, it duplicates will be blocked
create table abhi_1 ( l_number number ) CREATE UNIQUE INDEX abhi_1_UK ON abhi_1 (l_number);
I can also use below syntax for duplicates blocking (index will be created internally)
create table abhi_1 ( l_number number, constraint abhi_1_UK UNIQUE (L_number) )
Please specify,
Hello
I would use a unique constraint. Allows you to create foreign key constraints referencing the single column.
As you said, when you create a unique constraint, Oracle automatically creates an index for it if necessary. You can explicitly set the attributes of that index (for example, the name and tablespace) If you wish.
-
a unique index or unique constraint on the issue of view Matt
10.2.0.3
I have an OLTP table and a matte view to fast refresh of the table in the warehouse. I have unique indexes on the matte view just as I have on the OLTP table. Of course, it's a bad idea because the updating Oracle on mattress views mechanism does not apply to the dml in the same order that it occurred on the side of OLTP? Should I get rid of all the unique indexes on views mattress in my warehouse and create regular index because of their unique nature will just happen because the side OLTP has a unique index? What will be the impact on the performance of the queries? Here's the alert log...
Journal of owp2 alerts
=======================
ORA-12012: error on auto work 1595
ORA-12008: error path refresh materialized view
ORA-00001: unique constraint (SMS_AR. IU02_ROUTE_REF_MRKR) violated
ORA-06512: at "SYS." DBMS_SNAPSHOT", line 510
ORA-06512: at line 1
ORA-00001: unique constraint (SMS_AR. IU02_ROUTE_REF_MRKR) violated
ORA-00610: internal error Code
ORA-12012: error on auto work 260282
ORA-30439: updating of the ' ORA-30439: updating of the 'SMS_AR MV_ROUTE_REF_MRKR' failed due to the ORA-12008: error in the path of refresh materialized view
ORA-00001: unique constraint (SMS_AR. IU02_ROUTE_REF_MRKR) violated
ORA-06512: at "SYS." DBMS_SNAPSHOT", line 2254
ORA-06512: at "SYS." DBMS_SNAPSHOT", line 2460
ORA-06512: at "SYS." DBMS_SNAPSHOT", line 2429
ORA-06512: at "SMS_AR.PA_PIES_WAREHOUSE", line 44
ORA-06512: at line 2
ORA-20000: index 'SMS_AR '. "' I01_MV_PIES_INV_REFMKR ' or the partition of this index is unusableMark Reichman wrote:
I think that this problem is resolved... Unless someone has something else to add. I have not tried yet... But it seems to be valid. I did a test and a unique constraint can be delayed in fact creates a non-unique index. So I need to remove my unique index on my matte view and create unique constraints can be delayed.Or...
forget the unqiue part and simply change the indexes not unique because the main table has a unique index and guarantees uniqueness for me and the matte view will simply copy whats in the main table.
Mark,
the solution seems reasonable. Just a note: If you use a "reportable" unique constraint Oracle ignores any attempt to perform a direct-path insert of access and still stations conventional insert generating undo and many more again.
As long as you do only a 'rapid' refresh, it should not matter, but in case you deal with refreshs full large MVs, this could make a difference when running not atomic refreshs (who can take advantage of the direct-path inserts / DML etc. at the same time)...
Then you can consider using only non-unique index rather than the constraint may be delayed if performance can matter and given the fact that you should never see duplicates in the MV because of the constraint on the base table.
Furthermore, you can use a non-unique index to apply a not reportable unique/primary key constraint as well, it is supported. You just need to create the index yourself before you set the constraint or using explicit syntax "CREATE INDEX" of the constraint clause.
For more information, I wrote a note on this problem "may be deferred" some time ago:
http://Oracle-Randolf.blogspot.com/2008/07/Deferrable-constraints-and-direct-path.html
Kind regards
RandolfOracle related blog stuff:
http://Oracle-Randolf.blogspot.com/SQLTools ++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676 /.
http://sourceforge.NET/projects/SQLT-pp/ -
HelloI have a unique index associated with no doubt. Unique and not unique indexes are used B tree architecture. But I want to know if I create a non-unique index on a column that contains unique data.
When I query this table using this column, it scans each sheet or times found that value it scan stops and give us the result?
00125 wrote:
In a non-unique index, scans all the leaves... so what's the difference between full table scan and index ull. I went through a few articles they mentioned that a non-unique index to check with rowid. How she treated? I have clear knowledge in it.
Please help me with this.
Thanks in advance
If you go through architecture index B-tree you could easily understand how indexing works. The picture here shows how a look of column datatype NUMBER indexed as / stored internally. You can imagine that your indexed column TST_COLA this will look like in the internal process. In the B-tree indexes, you have 3 main structures 1. 2 root. Branch 3. Leaves and the database retrieves lines by browsing through the root of index-> branch-> leaves. If the photo if we wanted to retrieve the row whose value indexed column = 25. First data goes to the root and finds that plugs is set to 25, then he Stoops to this particular branch of find what block sheet retains the value 25. More far away after finding the leaves block then goes to this block of sheets and research the special value of 25.
If the index is UNIQUE, the database knows that there must be only one value, where it performs INDEX UNIQUE SCAN. If the index is NOT UNIQUE it should check all values in this block of leaves to find who all are 25 - in this case INDEX RANGE SCAN is done - as you must check not only value, but all values in this block of sheets - given that the values are not unique. As you can see it that the sheet block contains the long side of the value of the column ROWID, using this database rowid, then goes to the table to retrieve that particular line.
Full table scan is a method of access where the database just to access the table directly (bypassing index structure) and analyze the ENTIRE table to satisfy the request.
-
Hello
indexes and constraints are in different namespaces, so it should be possible to give them the same name.
In the following case that apparently does not work:
create unique index orders_year_show_uq on orders (year desc, show_orders asc); alter table orders add constraint orders_year_show_uq unique (year, show_order);
When I run these statement, I get a "SQL Error: ORA-00955: name is already used by an existing object". ""
If I clean and I execute the same instructions as above with the only difference on the 2 line, using "asc year" instead of "year desc":
on orders (year asc, show_orders asc);
then it success.
I can't explain it, you have an idea?
Thanks in advance.
Kind regards
Giovanni
First of all, you have show_orders in index and show_order in the constraint. I'll assume that it's a typo. Second, when you create constraint without index enhance the specification Oracle seeks indexes existing on the same set of columns in ascending order. If this index does not exist (and it's your case, since one of your columns to index is in descending order), Oracle tries to create one with the same name as the constraint. That's why you get ORA-00955: name is already used by an existing object. In general, you can specify explicitly the index name to force the Oracle by using the existing index. But it will not help you. If you issue
ALTER table orders add unique constraint (year, show_orders) orders_year_show_uq using index orders_year_show_uq;
You will get the ORA-14196: specified index cannot be used to apply the constraint.
In any case, Oracle does not support using index DESC for PK/UK.
SY.
-
Difference of path between primary key and a Unique Index
Hi all
Is there a specific way the oracle optimizer to treat differently the Primary key and Unique index?
Oracle Version
Sample data test for Index NormalSQL> select * from v$version; BANNER -------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production PL/SQL Release 11.2.0.3.0 - Production CORE 11.2.0.3.0 Production TNS for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production NLSRTL Version 11.2.0.3.0 - Production SQL>
Examples of test when using primary key dataSQL> create table t_test_tab(col1 number, col2 number, col3 varchar2(12)); Table created. SQL> create sequence seq_t_test_tab start with 1 increment by 1 ; Sequence created. SQL> insert into t_test_tab select seq_t_test_tab.nextval, round(dbms_random.value(1,999)) , 'B'||round(dbms_random.value(1,50))||'A' from dual connect by level < 100000; 99999 rows created. SQL> commit; Commit complete. SQL> exec dbms_stats.gather_table_stats(USER_OWNER','T_TEST_TAB',cascade => true); PL/SQL procedure successfully completed. SQL> select col1 from t_test_tab; 99999 rows selected. Execution Plan ---------------------------------------------------------- Plan hash value: 1565504962 -------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 99999 | 488K| 74 (3)| 00:00:01 | | 1 | TABLE ACCESS FULL| T_TEST_TAB | 99999 | 488K| 74 (3)| 00:00:01 | -------------------------------------------------------------------------------- Statistics ---------------------------------------------------------- 1 recursive calls 0 db block gets 6915 consistent gets 259 physical reads 0 redo size 1829388 bytes sent via SQL*Net to client 73850 bytes received via SQL*Net from client 6668 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 99999 rows processed SQL> create index idx_t_test_tab on t_test_tab(col1); Index created. SQL> exec dbms_stats.gather_table_stats('USER_OWNER','T_TEST_TAB',cascade => true); PL/SQL procedure successfully completed. SQL> select col1 from t_test_tab; 99999 rows selected. Execution Plan ---------------------------------------------------------- Plan hash value: 1565504962 -------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 99999 | 488K| 74 (3)| 00:00:01 | | 1 | TABLE ACCESS FULL| T_TEST_TAB | 99999 | 488K| 74 (3)| 00:00:01 | -------------------------------------------------------------------------------- Statistics ---------------------------------------------------------- 1 recursive calls 0 db block gets 6915 consistent gets 0 physical reads 0 redo size 1829388 bytes sent via SQL*Net to client 73850 bytes received via SQL*Net from client 6668 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 99999 rows processed SQL>
If you see here the same even as the statistics were gathered,SQL> create table t_test_tab1(col1 number, col2 number, col3 varchar2(12)); Table created. SQL> create sequence seq_t_test_tab1 start with 1 increment by 1 ; Sequence created. SQL> insert into t_test_tab1 select seq_t_test_tab1.nextval, round(dbms_random.value(1,999)) , 'B'||round(dbms_random.value(1,50))||'A' from dual connect by level < 100000; 99999 rows created. SQL> commit; Commit complete. SQL> exec dbms_stats.gather_table_stats('USER_OWNER','T_TEST_TAB1',cascade => true); PL/SQL procedure successfully completed. SQL> select col1 from t_test_tab1; 99999 rows selected. Execution Plan ---------------------------------------------------------- Plan hash value: 1727568366 --------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | --------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 99999 | 488K| 74 (3)| 00:00:01 | | 1 | TABLE ACCESS FULL| T_TEST_TAB1 | 99999 | 488K| 74 (3)| 00:00:01 | --------------------------------------------------------------------------------- Statistics ---------------------------------------------------------- 1 recursive calls 0 db block gets 6915 consistent gets 0 physical reads 0 redo size 1829388 bytes sent via SQL*Net to client 73850 bytes received via SQL*Net from client 6668 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 99999 rows processed SQL> alter table t_test_tab1 add constraint pk_t_test_tab1 primary key (col1); Table altered. SQL> exec dbms_stats.gather_table_stats('USER_OWNER','T_TEST_TAB1',cascade => true); PL/SQL procedure successfully completed. SQL> select col1 from t_test_tab1; 99999 rows selected. Execution Plan ---------------------------------------------------------- Plan hash value: 2995826579 --------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | --------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 99999 | 488K| 59 (2)| 00:00:01 | | 1 | INDEX FAST FULL SCAN| PK_T_TEST_TAB1 | 99999 | 488K| 59 (2)| 00:00:01 | --------------------------------------------------------------------------------------- Statistics ---------------------------------------------------------- 1 recursive calls 0 db block gets 6867 consistent gets 0 physical reads 0 redo size 1829388 bytes sent via SQL*Net to client 73850 bytes received via SQL*Net from client 6668 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 99999 rows processed SQL>
* In the 1st table T_TEST_TAB, table always use FULL table access after creating indexes.
* And in the 2nd table T_TEST_TAB1, table uses PRIMARY KEY as expected.
Any comments?
Kind regards
BPat>
* In the 1st table T_TEST_TAB, table always use FULL table access after creating indexes.
* And in the 2nd table T_TEST_TAB1, table uses PRIMARY KEY as expected.
>
Yes - for the first table a full table scan will be used as the currently selected column is nullable and indexes do not include null values.The index can be used for the second query, since all the data (first column) is available between the index and there may be no NULL values because of the primary key. If you check constraints, you find that the there is now a CHECK constraint to ensure that the first column cannot be null.
For a full and interesting discussion see the explanation of this and a related issue on the question I ask in this thread
What SYS tables (not seen) contain the value NULL spec /not/ column definition? and my response he posted: 23 April 2012 09:02I ask the question is based on a question here which is similar to yours
Columns becoming nullable after a fall of primary key? -
Name of the PK, unique constraints and to support the index
I want to have my primary key constraint and index support share of the same name, IE:
Without definition explicit a unique index using the relational model, the generated DDL added 'X' for the name of the index:CREATE UNIQUE INDEX MYTABLE_PK ON MYTABLE(...); ALTER TABLE MYTABLE ADD CONSTRAINT MYTABLE_PK PRIMARY KEY(...);
I tried to add an index unique explicit to the table, but he changed the name (adds "v1") when I leave the table editor:CREATE UNIQUE INDEX MYTABLE_PKX ON MYTABLE(...); ALTER TABLE MYTABLE ADD CONSTRAINT MYTABLE_PK PRIMARY KEY(...);
I have the same problem with index & unique constraints.CREATE UNIQUE INDEX MYTABLE_PKv1 ON MYTABLE(...); ALTER TABLE MYTABLE ADD CONSTRAINT MYTABLE_PK PRIMARY KEY(...);
Issues related to the:
Can I generate DDL with name matching? "v1" thing seems unlikely, he doesn't want not myself save the definition as I want.
Where are the transformations of naming for this location? I found tools, preferences, and Data Modeling/naming Standards/Templates but this nugget does nto seem to be there.
Thank you.Hi Mike,.
The Production data release model 3.1 has been updated to allow constraints unique and primary and their indexes share the same name.
David
-
Creating a unique index frame on a one-to-many table and search
Hello
I was properly put in place of the full text index on multiple columns on the same table (using the MULTI_COLUMN_DATASTORE preferences), but now I have a situation with a table of one-to-many data collection (with a CF of a lookup table), and I need to get columns through two of these tables. Code example below, several of my chatter after the code block:
I want to be able to create a text index to group these fields:CREATE TABLE SUBMISSION ( SUBMISSION_ID NUMBER(10) NOT NULL, SUBMISSION_NAME VARCHAR2(100) NOT NULL ); CREATE TABLE ADVISOR_TYPE ( ADVISOR_TYPE_ID NUMBER(10) NOT NULL, ADVISOR_TYPE_NAME VARCHAR2(50) NOT NULL ); CREATE TABLE SUBMISSION_ADVISORS ( SUBMISSION_ADVISORS_ID NUMBER(10) NOT NULL, SUBMISSION_ID NUMBER(10) NOT NULL, ADVISOR_TYPE_ID NUMBER(10) NOT NULL, FIRST_NAME VARCHAR(50) NULL, LAST_NAME VARCHAR(50) NULL, SUFFIX VARCHAR(20) NULL ); INSERT INTO SUBMISSION (SUBMISSION_ID, SUBMISSION_NAME) VALUES (1, 'Some Research Paper'); INSERT INTO SUBMISSION (SUBMISSION_ID, SUBMISSION_NAME) VALUES (2, 'Thesis on 17th Century Weather Patterns'); INSERT INTO SUBMISSION (SUBMISSION_ID, SUBMISSION_NAME) VALUES (3, 'Statistical Analysis on Sunny Days in March'); INSERT INTO ADVISOR_TYPE (ADVISOR_TYPE_ID, ADVISOR_TYPE_NAME) VALUES (1, 'Department Chair'); INSERT INTO ADVISOR_TYPE (ADVISOR_TYPE_ID, ADVISOR_TYPE_NAME) VALUES (2, 'Department Co-Chair'); INSERT INTO ADVISOR_TYPE (ADVISOR_TYPE_ID, ADVISOR_TYPE_NAME) VALUES (3, 'Professor'); INSERT INTO ADVISOR_TYPE (ADVISOR_TYPE_ID, ADVISOR_TYPE_NAME) VALUES (4, 'Associate Professor'); INSERT INTO ADVISOR_TYPE (ADVISOR_TYPE_ID, ADVISOR_TYPE_NAME) VALUES (5, 'Scientist'); INSERT INTO SUBMISSION_ADVISORS (SUBMISSION_ADVISORS_ID, SUBMISSION_ID, ADVISOR_TYPE_ID, FIRST_NAME, LAST_NAME, SUFFIX) VALUES (1,1,2,'John', 'Doe', 'PhD'); INSERT INTO SUBMISSION_ADVISORS (SUBMISSION_ADVISORS_ID, SUBMISSION_ID, ADVISOR_TYPE_ID, FIRST_NAME, LAST_NAME, SUFFIX) VALUES (2,1,2,'Jane', 'Doe', 'PhD'); INSERT INTO SUBMISSION_ADVISORS (SUBMISSION_ADVISORS_ID, SUBMISSION_ID, ADVISOR_TYPE_ID, FIRST_NAME, LAST_NAME, SUFFIX) VALUES (3,2,3,'Johan', 'Smith', NULL); INSERT INTO SUBMISSION_ADVISORS (SUBMISSION_ADVISORS_ID, SUBMISSION_ID, ADVISOR_TYPE_ID, FIRST_NAME, LAST_NAME, SUFFIX) VALUES (4,2,4,'Magnus', 'Jackson', 'MS'); INSERT INTO SUBMISSION_ADVISORS (SUBMISSION_ADVISORS_ID, SUBMISSION_ID, ADVISOR_TYPE_ID, FIRST_NAME, LAST_NAME, SUFFIX) VALUES (5,3,5,'Williard', 'Forsberg', 'AMS'); COMMIT;
SUBMISSION_ADVISORS. FIRST NAME
SUBMISSION_ADVISORS. LAST_NAME
SUBMISSION_ADVISORS. SUFFIX
ADVISOR_TYPE. ADVISOR_TYPE_NAME
I looked at DETAIL_DATASTORE and USER_DATASTORE, but examples of Oracle Docs for DETAIL_DATASTORE leave me a little confused. It seems that this should be fairly simple.
Ideally, I try to avoid creating new columns and keeping a minimum shutter adjustments. But I'm open to any suggestion. Thanks for your time and your thoughts.
-JamieI would create a procedure that creates a virtual with labels document, what is the multi_column_datatstore behind the scenes. Then I would like to use this procedure in a user_datastore, so the result is the same for several tables as a multi_column_datastore for a table. I would use auto_section_group or another type of Group of sections, so that you can search from WITHIN as with the multi_column_datastore. Please see the demo below.
SCOTT@orcl_11gR2> -- tables and data that you provided: SCOTT@orcl_11gR2> CREATE TABLE SUBMISSION 2 ( SUBMISSION_ID NUMBER(10) NOT NULL, 3 SUBMISSION_NAME VARCHAR2(100) NOT NULL 4 ) 5 / Table created. SCOTT@orcl_11gR2> CREATE TABLE ADVISOR_TYPE 2 ( ADVISOR_TYPE_ID NUMBER(10) NOT NULL, 3 ADVISOR_TYPE_NAME VARCHAR2(50) NOT NULL 4 ) 5 / Table created. SCOTT@orcl_11gR2> CREATE TABLE SUBMISSION_ADVISORS 2 ( SUBMISSION_ADVISORS_ID NUMBER(10) NOT NULL, 3 SUBMISSION_ID NUMBER(10) NOT NULL, 4 ADVISOR_TYPE_ID NUMBER(10) NOT NULL, 5 FIRST_NAME VARCHAR(50) NULL, 6 LAST_NAME VARCHAR(50) NULL, 7 SUFFIX VARCHAR(20) NULL 8 ) 9 / Table created. SCOTT@orcl_11gR2> INSERT ALL 2 INTO SUBMISSION (SUBMISSION_ID, SUBMISSION_NAME) 3 VALUES (1, 'Some Research Paper') 4 INTO SUBMISSION (SUBMISSION_ID, SUBMISSION_NAME) 5 VALUES (2, 'Thesis on 17th Century Weather Patterns') 6 INTO SUBMISSION (SUBMISSION_ID, SUBMISSION_NAME) 7 VALUES (3, 'Statistical Analysis on Sunny Days in March') 8 SELECT * FROM DUAL 9 / 3 rows created. SCOTT@orcl_11gR2> INSERT ALL 2 INTO ADVISOR_TYPE (ADVISOR_TYPE_ID, ADVISOR_TYPE_NAME) 3 VALUES (1, 'Department Chair') 4 INTO ADVISOR_TYPE (ADVISOR_TYPE_ID, ADVISOR_TYPE_NAME) 5 VALUES (2, 'Department Co-Chair') 6 INTO ADVISOR_TYPE (ADVISOR_TYPE_ID, ADVISOR_TYPE_NAME) 7 VALUES (3, 'Professor') 8 INTO ADVISOR_TYPE (ADVISOR_TYPE_ID, ADVISOR_TYPE_NAME) 9 VALUES (4, 'Associate Professor') 10 INTO ADVISOR_TYPE (ADVISOR_TYPE_ID, ADVISOR_TYPE_NAME) 11 VALUES (5, 'Scientist') 12 SELECT * FROM DUAL 13 / 5 rows created. SCOTT@orcl_11gR2> INSERT ALL 2 INTO SUBMISSION_ADVISORS (SUBMISSION_ADVISORS_ID, SUBMISSION_ID, ADVISOR_TYPE_ID, FIRST_NAME, LAST_NAME, SUFFIX) 3 VALUES (1,1,2,'John', 'Doe', 'PhD') 4 INTO SUBMISSION_ADVISORS (SUBMISSION_ADVISORS_ID, SUBMISSION_ID, ADVISOR_TYPE_ID, FIRST_NAME, LAST_NAME, SUFFIX) 5 VALUES (2,1,2,'Jane', 'Doe', 'PhD') 6 INTO SUBMISSION_ADVISORS (SUBMISSION_ADVISORS_ID, SUBMISSION_ID, ADVISOR_TYPE_ID, FIRST_NAME, LAST_NAME, SUFFIX) 7 VALUES (3,2,3,'Johan', 'Smith', NULL) 8 INTO SUBMISSION_ADVISORS (SUBMISSION_ADVISORS_ID, SUBMISSION_ID, ADVISOR_TYPE_ID, FIRST_NAME, LAST_NAME, SUFFIX) 9 VALUES (4,2,4,'Magnus', 'Jackson', 'MS') 10 INTO SUBMISSION_ADVISORS (SUBMISSION_ADVISORS_ID, SUBMISSION_ID, ADVISOR_TYPE_ID, FIRST_NAME, LAST_NAME, SUFFIX) 11 VALUES (5,3,5,'Williard', 'Forsberg', 'AMS') 12 SELECT * FROM DUAL 13 / 5 rows created. SCOTT@orcl_11gR2> -- constraints presumed based on your description: SCOTT@orcl_11gR2> ALTER TABLE submission ADD CONSTRAINT submission_id_pk 2 PRIMARY KEY (submission_id) 3 / Table altered. SCOTT@orcl_11gR2> ALTER TABLE advisor_type ADD CONSTRAINT advisor_type_id_pk 2 PRIMARY KEY (advisor_type_id) 3 / Table altered. SCOTT@orcl_11gR2> ALTER TABLE submission_advisors ADD CONSTRAINT submission_advisors_id_pk 2 PRIMARY KEY (submission_advisors_id) 3 / Table altered. SCOTT@orcl_11gR2> ALTER TABLE submission_advisors ADD CONSTRAINT submission_id_fk 2 FOREIGN KEY (submission_id) REFERENCES submission (submission_id) 3 / Table altered. SCOTT@orcl_11gR2> ALTER TABLE submission_advisors ADD CONSTRAINT advisor_type_id_fk 2 FOREIGN KEY (advisor_type_id) REFERENCES advisor_type (advisor_type_id) 3 / Table altered. SCOTT@orcl_11gR2> -- resulting data: SCOTT@orcl_11gR2> COLUMN submission_name FORMAT A45 SCOTT@orcl_11gR2> COLUMN advisor FORMAT A40 SCOTT@orcl_11gR2> SELECT s.submission_name, 2 a.advisor_type_name || ' ' || 3 sa.first_name || ' ' || 4 sa.last_name || ' ' || 5 sa.suffix AS advisor 6 FROM submission_advisors sa, 7 submission s, 8 advisor_type a 9 WHERE sa.advisor_type_id = a.advisor_type_id 10 AND sa.submission_id = s.submission_id 11 / SUBMISSION_NAME ADVISOR --------------------------------------------- ---------------------------------------- Some Research Paper Department Co-Chair John Doe PhD Some Research Paper Department Co-Chair Jane Doe PhD Thesis on 17th Century Weather Patterns Professor Johan Smith Thesis on 17th Century Weather Patterns Associate Professor Magnus Jackson MS Statistical Analysis on Sunny Days in March Scientist Williard Forsberg AMS 5 rows selected. SCOTT@orcl_11gR2> -- procedure to create virtual documents: SCOTT@orcl_11gR2> CREATE OR REPLACE PROCEDURE submission_advisors_proc 2 (p_rowid IN ROWID, 3 p_clob IN OUT NOCOPY CLOB) 4 AS 5 BEGIN 6 FOR r1 IN 7 (SELECT * 8 FROM submission_advisors 9 WHERE ROWID = p_rowid) 10 LOOP 11 IF r1.first_name IS NOT NULL THEN 12 DBMS_LOB.WRITEAPPEND (p_clob, 12, '
'); 13 DBMS_LOB.WRITEAPPEND (p_clob, LENGTH (r1.first_name), r1.first_name); 14 DBMS_LOB.WRITEAPPEND (p_clob, 13, ' '); 15 END IF; 16 IF r1.last_name IS NOT NULL THEN 17 DBMS_LOB.WRITEAPPEND (p_clob, 11, ''); 18 DBMS_LOB.WRITEAPPEND (p_clob, LENGTH (r1.last_name), r1.last_name); 19 DBMS_LOB.WRITEAPPEND (p_clob, 12, ' '); 20 END IF; 21 IF r1.suffix IS NOT NULL THEN 22 DBMS_LOB.WRITEAPPEND (p_clob, 8, ''); 23 DBMS_LOB.WRITEAPPEND (p_clob, LENGTH (r1.suffix), r1.suffix); 24 DBMS_LOB.WRITEAPPEND (p_clob, 9, ' '); 25 END IF; 26 FOR r2 IN 27 (SELECT * 28 FROM submission 29 WHERE submission_id = r1.submission_id) 30 LOOP 31 DBMS_LOB.WRITEAPPEND (p_clob, 17, ''); 32 DBMS_LOB.WRITEAPPEND (p_clob, LENGTH (r2.submission_name), r2.submission_name); 33 DBMS_LOB.WRITEAPPEND (p_clob, 18, ' '); 34 END LOOP; 35 FOR r3 IN 36 (SELECT * 37 FROM advisor_type 38 WHERE advisor_type_id = r1.advisor_type_id) 39 LOOP 40 DBMS_LOB.WRITEAPPEND (p_clob, 19, ''); 41 DBMS_LOB.WRITEAPPEND (p_clob, LENGTH (r3.advisor_type_name), r3.advisor_type_name); 42 DBMS_LOB.WRITEAPPEND (p_clob, 20, ' '); 43 END LOOP; 44 END LOOP; 45 END submission_advisors_proc; 46 / Procedure created. SCOTT@orcl_11gR2> SHOW ERRORS No errors. SCOTT@orcl_11gR2> -- examples of virtual documents that procedure creates: SCOTT@orcl_11gR2> DECLARE 2 v_clob CLOB := EMPTY_CLOB(); 3 BEGIN 4 FOR r IN 5 (SELECT ROWID rid FROM submission_advisors) 6 LOOP 7 DBMS_LOB.CREATETEMPORARY (v_clob, TRUE); 8 submission_advisors_proc (r.rid, v_clob); 9 DBMS_OUTPUT.PUT_LINE (v_clob); 10 DBMS_LOB.FREETEMPORARY (v_clob); 11 END LOOP; 12 END; 13 /John Doe PhD Some Research Paper Department Co-Chair Jane Doe PhD Some Research Paper Department Co-Chair Johan Smith Thesis on 17th Century Weather Patterns Professor Magnus Jackson MS The sis on 17th Century Weather Patterns Associate Professor Williard Forsberg AMS Statistical Analysis on Sunny Days in
March
Scientist PL/SQL procedure successfully completed. SCOTT@orcl_11gR2> -- user_datastore that uses procedure: SCOTT@orcl_11gR2> BEGIN 2 CTX_DDL.CREATE_PREFERENCE ('sa_datastore', 'USER_DATASTORE'); 3 CTX_DDL.SET_ATTRIBUTE ('sa_datastore', 'PROCEDURE', 'submission_advisors_proc'); 4 END; 5 / PL/SQL procedure successfully completed. SCOTT@orcl_11gR2> -- index (on optional extra column) that uses user_datastore and section group: SCOTT@orcl_11gR2> ALTER TABLE submission_advisors ADD (any_column VARCHAR2(1)) 2 / Table altered. SCOTT@orcl_11gR2> CREATE INDEX submission_advisors_idx 2 ON submission_advisors (any_column) 3 INDEXTYPE IS CTXSYS.CONTEXT 4 PARAMETERS 5 ('DATASTORE sa_datastore 6 SECTION GROUP CTXSYS.AUTO_SECTION_GROUP') 7 / Index created. SCOTT@orcl_11gR2> -- what is tokenized, indexed, and searchable: SCOTT@orcl_11gR2> SELECT token_text FROM dr$submission_advisors_idx$i 2 / TOKEN_TEXT ---------------------------------------------------------------- 17TH ADVISOR_TYPE_NAME AMS ANALYSIS ASSOCIATE CENTURY CHAIR CO DAYS DEPARTMENT DOE FIRST_NAME FORSBERG JACKSON JANE JOHAN JOHN LAST_NAME MAGNUS MARCH PAPER PATTERNS PHD PROFESSOR RESEARCH SCIENTIST SMITH STATISTICAL SUBMISSION_NAME SUFFIX SUNNY THESIS WEATHER WILLIARD 34 rows selected. SCOTT@orcl_11gR2> -- sample searches across all data: SCOTT@orcl_11gR2> VARIABLE search_string VARCHAR2(100) SCOTT@orcl_11gR2> EXEC :search_string := 'professor' PL/SQL procedure successfully completed. SCOTT@orcl_11gR2> SELECT s.submission_name, 2 a.advisor_type_name || ' ' || 3 sa.first_name || ' ' || 4 sa.last_name || ' ' || 5 sa.suffix AS advisor 6 FROM submission_advisors sa, 7 submission s, 8 advisor_type a 9 WHERE CONTAINS (sa.any_column, :search_string) > 0 10 AND sa.advisor_type_id = a.advisor_type_id 11 AND sa.submission_id = s.submission_id 12 / SUBMISSION_NAME ADVISOR --------------------------------------------- ---------------------------------------- Thesis on 17th Century Weather Patterns Professor Johan Smith Thesis on 17th Century Weather Patterns Associate Professor Magnus Jackson MS 2 rows selected. SCOTT@orcl_11gR2> EXEC :search_string := 'doe' PL/SQL procedure successfully completed. SCOTT@orcl_11gR2> / SUBMISSION_NAME ADVISOR --------------------------------------------- ---------------------------------------- Some Research Paper Department Co-Chair John Doe PhD Some Research Paper Department Co-Chair Jane Doe PhD 2 rows selected. SCOTT@orcl_11gR2> EXEC :search_string := 'paper' PL/SQL procedure successfully completed. SCOTT@orcl_11gR2> / SUBMISSION_NAME ADVISOR --------------------------------------------- ---------------------------------------- Some Research Paper Department Co-Chair John Doe PhD Some Research Paper Department Co-Chair Jane Doe PhD 2 rows selected. SCOTT@orcl_11gR2> -- sample searches within specific columns: SCOTT@orcl_11gR2> EXEC :search_string := 'chair' PL/SQL procedure successfully completed. SCOTT@orcl_11gR2> SELECT s.submission_name, 2 a.advisor_type_name || ' ' || 3 sa.first_name || ' ' || 4 sa.last_name || ' ' || 5 sa.suffix AS advisor 6 FROM submission_advisors sa, 7 submission s, 8 advisor_type a 9 WHERE CONTAINS (sa.any_column, :search_string || ' WITHIN advisor_type_name') > 0 10 AND sa.advisor_type_id = a.advisor_type_id 11 AND sa.submission_id = s.submission_id 12 / SUBMISSION_NAME ADVISOR --------------------------------------------- ---------------------------------------- Some Research Paper Department Co-Chair John Doe PhD Some Research Paper Department Co-Chair Jane Doe PhD 2 rows selected. SCOTT@orcl_11gR2> EXEC :search_string := 'phd' PL/SQL procedure successfully completed. SCOTT@orcl_11gR2> SELECT s.submission_name, 2 a.advisor_type_name || ' ' || 3 sa.first_name || ' ' || 4 sa.last_name || ' ' || 5 sa.suffix AS advisor 6 FROM submission_advisors sa, 7 submission s, 8 advisor_type a 9 WHERE CONTAINS (sa.any_column, :search_string || ' WITHIN suffix') > 0 10 AND sa.advisor_type_id = a.advisor_type_id 11 AND sa.submission_id = s.submission_id 12 / SUBMISSION_NAME ADVISOR --------------------------------------------- ---------------------------------------- Some Research Paper Department Co-Chair John Doe PhD Some Research Paper Department Co-Chair Jane Doe PhD 2 rows selected. SCOTT@orcl_11gR2> EXEC :search_string := 'weather' PL/SQL procedure successfully completed. SCOTT@orcl_11gR2> SELECT s.submission_name, 2 a.advisor_type_name || ' ' || 3 sa.first_name || ' ' || 4 sa.last_name || ' ' || 5 sa.suffix AS advisor 6 FROM submission_advisors sa, 7 submission s, 8 advisor_type a 9 WHERE CONTAINS (sa.any_column, :search_string || ' WITHIN submission_name') > 0 10 AND sa.advisor_type_id = a.advisor_type_id 11 AND sa.submission_id = s.submission_id 12 / SUBMISSION_NAME ADVISOR --------------------------------------------- ---------------------------------------- Thesis on 17th Century Weather Patterns Professor Johan Smith Thesis on 17th Century Weather Patterns Associate Professor Magnus Jackson MS 2 rows selected. -
When I change a column is a primary key the associated non-unique index to become unique?
So basically I already tried this and it shows me that the associated index is not unique.
create table employees2 in select * from employees;
create index emp_idx on employees2 (employee_id);
ALTER employees2 table add primary key (employe_id) using index emp_idx;
Select * from user_indexes where index-name = "EMP_IDX";
I was wondering if I right assuming that when you change a column to a primary key or unique while using a given index that does not have the respective index become unique.
The textbooks I use are sometimes a little hard to understand because of the wording, also, I want to just ask someone with a little more experience than me.
Thank you.
your test did give the correct answer: the index is not unique if it serves to bear a unique or primary key constraint. Indeed, it is one of the benefits of the use of no unique indexes in support of UK/PK constraints (since it allows to set the unusable index before to make bulk loads; and, of course, they have also some disadvantages - for example, they need an additional logical reading to reach a line). Richard Foote explains the details in https://richardfoote.wordpress.com/2008/06/04/primary-keys-and-non-unique-indexes-whats-really-happening/ (and other items).
-
Transform a no Unique Index in a single index
Hello
Version: 11.2.0.4.0 Enterprise Edition
We got a non-unique Index for a primary key constraint. I would like to change that in a unique index. I know that you can not change the index to change. Is the only way to disable the primary key, delete the index and re-enable the constraint or is there a better solution? It is a 24/7 platform.
sql_colder
Windows service exist for a reason.
You can also create clues online in an operational database.
There is no other method outside the use of DBMS_REDEFINITION.
Think about it: what is the business case to change the index?
-----------
Sybrand Bakker
Senior Oracle DBA
-
Hello
I use OLIVIER 7.9.6.4
and EBS Instance ORA12.1.3
I get below error when I tried to run full load for the DAC order management
CREATE A UNIQUE INDEX
W_PROD_CAT_DH_U1
WE
W_PROD_CAT_DH
(
INTEGRATION_ID Asc
DATASOURCE_NUM_ID Asc
EFFECTIVE_FROM_DT Asc
)
NOLOGGING
ORA-01452: cannot CREATE a UNIQUE INDEX. duplicate keys found
Among the responsible 1,45,423 records 24 140 are duplicated.
Apart from the removal of duplicates of records in DB is there any changes that I can do in Informatica mapping to limit duplicate records to be loaded into DB.
Any question even face to face only one?
Kind regards
NN.
Hello
For those who have faced the question above.
Here is the Solution.
- Informatica PowerCenter Designer, place you in the SIL_Vert\Mappings folder and open the "SIL_ProductCategoryDimension_Hierarchy" mapping in the mapping Designer tool.
- Change the qualifier Source SQ_W_PRODCAT_DS to display the dialog box change Transformations and switch to the Properties tab.
- Select the name of the attribute processing Sql Query and edit the substitution of sql to change the status of outer join left in w_product_d as:
- DATABASE W_PRODCAT_DS
- LEFT OUTER JOIN W_PRODUCT_D PROD ON
- BASE. PROD_ID = PROD. INTEGRATION_ID AND PROD. CURRENT_FLG = 'Y '.
- Save the details and archive.
The changes described above helped me load management command successfully.
Kind regards
NN.
-
When we use a unique index for PK?
I was reading this part of the manual oracle:
http://docs.Oracle.com/CD/B28359_01/server.111/b28310/indexes003.htm#ADMIN11727
I got confused because I was trying to research why sometimes, we want to create a primary key by using a unique index.
CREATE A UNIQUE MYTABLE_PK ON MYTABLE INDEX
(START_DT, ANNUAL)
LOGGING
TABLESPACE TBS_INDEX01
NOPARALLEL;
ALTER TABLE MYTABLE ADD)
CONSTRAINT MYTABLE_PK
KEY ELEMENTARY SCHOOL
(START_DT, ANNUAL)
WITH THE HELP OF INDEX MYTABLE_PK);
And sometimes we simply create the primary key without using a unique index.
ALTER TABLE MYTABLE ADD)
CONSTRAINT PK_MYTABLE
KEY ELEMENTARY SCHOOL
(START_DT, ANNUAL)
THE HELP INDEX);
When we use a unique index for PK?
James, you have returned to the question thread.
I apologize: I'm sorry, user8875620, your son has been hijacked. A UK or PK constraint needs an index. You can create a (unique or non-unique) explicitly, or you can let Uncle Oracle create it implicitly when you define the constraint.
Maybe you are looking for
-
Re: Smoker L650 screen Dithering (grainy/noisy photo)
Hello I bought a Satellite L650 a month ago and I realized that the screen has a problem of dithering (explanation of dither is after the grey square--> [http://www.lagom.nl/lcd-test/black.php]). This computer has an i5 - 450 M and a Radeon 5650. Any
-
Satellite 2210CDT: hardware upgrade
Hello again! I'll update my Toshiba hadware a little... 1: 196 MB RAM upgrade - I bought SODIM 128 but How to put inside - do I have to unscrew everything laptop? 2: upgrade CD DVD: but can give me these details: How is it fixed and the size and what
-
Hello I have configured option 43 on server dhcp, restarted 1131 AP, but AP still try to resolve the CISCO-LWAPP-CONTROLLER instead of the ip provided by dhcp. How can I debug this? Router config: IP dhcp pool seg20 F104.0a0f.64fd hexagonal option 43
-
Failed to refresh an af:query with dynamic query
Hi guys, I'm on JDev 11.1.1.7.0 and have a usecase where I use a valueChangeListener on a selectOneChoice to dynamically set a pageFlowScope on the search box in the pageDef. The viewcriteria have different criteria and labels for the viewcriteriaite
-
I have a hue/Sat adjustment layer to desaturate the shadow under the display value. I filled the mask and trying to reveal the desaturation brush is not revealing the mask but rather its quality as a brush, and a black line on the image of brushing.