I try create project but I have get to proplem
in form builder when I click right and chose data block then chose table and click in add realshenshep I get these error said 'error no master data blocks are available'
Please help me
I am waiting to reply me
Thanx
If you want the Wizard to create relationship between master and detail block, underlying tables have to be related - master table has to have a primary key, and it has to be referenced by detail table's foreign key.
Forms is capable of detecting that and, if it exists, can create the relationship.
Otherwise, if there's no such a relation between those tables, you'll have to create it manually.
[EDIT]
How to create a foreign key?
SQL> create table master
2 (id number,
3 name varchar2(20));
Table created.
SQL> create table detail
2 (id number,
3 idm number,
4 datum date
5 );
Table created.
SQL> -- create a primary key on the master table
SQL> alter table master add constraint pk_mas primary key (id);
Table altered.
SQL> -- create a foreign key on the detail table
SQL> alter table detail add constraint fk_det_mas foreign key (idm)
2 references master (id);
Table altered.
SQL>
As of manually creating a relationship: put the join condition in there, such as
detail.idm = master.id
Related
please help me with an example on how to add primary key to materialized view in oracle 19c or 21c.
Also, real life application where we use primary key to materialized view. I posting this after complete research on materialized view.
I have a strong opinion that primary key is not required on materialized view. Please correct me if I am wrong.
How to add a primary key? Using the ALTER TABLE statement.
This is a sample table; I'll create a materialized view on it.
SQL> create table test as
2 select deptno, empno, ename, job
3 from emp;
Table created.
SQL> create materialized view mv_test as
2 select deptno, empno, ename, job
3 from test;
Materialized view created.
Primary key:
SQL> alter table mv_test add constraint pk_mvt primary key (empno);
Table altered.
SQL>
Real life: use it whenever appropriate. Primary key implicitly creates index on primary key column(s). Index improves performance (if optimizer chooses to use it).
I am trying to make foreign key connections between flat and nested tables in SQL Developer.
Scenario One:
Flat table to Nested table using a foreign key connection.
In this scenario, I want to connect the flat table "GRANPARENT_TABLE" directly with the table "CHILD_TABLE", which "CHILD_TABLE" is nested to "PARENT_TABLE".
First I create the nested table "CHILD_TABLE" INSIDE the table "PARENT_TABLE"
CREATE TYPE CHILD_OBJECT AS OBJECT(
CHILD_ID NUMBER
);
CREATE TYPE CHILD_TYPE IS TABLE OF CHILD_OBJECT;
CREATE TABLE PARENT_TABLE (
PARENT_ID NUMBER,
CHILD CHILD_TYPE
)NESTED TABLE CHILD STORE AS CHILD_TABLE;
After creating the tables "PARENT_TABLE" and "CHILD_TABLE",
I declare a primary key to the nested table "CHILD_TABLE"
ALTER TABLE CHILD_TABLE
ADD CONSTRAINT CHILD_TABLE_PK PRIMARY KEY (CHILD_ID);
Finally, I create the "GRANDPARENT_TABLE" and at the same time I make the foreign key connection
between the flat table "GRANDPARENT_TABLE" and the nested table "CHILD_TABLE".
CREATE TABLE GRANDPARENT_TABLE(
GRANDPARENT_ID NUMBER,
CHILD_ID NUMBER,
CONSTRAINT GRANDPARENT_TO_CHILD FOREIGN KEY (CHILD_ID) REFERENCES CHILD_TABLE(CHILD_ID)
);
The result of the above scenario is the successful creation of the foreign key connection,
as shown below:
Flat table to Nested table foreign key connection
So far, so good.
Scenario Two:
Nested table to Flat table using a foreign key connection.
In this scenario, I want to connect the nested table "CHILD_TABLE", which is inside the table "PARENT_TABLE", directly with the flat table "GRANDPARENT_TABLE".
First I create the flat table "GRANDPARENT_TABLE"
CREATE TABLE GRANDPARENT_TABLE(
GRANDPARENT_ID NUMBER,
CHILD_ID NUMBER
);
Then create the the nested table "CHILD_TABLE" inside the table "PARENT_TABLE"
CREATE TYPE CHILD_OBJECT AS OBJECT(
CHILD_ID NUMBER
);
CREATE TYPE CHILD_TYPE IS TABLE OF CHILD_OBJECT;
CREATE TABLE PARENT_TABLE (
PARENT_ID NUMBER,
CHILD_ID CHILD_TYPE
)NESTED TABLE CHILD_ID STORE AS CHILD_TABLE;
I continue declaring the primary key of the nested table "CHILD_TABLE"
ALTER TABLE CHILD_TABLE
ADD CONSTRAINT CHILD_TABLE_PK PRIMARY KEY (CHILD_ID);
Finally, I TRY to make the foreign key connection between the flat table "GRANDPARENT_TABLE" and the nested table "CHILD_TABLE"
ALTER TABLE CHILD_TABLE
ADD CONSTRAINT CHILD_TO_GRANDPARENT FOREIGN KEY (CHILD_ID) REFERENCES GRANDPARENT_TABLE(CHILD_ID);
but, in this scenario, Oracle SQL Developer won't allow such action and return the following error:
Error report -
ORA-30730: referential constraint not allowed on nested table column
30730. 00000 - "referential constraint not allowed on nested table column"
*Cause: An attempt was made to define a referential constraint on a nested
table column.
*Action: Do not specify referential constraints on nested table columns.
Although, in the first scenario, Oracle SQL Developer would let me make the connection between the two tables, in the second one, it won't allow such action. Why is this happening? Is there any way to make the connection possible in the second scenario?
As the ORA-30730 says, you cannot create a referential constraints on nested table columns. This is forbidden. In scenario one you are creating the constraint on GRANDPARENT_TABLE, not the other way around. This is possible.
This link suggests a workaround to do what is forbidden to do, but it's not your case:
http://ksun-oracle.blogspot.com/2011/05/foreign-key-on-nested-table.html
As a general suggestion, avoid the use of nested tables, they cause lots of problems, be sure!
I have an Oracle table in a live production environment and the table is over half a gig in size. Is it possible to change this normal Oracle table from being heap organised to index organised or is this only achievable by moving the data from this table to another new table which is index organised? Either way, I would be grateful if you could you please list the steps involved in this procedure.
There is no way to alter a table to make it index-organized table. Instead you can redefine the table(using DBMS_REDEFINITION)or can create new table using CTAS.
Example:
create table t2 (
id number, first_name varchar2(20),
constraint pk_id primary key (id)
)
organization index
as select * from t1;
I never used DBMS_REDEFINITION but with CTAS it is not only step to create table if it is production.
List all indexes, constraints, foreign keys and so on based on system views
Prepare create index, constraints and alter foreign keys statements. prepare list of triggers, procedures that depend on table.
Create table as select (consider lock before that step if you can)
Create all indexes, constraints with prepared statements from step 2
Swap table names and swap foreign keys (this step may cause some errors if you hit insert on foreign keys (if you expect it on that time you should lock the table and tables referencing by foreign key).
Compile dependent objects from 2 (if you locked tables unlock here)
(if you haven't locked on step 3) Insert into table select * from new minus select * from old; or if you have timstamp of inserting row just insert new rows.
I hope the list is complete.
Initial situation:
A table PARENT_TABLE with a primary key on its column PK_COL.
A table CHILD_TABLE1 with a foreign key on PARENT_TABLE(PK_COL).
I insert a line into CHILD_TABLE1 in a transaction and do not commit.
Then I try to create a table CHILD_TABLE2 symmetrical to CHILD_TABLE1 in another session.
But an ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired is raised when I create the foreign key, because of the ongoing insertion in CHILD_TABLE1.
I don't understand why Oracle is preventing the foreign key creation: there is no modification performed on PARENT_TABLE.
Please help.
To reproduce under sqlplus:
set autocommit off
create table PARENT_TABLE(PK_COL varchar(10));
alter table PARENT_TABLE add constraint PK_CONSTRAINT primary key (PK_COL);
insert into PARENT_TABLE values ('foo');
commit;
create table CHILD_TABLE1(CHILD_PK_COL varchar(10), FK_COL varchar(10));
alter table CHILD_TABLE1 add constraint CHILD_TABLE1_CONSTRAINT foreign key (FK_COL) references PARENT_TABLE(PK_COL);
create index CHILD_TABLE1_INDEX on CHILD_TABLE1(FK_COL);
insert into CHILD_TABLE1 values ('bar', 'foo');
In another console:
alter session set ddl_lock_timeout=10;
create table CHILD_TABLE2(CHILD_PK_COL varchar(10), FK_COL varchar(10));
alter table CHILD_TABLE2 add constraint CHILD_TABLE2_CONSTRAINT foreign key (FK_COL) references PARENT_TABLE(PK_COL);
Funny: with NOVALIDATE in CHILD_TABLE2_CONSTRAINT creation, the execution is hanging...
You are not modifying something in the parent table. But you're
actually, trying to refer its primary key in your child table. Before
establishing a relationship or any DDL with table, it has to be free
of locks.
So, before creating this constraint, Oracle do check for existing locks over the referred table(PARENT_TABLE). A lock over a table(Table Level Lock,in this context) is actually for a reason to adhere to the ACID properties.
One best example to understand its importance is ON DELETE CASCADE which means if a record in the parent table is deleted, then the corresponding records in the child table will automatically be deleted.
So, when there's a uncommitted insert/update/delete over the child table referring a parent table. No other referential constraint can be created to the parent. Just to avoid a deadlock or chaos.
To be more crisp, when you have an uncommitted insert in your child table.
There's a lock over your parent table as well. So all other further DDLs referring it will be made wait.
You can use this query to check the same.
SELECT c.owner,
c.object_name,
c.object_type,
b.sid,
b.serial#,
b.status,
b.osuser,
b.machine
FROM v$locked_object a ,
v$session b,
dba_objects c
WHERE b.sid = a.session_id
AND a.object_id = c.object_id;
I added the LOCKED_MODE explanation in you query:
DECODE(a.LOCKED_MODE, 0,'NONE', 1,'NULL', 2,'ROW SHARE (RS/SS)', 3,'ROW EXCLUSIVE (RX/SX)', 4,'SHARE (S)', 5,'SHARE ROW EXCLUSIVE (SRX/SSX)', 6,'EXCLUSIVE (X)', NULL) LOCK_MODE.
Here is the result:
OBJECT_NAME OBJECT_TYPE LOCK_MODE SID SERIAL# STATUS
------------------------------ ------------------- ----------------------------- ---------- ---------- --------
PARENT_TABLE TABLE ROW EXCLUSIVE (RX/SX) 71 8694 INACTIVE
CHILD_TABLE1 TABLE ROW EXCLUSIVE (RX/SX) 71 8694 INACTIVE
RX/SX is a table lock so it prevents any DDL operation (That seems to be said in the doc). This lock is used on both parent and child. I suppose that the lock is added on parent to at least prevent it from being deleted so we would lost the pending update on the child table.
That said, I still have no solution. Suppose that the parent table is a manufacturer. There is a child car table and we are inserting plenty of new cars in that table on the fly. There is a foreign key from car to manufacturer. Now there is a new product that we want to manage: "bicycles". So we want to create a bicycle table similar to car. But we cannot create the table as we are performing insertions in car. Seems a very simple use case... How to support it?
=====
Edit:
There might be no solution. Here is a guy with the same issue.
In MS SQL Server it is possible to create a foreign key with ON UPDATE CASCADE option, so whenever you update one of the columns in the primary key, the foreign keys in other tables will also be update by the DBMS.
So, how to do it in Oracle?
Oracle does not allow a Foreign Key constraint with “ON UPDATE CASCADE”.
Here are a couple of options you have.
Create the Foreign Key, and create an “On Update” trigger.
Make use of the package below (needs to be installed in the db).
http://tkyte.blogspot.com/2009/10/httpasktomoraclecomtkyteupdatecascade.html
Let me know if you have additional questions or need more information.
Would a database trigger do the job for you ?
Here is the Oracle doc on the subject of Data Integrity for 11g (just incase you were interested).
You can't use on update cascade, but you can create a trigger that will resolve the issue:
create table tab1(
pk int PRIMARY KEY,
aa int);
create table tab2(
pk int PRIMARY KEY,
tab1_pk int,
FOREIGN KEY(tab1_pk) REFERENCES tab1(pk));
------------------------------------------
create or replace trigger tab1_pkUpdate
after update of pk on tab1
for each row
begin
update tab2 s
set s.tab1_pk = :new.pk
where s.tab1_pk = :old.pk;
end;
/