How to create form/report on a table which has only primary keys? - oracle

Im trying to create a form with a report on a table that has only primary keys.
I have a table:
create table WRITE
(
author varchar(5) references AUTHOR (authorcode) ,
book varchar(20) references BOOK (bookid),
primary key(author,book)
);
I'm using APEX Application Builder to create a form on a table with report;
But When I get to the "Select the columns to include in the form" , I have no options to select from because I only have unique primary keys in my table.

Which Apex version is it? I've tried it on apex.oracle.com which uses 19.1 and it doesn't have that problem.
Anyway, two options I can think of:
temporarily drop primary key constraint
then create report + form pages
after you're done, create the primary key constraint once again
create an interactive report (using the wizard)
then create a form, manually adding items
this isn't as easy as it looks like because you'll have to create all processes as well (initialization one, along with automatic row processing)
I presume that the first option is a lot simpler.

Related

Oracle Apex 5 File Browser Blob Creation

I'm using APEX 5 for the first time and having issue trying to insert items into my blob table.
I searched for many guides about creating File Browse's storage type to BLOB columns, which allows me to add MIME_TYPE, FILENAME, and CHARSET etc into my table. I am trying to create both upload and download feature.
But one thing that's been really confusing is creating DML processes, I could not understand where they getting their primary key item from, I somewhat understand that the DML primary key column are supposed to be my table's primary key?Errors keep coming up when I try to upload.
: https://i.stack.imgur.com/pj0G0.png
Any kind of help or tips would be greatly appreciated!
Below is my table to store blob
CREATE TABLE "MATERIALS"
( "ID" NUMBER NOT NULL ENABLE,
"MATERIAL_NAME" VARCHAR2(400),
"FILENAME" VARCHAR2(350),
"M_COURSE_ID" VARCHAR2(68),
"MIME_TYPE" VARCHAR2(255),
"DOC_SIZE" NUMBER,
"CHARSET" VARCHAR2(128),
"LAST_UPDATE_DATE" DATE,
"CONTENT" BLOB,
CONSTRAINT "MATERIALS_PK" PRIMARY KEY ("ID")
USING INDEX ENABLE
) NO INMEMORY
You'll need a item on your page to hold the id field. Your first process will populate it. I'm guessing you have a sequence?
Create a Hidden item, I'll call it P1_ID.
Your first process will populate it if it's empty. Create a process at the Processing step with a body of:
apex_util.set_session_state( 'P1_ID', mysequence.NEXTVAL );
Your DML process must run after this step, so drag them around or change the sequence if necessary.
Now set the Primary Key Item value to P1_ID in your DML process.

How to update a column which is also a primary key?

There is a name field in the UI which is also the primary key column in the underlying table. There is a requirement to make that field editable in the UI. There should be an ID which should serve as the primary key, but there isn't and now it is not feasible to introduce any ID column.
Is there any alternate design idea which can be used in such a scenario ?
The UI is in Swing and DB is Oracle.
First of all, I don't know, who thinks Name field can be Primary Key. That's the wrong database design ever.
Yes, you better change it to some ID column as Primary Key and that shouldn't be updated in future. Since, you can't have multiple Primary Key. So, you need to perform some circus here.
You need to drop existing Primary Key first. Since, you can't have multiple Primary Key in single table.
Create your ID column and allow NULL
Then, update this column with sequence.
Once your ID column gets populated, you need to create Primary Key on this column.
You can only have one primary key, but you can have any number of unique indexes on a table. So let the existing primary key be the immutable primary key and have the application use this key internally for everything. Add another column to the table and create a unique index on it. Let the users modify this other field.
Another alternative would be to declare all child tables with foreign keys ON UPDATE CASCADE. That way, any update to the primary key will cascade to the child tables. Once implemented in production, quit the company and run fast in the other direction and write an article about how you were the first person ever to use ON UPDATE CASCADE in a production setting.

Update or Insert into postgres table without any primary key

I have a table which needs to be ingested from Oracle source to Greenland target using ETL tool talend. The table is huge , hence we want to load the data on daily basis incrementally. The table doesn't have any primary or unique key.
Table has date column, I am able to get both inserted/updated records from last update date but to insert that data, we need a primary key.
Any solution on how to load the data without using a primary key?
You need to define your key in talend in the schema of the component that insert into your target table, like this :
And you can use this key to update your table, in the advanced settings of the same component, activate the check box use fields optins and select your key :
This is tested and worked fine against Oracle table that does not have primary key, and it should work for you.

ORA-00955 "name is already used by an existing object"

I need to modify an existing PK. Therefore I drop an recreate it.
ALTER TABLE B DROP CONSTRAINT PK_B;
ALTER TABLE B ADD CONSTRAINT PK_B PRIMARY KEY ("TYP", "NR", "HH", "QUART");
Unfortunately the last Statement will give me an error ORA-00955
If I create the PK constraint like it was defined originally with:
ALTER TABLE B ADD CONSTRAINT PK_B PRIMARY KEY ("TYP", "NR", "HH");
everything works fine.
Perhaps there is an INDEX associated with the PRIMARY KEY CONSTRAINT, and it is also named as PK_B.
You can check it as :
SELECT * FROM USER_INDEXES WHERE TABLE_NAME='<table_name>';
If that's true, then do :
ALTER INDEX "PK_B" RENAME TO "PK_XYZ";
Update : Regarding ALTER INDEX statement, few important points as mentioned by Justin in the comments
Oracle implicitly creates an UNIQUE index to support the PRIMARY KEY CONSTRAINT. Since, the index is of the same name that of the primary key, and now that the primary key is being modified, it is better to drop and re-create the index again as per the definition of the old primary key.
My conclusion :
The primary key constraint is enforced through a unique index.
If Oracle already finds an index – unique or non-unique – it uses it
for the primary key.
If the index was initially created as non-unique, it will continue to
show as non-unique, however it will actually be a unique index.
A good demonstration and quite detailed on other aspects too, by Arup : Primary Keys Guarantee Uniqueness? Think Again.
I had the same issue where I had to do the following to delete reference to a table from the view whilst recreating the database from the scratch. I was searching for the same in tables and indexes first.
connect sys/oracle as sysdba;
select * from all_tables
select * from all_indexes
(finally located the reference in the views)
select * from all_views where view_name like '%WKSTSTATE%';
drop view RUEGEN.WKSTSTATE;

Oracle designer - table definition

I've added a new table definition to a project folder and then created a primary key, however when I click on the 'columns' to create a key component its telling me no mandatory columns are in the Table Definition - create one or more mandatory columns. I've gone back to table definitions but I can't see how I do this and then assign columns to the Primary key?
Any help appreciated!!

Resources