Menu
  • HOME
  • TAGS

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

Tag: oracle,plsql,udt,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).

Best How To :

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;

How to catch Oracle exception “ORA-06535: statement string in OPEN is NULL or 0 length”?

oracle,plsql

Some exceptions have names such as 'TOO_MANY_ROWS'. However, most of oracle exceptions do not have names. So if you want to trap any of them, you need to give them names. For your exception, you can do something like this: DECLARE .... NULL_STRING EXCEPTION; PRAGMA EXCEPTION_INIT(NULL_STRING, -06535); .... Begin .........

Why I can't compare dates?

sql,oracle,oracle10g

First, your date comparison is too complicated. If h.time is an internal date format (which it should be), then just do: WHERE h.time BETWEEN DATE '2015-05-07' AND DATE '2015-06-07' Another very important issue with your query is that the WHERE clause is turning the LEFT JOIN into an INNER JOIN....

Cant delete in database because of constraints

c#,sql,asp.net,oracle

Best way to do it is by using a stored proceed rather than a sql statement in C# code. You are getting error because the referenced records are still present in referenced table and are using cmd.ExecuteReader(); rather than cmd.ExecuteNonQuery();. So you need to delete records for DBS2_MOVIE WHERE MOVIE_ID...

Changing Primary Key in Oracle

oracle,django-models,oracle-sqldeveloper

The biggest problem you have is all the application code which references VENDOR_NAME in the dependent tables. Not just using it to join to the parent table, but also relying on it to display the name without joining to VENDOR. So, although having a natural key as a foreign key...

Column ambiguously defined error with Oracle Merge statement

sql,oracle

You've selected b.itam_first_name and b.itam_last_name twice in the select list. Did you mean to? Should the last two have itrm instead of itam? SELECT A.itam_relevant_appl_code as ret, b.service_id, b.it_service, b.itam_user_id, b.itam_last_name, -- 1st occurrence b.itam_first_name, -- 1st occurrence b.itrm_user_id, b.itam_first_name, -- 2nd occurrence b.itam_last_name -- 2nd occurrence FROM ... If...

Notice: Array to string conversion in “path of php file” on line 64

php,mysql,arrays,oracle

Curly brackets are your friend when inserting variables into double quoted strings: $main_query=oci_parse($connection,"INSERT INTO ROTTAN(NAME,ROLLNO) VALUES('{$array[$rs][0]}','{$array[$rs][1]}')"); ...

How to join 2 tables with select and count in single query

sql,oracle,left-join

With your sample data, you don't even need the Person table -- because you seem to have redundant table in the two tables. You should probably fix this, but: select pl.id, pl.name, count(*) from personline pl group by pl.id, pl.name; Your count is just counting all the rows from the...

SQL*Loader Control File Custom Date Format

oracle,toad,sql-loader

Try with below code time date 'YYYY-MM-DD"T"HH24MISS' ...

Entity Framework code-first: querying a view with no primary key

sql,oracle,entity-framework,view,ef-code-first

It's not possible in Entity Framework to have Entities without primary key. Try to get a possible unique key from the views, combining columns, ... to create a unique primary key. If is not possible there is a workaround, if is only a queryable view, with out need to do...

Find any character occur more than 4 times

sql,regex,oracle

SELECT regex_test_name FROM regex_test WHERE REGEXP_LIKE(regex_test_name, '([[:alpha:]])\1{3,9}') Inspired by dnoeth's answer, but since it catches the first character, specifying 3-9 subsequent repeats means 4-10 successive occurences in total....

Using MyBatis Update with foreach

sql,oracle,mybatis

try with open = "'" close = "'" and separator = "," and ${item} With these settings mybatis does not bind the variables but performs a String substitution. Be careful that string substittution is vulnerable to sql injection. If you face some more problems please post the updated sql query...

update a table from another table using oracle db

sql,oracle

Try this instead: UPDATE product SET provider_name = ( SELECT p.name FROM provider p WHERE p.provider_id = product.provider_id ); ...

Result from pipelined function, always will sorted as “written”, or not?

sql,oracle,plsql,oracle12c

Pipelining negates the need to build huge collections by piping rows out of the function as they are created, saving memory and allowing subsequent processing to start before all the rows are generated pipelined-table-functions This means, it will start processing the rows before get fetched completely and that's why...

Why does the date doesn't match with what I have inserted into the database?

sql,database,oracle

In the TO_DATE function you have to keep the format. The first parameter is the data and the second parameter is the format you are putting it. For example: to_date('29-Oct-09', 'DD-Mon-YY') to_date('10/29/09', 'MM/DD/YY') to_date('120109', 'MMDDYY') to_date('29-Oct-09', 'DD-Mon-YY HH:MI:SS') to_date('Oct/29/09', 'Mon/DD/YY HH:MI:SS') to_date('October.29.2009', 'Month.DD.YYYY HH:MI:SS') So if you put TO_DATE('05-06-2015','yyyy/mm/dd HH24:MI:SS')...

Identifier is too long

sql,oracle

Use single quotes for string in PL SQL declare type app_realm_rec is record ( resource_filter varchar2(500), status varchar2(500), role varchar2(500) ); type app_realm_tab is table of app_realm_rec index by pls_integer; realm_tab app_realm_tab; begin realm_tab(1).resource_filter := '/secure/records*'; realm_tab(1).status := 'true'; realm_tab(1).role := 'ou=internal,ou=users,dc=chinastreet,dc=com;ou=external,ou=users,dc=chinastreet,dc=com'; realm_tab(2).resource_filter := '/secure/login'; realm_tab(2).status := 'false'; realm_tab(2).role :=...

How to use subquery result as the column name of another query

sql,oracle,plsql

Use your sub query as an inline table. Something like.... select item, item_type, .. decode(fore_column_name, 'foo', 1, 2) * 0.9 as finalforcast, decode(fore_column_name, 'foo', 1, 2) * 0.8 as newforcast from sales_data, ( select fore_column_name from forecast_history where ... ) inlineTable I'm assuming here that the value from the sub-query...

Oracle 11g Insert Statement into Multiple Tables

sql,oracle,oracle11g,triggers,sql-insert

Based on your comment, I'm still not clear on what tool you are using to submit the statements to the database. It's quite possible that your query tool can only handle one statement at a time. And even if you batch up the 3 statements the way you did, those...

SQL Oracle | How to delete records from a table when they match another table?

sql,oracle,delete

If it's a small delete table: delete from TableA A where a.key in ( select key from deleteTable ); If it's a bigger table, you can try an EXISTs: delete from TableA A where exists ( select * from deleteTable d where d.key = A.key ); All this depends of...

PLS-00103: Encountered the symbol “;” when expecting one of the following:

plsql,plsqldeveloper

No need (and not valid) to add a block label outside of the code. Try something like: DECLARE o_mgr_id NUMBER(6) := 1; dept_count number := 0; BEGIN SELECT count(*) INTO dept_count FROM EMP WHERE EMPNO = o_mgr_id; IF dept_count > 0 THEN <<inner_block>> DECLARE dept_name VARCHAR2(30); i_mgr_id NUMBER(6) := 1;...

SQL Error: ORA-00933: SQL command not properly ended in Oracle Update query

sql,oracle,sql-update

This code should be like this : sp_id = 'SP602' to sp_id = ''SP602'' and this '2' to ''2'' your final code should be like this Update RATOR_MONITORING_CONFIGURATION.SYSTEM_SQL_CHECK SET CHECK_SQL = 'select count(*) as CNT from O2_SDR_Header where id = (select max(id) from O2_SDR_Header where id > 2012000000000000 and sp_id...

Oracle SQL - Returning the count from a delimited field

oracle

SQL Fiddle Oracle 11g R2 Schema Setup: CREATE TABLE TableAccount ( value ) AS SELECT 'P1:P2:P3' FROM DUAL UNION ALL SELECT 'P1' FROM DUAL UNION ALL SELECT 'P2:P3' FROM DUAL UNION ALL SELECT 'P1:P3' FROM DUAL UNION ALL SELECT 'P1:P4' FROM DUAL UNION ALL SELECT 'P5' FROM DUAL; Query 1:...

Why does .Where() with a Func parameter executes the query?

c#,oracle,linq,entity-framework

There is a very important difference between Enumerable.Where and Queryable.Where: Enumerable.Where takes a Func<T, bool>. Queryable.Where takes an Expression. Your filter variable is not an Expression, it is a Func<T, bool>, therefore, the compiler uses Enumerable.Where. What happens then is that all rows of your FOO table are transferred to...

oracle sql error Case When Then Else

sql,oracle,oracle11g

Perhaps this is what you want? If there are rows in SecondTable, then do the second EXISTS: SELECT * FROM FirstTable WHERE RowProcessed = 'N' AND (NOT EXISTS (SELECT 1 from SecondTable) OR EXISTS (SELECT 1 FROM SecondTable WHERE FirstTable.Key = SecondTable.Key and SecondTable.RowProcessed = 'Y')) AND OtherConditions ...

Dealing with nulls when selecting in MyBatis

java,oracle,mybatis

Try this way, <result column="DATE_TO" property="dateTo" jdbcType="DATE" javaType="java.util.Date"/> And also need to check and update your JDBC jar file.Check the compatibility of ojdbc.jar here (I think you should need at least ojdbc6.jar) . For additional checking, If you have declared in your mybatis configuration xml file like this <settings> <setting...

sql script to find index's tablespace_name only

sql,database,oracle

SELECT DTA.* FROM DBA_TABLESPACES DTA, dba_indexes DI WHERE DI.TABLESPACE_NAME = DTA.TABLESPACE_NAME AND DI.OWNER ='USER' AND NOT EXISTS (SELECT 'x' FROM DBA_TABLES DTT WHERE DTT.TABLESPACE_NAME = DTA.TABLESPACE_NAME AND DTT.OWNER = DI.OWNER ); ...

Trigger to find next available inventory location

oracle,triggers,inventory

There are several ways to do it. You could add column AVAILABLE or OCCUPIED to first table and select data only from this table with where available = 'Y'. In this case you need also triggers for delete and for update of location_id on second table. Second option - when...

'ORA-00942: table or view does not exist' only when running within a Stored procedure

oracle,plsql

Sounds like an issue with select privileges granted via a role, rather than directly to the schema. See ORA-00942: table or view does not exist (works when a separate sql, but does nto work inside a oracle function).

Trying to access Oracle's Maven repository

oracle,maven,repository

From your settings.xml I can see that you use Artifactory. Why won't you define Oracle's repository as a remote in Artifactory? That will make the access much easier. Here's a simple guide on how to do so. And, of course, here's the official user guide on it. I am with...

Optimizer using an index not present in the current schema

oracle,indexing,optimizer

You're connected as user ALLL, but you're querying a table in the HR schema: SELECT /*+ FIRST_ROWS(25) */ employee_id, department_id FROM hr.employees WHERE department_id > 50; You stressed other schema in the question, but seem to have overlooked that the table you're querying is also in another schema. The employees...

Groovy - timestamp from minutes

oracle,grails,groovy,timestamp

I assume you want to use the current day offset with the number of minutes given for your timestamp. Since a new Date or Timestamp will be initialized to the current time and date, you can use that and override the minute field with the values from your array. Values...

How to derive years of service for employees that have termed and returned several times

sql,oracle,oracle11g

As @PonderStibbons pointed out, this can be done quite simply by adding together the span of each hired period, and also adding the span of the between-hiring periods if the bridge value is 'Yes'. Open-ended hirings and different numbers of hirings can be handled by treating all null dates as...

PLSQL - Error in associative array

oracle,plsql,associative-array

You have some unterminated append operations || on lines: Dbms_Output.Put_Line('Dropping TABLE '|| L_Key ||); And EXECUTE IMMEDIATE 'create table schema1.' ||l_key||' as select * from schema2.'||l_tbl(l_key)||; Get rid of the || at the end. Also the way you are using LOOP is incorrect. Refer example: while elem is not null...

SQL Oracle | How would I select a substring where it begins with a certain letter and ends with a certain symbol?

sql,oracle,select,substring

You can use a Regular Expression: regexp_substr('Hazel/Green==F123==Brown','(==F.+?==)') extracts '==F123==', now trim the =: ltrim(rtrim(regexp_substr('Hazel/Green==F123==Brown','(==F.+?==)'), '='), '=') If Oracle supported lookahead/lookbehind this would be easier... Edit: Base on @ErkanHaspulat's query you don't need LTRIM/RTRIM as you can specify to return only the first capture group (I always forget about that). But...

Get only Oracle function return table's columns and their types

c#,oracle

For current login, use SELECT uta.attr_name, uta.attr_type_name || CASE WHEN uta.length IS NOT NULL THEN '('||uta.length||')' ELSE NULL END FROM user_coll_types uct JOIN user_type_attrs uta ON uta.type_name = uct.elem_type_name WHERE uct.type_name = 'COLLECTION_NAME' ORDER BY uta.attr_no; For the logged in user having access on types from another users: SELECT ata.attr_name,...

Exclude / ignore weekends in Oracle SQL

sql,oracle

Your query with small modification in case ... when excluding weekend days: select min(d), max(d), v from ( select d, v, sum( gc) over (partition by v order by d) g from ( select d, v, case when d-lag(d) over (partition by v order by d) = decode(trunc(d, 'iw') -...

Can't obtain connection with the DB due to very long schema validation and connection reset afterwards

java,oracle,hibernate

Have you tried the solutions in the following question? Oracle 11g connection reset error One particular answer had to do with the following comment: I could get it resolved by adding this parameter to the Hotspot JVM: -Djava.security.egd=file:/dev/./urandom This issue does not affect windows, so it might be similar to...

How to design a history for n:m relations

sql,plsql,many-to-many

What about this commonly used model? create table cross_ref ( a_id references a , b_id references b , from_ts timestamp , to_ts timestamp , primary key (a_id, b_id, from_ts) ); (NB I used timestamp as you did; normally I would use date)...

SQL Developer does not connect with SID as defined in tnsnames.ora

oracle,oracle-sqldeveloper

The CLRExtProc entry in the tnsnames.ora is for external processes. That is not the database SID you use for normal client connections. The ORCL entry is defined to use servicename orcl. The service name and SID may or may not be the same. The database instance has a single SID,...

like and regexp_like

sql,regex,oracle,oracle11g,regexp-like

Try this one: SELECT * FROM employee WHERE REGEXP_LIKE (fname, '^pr(*)'); Fiddle This one also seems to work as far as I can tell: SELECT * FROM employee WHERE REGEXP_LIKE (fname, '^pr.'); Or another one that works: SELECT * FROM employee WHERE regexp_like(fname,'^pr'); ...

Fill with zero to complete a defined number in sql [closed]

sql,oracle

You could use lpad, but if you're starting with a number you could use a 9-digit format model instead, and concatenate that onto your prefix: select '11111' || to_char(25, 'FM000000000') from dual; 11111000000025 The FM format modifier stops Oracle adding a space for a potential +/- sign indicator. SQL Fiddle...

Extracting XML data from CLOB

sql,xml,oracle

Use xmltable. Data setup: create table myt( col1 clob ); insert into myt values('<ServiceDetails> <FoodItemDetails> <FoodItem FoodItemID="6486" FoodItemName="CARROT" Quantity="2" Comments="" ServingQuantityID="142" ServingQuantityName="SMALL GLASS" FoodItemPrice="50" ItemDishPriceID="5336" CurrencyName="INR" CurrencyId="43"/> </FoodItemDetails> <BillOption> <BillDetails TotalPrice="22222" BillOption="cash"/> </BillOption> <Authoritativeness/> </ServiceDetails>' ); commit; Query:...

Calculating overlap between groups

sql,oracle,oracle11g,pivot

You can use simple PIVOT: SELECT t1.bucket_id, SUM( CASE WHEN t2.bucket_id = 'A' THEN 1 ELSE 0 END ) AS A, SUM( CASE WHEN t2.bucket_id = 'B' THEN 1 ELSE 0 END ) AS B, SUM( CASE WHEN t2.bucket_id = 'C' THEN 1 ELSE 0 END ) AS C, SUM(...

Get unmatched records without using oracle minus except not in

oracle,plsql,inner-join,outer-join

The one option left with you is using NOT EXISTS SELECT t1.name FROM table1 t1 WHERE NOT EXISTS (SELECT 'X' FROM table2 t2 WHERE t2.name = t1.name); Update: Using Join with table_ as ( select t1.name t1_name, t2.name t2_name from table1 t1 left join table2 t2 on t1.name = t2.name)...

How to pull the date in proper format from timestamp

oracle,timestamp

Try formatting your date to use a full 4 digit year using the to_char function and then do an export to excel. SELECT TO_CHAR(Trunc(assigned_date, 'IW'), 'MM-DD-YYYY') AS bonus_week Note: I am assuming you have an issue of 28 getting converted to 2028 instead of 1928. The solution above should fix...