How to update a type as datatype reference in another table - oracle

create or replace type My_abc_typ FORCE as object
(
...
Pqr pqr_typ,
...
)
/
Actually the Table My_abc is created as
CREATE TABLE "ABC"."My_abc" OF "ABC"."My_abc_TYP"
(... ,
...)
and primary keys and indexes are there for this
the problem is in type i ve changed the data type of a particular column , and compiled it... its working fine.
but the table is not reflecting the change... its showing
(
...
Pqr (null),
...
)
in order to modify that column alone i executed the following query
alter table My_abc modify Pqr pqr_typ;
the following error appears
SQL Error: ORA-04063: table "ABC.My_abc" has errors
04063. 00000 - "%s has errors"
*Cause: Attempt to execute a stored procedure or use a view that has
errors. For stored procedures, the problem could be syntax errors
or references to other, non-existent procedures. For views,
the problem could be a reference in the view's defining query to
a non-existent table.
Can also be a table which has references to non-existent or
inaccessible types.
*Action: Fix the errors and/or create referenced objects as necessary.

Instead of re-creating type:
modify the typ attribute as:
ALTER TYPE my_abc_typ MODIFY ATTRIBUTE (pqr VARCHAR2(20))CASCADE NOT INCLUDING TABLE DATA;
Link: http://docs.oracle.com/cd/E11882_01/appdev.112/e11822/adobjadv.htm
Thanks.

Related

How to give a field of an object the same type as a column of a table?

I would like to a object with a field that has the same type as column of a table.
create table TA (
TA_1 number
);
CREATE TYPE my_obj2 IS object
(
TA_1 TA.TA_1%type
);
ORA-24344: success with compilation error
Is it possible. If yes, what is wrong in this code?
code
You can't do that.
The CREATE TYPE document states:
This data type must be stored in the database; that is, either a predefined data type or a user-defined standalone collection type.

Impossible to create trigger in a table with a reserved name in Oracle

I have a table named BLOB, and I can select, update, insert normally via SQL, but it's impossible to define a trigger for it, obviously the cause is the name.
In PL/SQL as a procedure, I work around the problem by creating a view which selects all the columns of the table, and using it in the body but it doesn't work on the table itself.
Does anyone have a solution? I cannot rename the table. Also using a synonym is out.
Structure of the table:
CREATE TABLE BLOB
(
BLOBID CHAR(7 BYTE) NOT NULL,
OGGETTO BLOB
)
The problem is related to the presence of a column of type BLOB in a table named BLOB, but only in PL/SQL environment (procs, triggers, ...)

Can I add a subcolumn to a hive struct column using alter table?

I've a very complex table structure in hive, let's say that it's like the following table:
create table dirceu ( a struct<b:string,c:string>);
Now I do need to add another subcolumn to the a column, and it should have the structure b,c and d, I'm trying to do it with the following alter table:
alter table dirceu change column a a struct<b:string,c:string, d:string>;
But this throw the following error:
Error: Error while processing statement: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. Unable to alter table. The following columns have types incompatible with the existing columns in their respective positions :
a (state=08S01,code=1)
Is there a way to do this using alter table? I know that I can do it using create table and copy the data, but I would like to know if there is another way to do it.
UPDATE
I'm using hive: 2.1.0.2.6.1.0-129
HortonWorks: HDP-2.6.1.0
This is the command you need to give,
ALTER TABLE dirceu CHANGE COLUMN a a STRUCT<b:STRING, c:STRING, d:STRING>;
You can't add a new field to Collection data type. Instead, you need to completely change the schema.
Hope you like the answer. Yippee!!
I guess it works by this command,
alter table dirceu add column a struct<d:string>;
Please let me know if it doesn't work by comment.

Add enum type column to table

im trying to add a new column to my existing table 'Results', and it seems to be very easy but I cant see the mistake.
Here is my code:
SQL> Alter table results add column CAL ENUM('A','B');
ERROR at line 1: ORA-00904: : invalid identifier
What am I missing?
I've read this from w3 and this from java2s but cant see the difference to mine.
Thanks, and sorry for the dumb question.
OK, with an ORA- error I am assuming that this is an oracle database, and not mysql. you have both tags and you are linking to MySQL example, but the error is not a MySQL error.
Assuming that this IS an Oracle DB, then there is no native ENUM data type. You have to do this as follows: First - you add the column with a correctly defined data type, and second you create a constrained list of permitted values on that column as a check constraint.
Alter table results add (cal varchar2(1));
Alter table results add constraint chk_cal CHECK (cal in ('A','B')) ENABLE;
(EDITED to fix brackets in constraint creation line)

Oracle PL/SQL table of parent object type breaks when I add another inheriting child object type

I am using custom object types with Oracle PL/SQL, including several object types that inherit from a parent object. I have a TP_DOCUMENTS parent object, and child document types, such as TP_PUBLICATION, TP_CONTRACT, etc. We successfully created a table of TP_DOCUMENT and have added records of TP_PUBLICATION, TP_CONTRACT, and other child document records. However, I needed to create an additional type of document. Once I did this, it broke the DOCUMENTS table. How can I create additional child types, without breaking the table of the parent object (making me lose all the data previously contained in the parent object table!!)?
Here is some of my code:
create or replace TYPE "TP_DOCUMENT" AS OBJECT
(
...fields go here
) NOT FINAL
create or replace TYPE "TP_PUB_INSTRUCTION" UNDER TP_DOCUMENT()
CREATE TABLE DOCUMENTS OF TP_DOCUMENT
After creating these types (and others with additional fields), I created the table DOCUMENTs as shown above. I tried to create another sub-type, and the DOCUMENTS table broke.
MORE INFORMATION:
The error code message is as follows:
ORA-04063: table/view has errors
Cause: Attempt to execute a stored procedure or use a view that has errors. For stored procedures, the problem could be syntax errors or references to other, non-existent procedures. For views, the problem could be a reference in the view's defining query to a non-existent table. Can also be a table which has references to non-existent or inaccessible types.
Action: Fix the errors and/or create referenced objects as necessary.
Thank you!
UPDATE WITH ANSWER FROM COMMENTER BELOW:
I had unfortunately dropped a Sub-Type using the Force option. That likely was the cause for why my Documents table was corrupted. In the future, I will use the Validate command (see answer below).
Instead of FORCE you should use the VALIDATE option when dropping types:
VALIDATE
If you specify VALIDATE when dropping a type, then Oracle Database
checks for stored instances of this type within substitutable columns
of any of its supertypes. If no such instances are found, then the
database completes the drop operation.
This clause is meaningful only for subtypes. Oracle recommends the use
of this option to safely drop subtypes that do not have any explicit
type or table dependencies.
Here's an example:
create or replace type tp_document as object
(
a number
) not final;
create or replace type tp_pub_instruction under tp_document();
create table documents of tp_document;
--This fails with this error message:
--ORA-02303: cannot drop or replace a type with type or table dependents
drop type tp_pub_instruction;
--This works since there's no data with that type.
drop type tp_pub_instruction validate;

Resources