IF I FIRE A QUERY IN SQLPLS
DROP INDEX ord_customer_ix_demo;
This statement drops an index named ord_customer_ix_demo, which was created in "Compressing an Index: Example":
does this drop my table too?
I FIREd A QUERY IN SQLPLS
DROP INDEX ord_customer_ix_demo;
This statement drops an index named ord_customer_ix_demo, which was created in "Compressing an Index: Example":
i want to know does this drop my table too?
No, it won't drop a table.
Sample table:
SQL> create table demo as select level id from dual connect by level <= 5;
Table created.
Index on that table:
SQL> create index ord_ix_demo on demo (id);
Index created.
Table contents:
SQL> select * from demo;
ID
----------
1
2
3
4
5
Drop the index:
SQL> drop index ord_ix_demo;
Index dropped.
Is table still here? Yes:
SQL> select * from demo;
ID
----------
1
2
3
4
5
SQL>
Related
i created a table but i forgot to add a sequence to one of the PK, its a sequence on a form page, i just cant find anything about it, is it possible or do i have to do the form all over again.
i tried to replace the PK but it doesnt give me the option to add the sequence when creating a new one.
i searched everywhere and asked the support in chat (didn't really help since its not their job).
all i could find was this and this.
I'd suggest you to skip Apex in this matter and do the following: presume this is your table:
SQL> create table test
2 (id number constraint pk_test primary key,
3 name varchar2(20)
4 );
Table created.
This is the sequence:
SQL> create sequence myseq;
Sequence created.
As you forgot to specify PK source while creating Apex Form page, never mind - let the database handle it. How? Create a BEFORE INSERT trigger:
SQL> create or replace trigger trg_bi_test
2 before insert on test
3 for each row
4 when (new.id is null)
5 begin
6 :new.id := myseq.nextval;
7 end trg_bi_test;
8 /
Trigger created.
Let's test it: I'm inserting only the NAME (which is what your Apex Form will be doing):
SQL> insert into test (name) values ('Littlefoot');
1 row created.
What is table's contents?
SQL> select * from test;
ID NAME
---------- --------------------
1 Littlefoot
SQL>
See? Trigger automatically inserted ID (primary key) column value.
If it were an Interactive Grid (which lets you insert several records at a time):
SQL> insert into test (name)
2 select 'Bigfoot' from dual union all
3 select 'FAD' from dual;
2 rows created.
SQL> select * from test;
ID NAME
---------- --------------------
1 Littlefoot
2 Bigfoot
3 FAD
SQL>
Works just fine.
And what's another benefit: you don't have to modify Apex application at all.
I am trying to come up with a way to make sure that when a table is updated, that a certain condition is met. Can this be done in a trigger? I have made the following two tables, storeTable and employeeTable.
I need to make sure that when storeManager is updated in the storeTable, that the employee has a storeID that matches the store in which I am trying to update the storeManager. (employee cannot be manager of a store he does not work at)
In addition, I need to make sure that the employee exists in the employeeTable. I was thinking some sort of CASE statement would be best, but dont know how this could be enforced by a trigger.
I was thinking about morphing the "Foreign Key Trigger for Child Table" trigger example from https://docs.oracle.com/cd/B12037_01/appdev.101/b10795/adfns_tr.htm#1007172 but I could not figure out how to change this to fit my specific need. Any help is much appreciated.
For context, the current keys are:
storeTable:
storeID PRIMARY KEY
employeeTable:
empID PRIMARY KEY
storeID FOREIGN KEY REFERS TO storeTable.storeID
To me, it seems that constraints can do the job. You don't need triggers.
Here's how. First, create tables without any constraints. Then add them, both primary and foreign key ones which will be deferrable (otherwise you wouldn't be able to insert any rows as parent keys don't exist yet).
SQL> create table employee
2 (empid number,
3 fname varchar2(10),
4 storeid number
5 );
Table created.
SQL> create table store
2 (storeid number,
3 storename varchar2(20),
4 storemanager number
5 );
Table created.
SQL>
SQL> alter table employee add constraint pk_employee primary key (empid, storeid);
Table altered.
SQL> alter table store add constraint pk_store primary key (storeid);
Table altered.
SQL>
SQL> alter table store add constraint fk_store_emp foreign key (storemanager, storeid)
2 references employee (empid, storeid)
3 deferrable initially deferred;
Table altered.
SQL> alter table employee add constraint fk_emp_store foreign key (storeid)
2 references store (storeid)
3 deferrable initially deferred;
Table altered.
SQL>
Now let's add some data: initial insert into employee will be OK until I commit - then it'll fail because its store doesn't exist yet:
SQL> insert into employee values (1, 'John' , 1);
1 row created.
SQL> commit;
commit
*
ERROR at line 1:
ORA-02091: transaction rolled back
ORA-02291: integrity constraint (SCOTT.FK_EMP_STORE) violated - parent key not
found
SQL>
But, if I don't commit and pay attention to what I'm entering (i.e. that referential integrity is maintained), it'll be OK:
SQL> insert into employee values (1, 'John' , 1);
1 row created.
SQL> insert into employee values (2, 'Matt' , 2);
1 row created.
SQL> insert into store values (1, 'Santa Clara', 1);
1 row created.
SQL> insert into store values (2, 'San Francisco', 2); --> note 2 as STOREID
1 row created.
SQL> commit;
Commit complete.
SQL> select * From employee;
EMPID FNAME STOREID
---------- ---------- ----------
1 John 1
2 Matt 2
SQL> select * From store;
STOREID STORENAME STOREMANAGER
---------- -------------------- ------------
1 Santa Clara 1
2 San Francisco 2
SQL>
See? So far so good.
Now I'll try to modify STORE table and set its manager to John who works in storeid = 1 which means that it should fail:
SQL> update store set storemanager = 1
2 where storeid = 2;
1 row updated.
SQL> commit;
commit
*
ERROR at line 1:
ORA-02091: transaction rolled back
ORA-02291: integrity constraint (SCOTT.FK_STORE_EMP) violated - parent key not
found
SQL>
As expected.
Let's now add emplyoee ID = 6, Jimmy, who works in storeid = 2 and set him to be manager in San Francisco (storeid = 2):
SQL> insert into employee values (6, 'Jimmy', 2);
1 row created.
SQL> update store set storemanager = 6
2 where storeid = 2;
1 row updated.
SQL> commit;
Commit complete.
SQL>
Yey! It works!
As you can see, no triggers needed.
Note that - if you want to drop any of those tables - you'll fail as they are referenced by each other:
SQL> drop table store;
drop table store
*
ERROR at line 1:
ORA-02449: unique/primary keys in table referenced by foreign keys
SQL> drop table employee;
drop table employee
*
ERROR at line 1:
ORA-02449: unique/primary keys in table referenced by foreign keys
SQL>
It means that you'd first have to drop foreign key constraints, then drop tables:
SQL> alter table employee drop constraint fk_emp_store;
Table altered.
SQL> alter table store drop constraint fk_store_emp;
Table altered.
SQL> drop table store;
Table dropped.
SQL> drop table employee;
Table dropped.
SQL>
That's all, I guess.
One of my field has Data Type as Numeric and the size is (16,8). If I give the value as 0.000000012 will it take and load it in the table? As there are 9 places after the decimal.
It will accept and round the values (at least in 11g):
SQL> CREATE TABLE tst (c1 NUMBER(10,2));
Table created
SQL> INSERT INTO tst VALUES (9.123);
1 row inserted
SQL> INSERT INTO tst VALUES (9.129);
1 row inserted
SQL> SELECT * FROM tst;
C1
------------
9.12
9.13
I have to create an index on a table which has billion of records. at first i thought to create the index using PARALLEL 8 option since the server is running with 8 cores.
Now the question is, nioce the index is created, primary key is created using that index. Can i add NOPARALLEL option?
I have tried this statement
ALTER INDEX PK_TABLE_NAME_ NOPARALLEL;
But it doesn't work. can someone suggest me something?
That should work just fine:
SQL> create table t1
2 as
3 select rownum row_id
4 from dual
5 connect by level <= 100;
Table created.
SQL> create unique index i1 on t1(row_id) parallel 8;
Index created.
SQL> alter table t1
2 add constraint pk1 primary key(row_id)
using index i1;
Table altered.
SQL> alter index i1 noparallel;
Index altered.
I think you're looking for ALTER INDEX myidx parallel 1;
Source: http://www.dba-oracle.com/t_parallel_create_index.htm
Can someone explain what nested table objects are in Oracle ? While building an interface between to systems I discovered what was to me an odd column SYS_NC00054$. After some research I discovered that it was a nested table object from the function based index I created.
Function-based indexes are different from nested tables.
A regular index is built against actual columns ...
create index emp_job_idx on emp (job)
/
... whereas a function-based index is build on functions applied to columns. For instance we might what an index we can use when we query a date column without the time element...
create index emp_hire_idx on emp(trunc(hiredate))
/
When we query USER_IND_COLUMNS, the indexed column shows up in the first case but not in the second, because we are not indexing an actual column. What we see instead is the system generated "column'....
SQL> select index_name, column_name
2 from user_ind_columns
3 where table_name = 'EMP'
4 /
INDEX_NAME COLUMN_NAME
------------------------------ ---------------
PK_EMP EMPNO
EMP_UK ENAME
EMP_JOB_IDX JOB
EMP_HIRE_IDX SYS_NC00010$
SQL>
We can see the make-up of the index in USER_IND_EXPRESSIONS ...
SQL> select index_name, column_expression
2 from user_ind_expressions
3 where table_name = 'EMP'
4 /
INDEX_NAME COLUMN_EXPRESSION
------------------------------ --------------------
EMP_HIRE_IDC TRUNC("HIREDATE")
SQL>
Nested Tables
Nested tables are something different: they are user-defined arrays of simple or complex types. They can be used to define PL/SQL collections or columns in an ORDBMS table. Like this...
SQL> create or replace type address_t
2 as object
3 (
4 address_line_1 varchar2(70)
5 , address_line_2 varchar2(70)
6 , address_line_3 varchar2(70)
7 , address_line_4 varchar2(70)
8 , address_line_5 varchar2(70)
9 , postcode postcodestructure
10 ) final;
11 /
create or replace type address_t
*
ERROR at line 1:
ORA-02303: cannot drop or replace a type with type or table dependents
SQL>
SQL> create or replace type address_nt as table of address_t
2 /
Type created.
SQL>
SQL> create table contact_details (
2 person_id number not null
3 , email_address varchar2(254)
4 , addresses address_nt
5 )
6 nested table addresses store as nested_addresses
7 /
Table created.
SQL>
Basically, a table that has a column that stores data in the form of another table (or other complex type): A table nested inside another.
http://www.databasejournal.com/features/oracle/article.php/3788331/So-what-is-an-Oracle-Nested-Table.htm