ORA-12996: cannot drop system-generated virtual column - oracle

After marking a column as unused on my compressed and partitioned table, whenever i try to do
ALTER TABLE t1 DROP UNUSED COLUMNS;
I get the error:
ORA-12996: cannot drop system-generated virtual column
What can i do?

This worked for me:
alter table t drop unused columns checkpoint 500;

The system-generated virtual column typically supports a function-based index.
Please show us the DBMS_METADATA.GET_DDL() for the table just like in this Ask Tom example.
Once the source of the column is known, dropping it may be easier (or maybe not in some unusual cases.)

Related

Hive drops all the partitions if the partition column name is not correct

I am facing a strange issue with hive,
I have a table, partitioned on the basis of dept_key (its a integer eg.3212)
table is created as follows
create external table dept_details (dept_key,dept_name,dept_location) PARTITIONED BY (dept_key_partition INT) ROW FORMAT DELIMITED FIELDS TERMINATED BY '~' LOCATION '/dept_details/dept/';
Now I have some partitions already added e.g: 1204,1203,1204
When I tried dropping the partition I by mistake typed only dept_key and not "dept_key_partition" this in turn dropped all my partition
drop query alter table dept_details drop partition (dept_key=12), its a very strange issue which I am facing. Please let me know what can be the probable issue.
Thank you.
From Hive LanguageManual DDL...
As of Hive 0.14 (HIVE-8411), users are able to provide a partial
partition spec for certain above alter column statements, similar to
dynamic partitioning (...) you can change many existing partitions at once using a single ALTER statement (...) Similar to dynamic partitioning, hive.exec.dynamic.partition must be set to true
Looks like the partial specification feature has been ported to other commands like DROP, TRUNCATE even if it's not explicit in the documentation.
In short: it's not a bug, it's a feature.

Drop column in compressed table

is there any chance to drop a column in a compressed table?
I checked google and it seems like its not possible at all.
to get sure im asking here.
regards
set that column to unused:
ALTER TABLE TEST SET UNUSED (column name);
ALTER TABLE TEST DROP unused columns;
Note: This statement does not actually remove the target column data or restore the disk space occupied by these columns. However, a column that is marked as unused is not displayed in queries or data dictionary views, and its name is removed so that a new column can reuse that name. All constraints, indexes, and statistics defined on the column are also removed.
If that does not work for you for some reason, you can try to move the table into a non-compressed format and then drop the column and compress again.

Enforcement of unique/primary key - drop index

I am trying to drop an index :
DROP INDEX PK_CHARGES
but I get this error
cannot drop index used for enforcement of unique/primary key
Why I am getting this error? I will provide further information if you need any.
How to solve it?
Edit I have no primary key in the table, but I found this weird index that I don't remember I had added:
index name = SYS_C0040476 which have the same columns
You can query the ALL_CONSTRAINTS performance view to see which constraint the index is used by, and which table it applies to, e.g:
select owner, constraint_name, constraint_type,
table_name, index_owner, index_name
from all_constraints
where index_name = 'PK_CHARGES';
I would expect the table name to be 'CHARGES', the constraint name to match the index name, and the constraint type to be 'P'. But since you have a table in mind, perhaps the names aren't following a helpful convention. Maybe an old version of the table was renamed, which would leave the constraints against the new name (e.g. CHARGES_BACKUP or something).
You said you click on the table, then on the view. Perhaps you're not looking at the table that the constraint/index is on; or perhaps you're looking at a view on top of the actual table. You also mention a SYS_ index on the same columns - which can't be on the same table. Do you have multiple similar tables, or access to multiple schemas? You shold run the above query for that index too. As mentions above, you might find an old version (or versions) of the table.
Once you've identified which table the constraint is on, you'll need to decide whether you should actually be keeping it, and if not you can remove it by dropping the constraint with an ALTER TABLE command.
The problem with
But I found this weird index that I dont rember I hadve add
comes because you didn't add it. You had a primary key, then you dropped it, but when you do that Oracle doesn't drop the associated unique index that every primary key has.
So when you drop a primary key you have to drop the unique index of that primary key, that amazingly has the same name as the primary key had.
So for dropping a MY_TABLE_PK you must do:
ALTER TABLE MY_TABLE DROP PRIMARY KEY DROP INDEX;
so you ensure that the index is dropped as well.
"from pl/sql I right click on the table"
The problem with IDEs is that they make us feel very productive, because we can do things with just a click instead of writing some code. This is a problem because when something unusual happens the IDE is no good for investigation and we lack the understanding of the underlying structure of the database which we need to help ourselves.
If you want to learn the Oracle database the worst thing you can do is download SQL Developer or PLSQL Developer or TOAD. They're all fine tools but the only people who should use them are the people who don't need to use them.
the following worked for me with unique index:
ALTER INDEX UX_CHARGES UNUSABLE
/
DROP INDEX UX_CHARGES
/
see: https://docs.oracle.com/cd/E18283_01/server.112/e17120/indexes004.htm#insertedID3

Oracle drop column and unused column

I have one table named test which has 3 columns:
Name
id
address
After some time I know one column is not in use. I want to drop one column, let's say id .
Oracle has one feature to identify a column as unused. What is differenc between drop column vs set unused column?
When you drop a column it moves into recycle bin while when you mark a column unused it is like logically dropping it but physically preserving it.
Sometimes marking a column as unused and then using the alter table name drop unused column statement is useful because it allows the DBA to take away column access quickly and immediately. Later on, during a routine database maintenance weekend or after business hours, you can then remove the column with the alter table name drop unused column to reclaim the space.
On the other hand, marking the column unused won't free up any space and when there is an need to free up space and remove the columns that are not needed you would be better off dropping it.
It's a matter of convenience, actually...
see here
setting to "unused" is just like dropping, but will allow you to defer the actual physical deletion to a later date.
This is a help to DBA's maintenance window not for your use in general. For developer it means DROP column. that's it, no recovery later point. instead if you are in 12 c then use INVISIBLE option.

Oracle 10g - An invisible column?

Is it possible to 'hide' a column in an Oracle 10g database, or prevent data from being inserted altogether? We'd prefer to have existing INSERT statements still function, but have the information NOT insert for a particular column. Also, column masking or any type of encryption is not preferred.
Not sure if it's possible, but thanks in advance.
If all you need to do is stop data from being inserted, you could create a BEFORE INSERT FOR EACH ROW trigger that wipes out any value inserted into the column before the row is saved.
There are various other things you can do with security (also views) to prevent inserts/selects from particular users in particular circumstances, but these will probably not let existing inserts continue to work.
With Oracle feature virtual private database (VPD) you can define which users can change and which users can select a column. Virtual private database is also called fine-grained access control (FGAC).
I know how to hide the column.
You use the
SET UNUSED
option to mark one or more columns as unused.
You use the DROP
UNUSED COLUMNS
option to remove the columns that are marked as unused.
ALTER TABLE emp
SET UNUSED (last_name);
and
ALTER TABLE emp
DROP UNUSED COLUMNS;
Rename original table, create view with original table name but only selecting the columns you want to show.
Recompile code referring to existing table.
what about just setting your grants to each item you allow to update or insert
grant select on emp to scott;
grant update (column1, column2), insert (column1) on emp to scott

Resources