Delete tables from table based on table size - oracle

I use this table to store messages. I would like to delete rows by date if the size of the table is bigger than 10 MB. Is this possible in Oracle?
CREATE TABLE EVENTS(
EVENTID INTEGER NOT NULL,
SOURCE VARCHAR2(50 ),
TYPE VARCHAR2(50 ),
EVENT_DATE DATE,
DESCRIPTION VARCHAR2(100 )
)
/

Related

Oracle ORA-04063: table "TABLE" has errors

I Create a table with UDT type as a column , after some time i needed one more column to add the type, i altered the type using
alter type type_cust_instatus add attribute (sub_status_to varchar2(20)) invalidate
alter type type_cust_instatus compile
After that the table becomes invalid and tried to make the column unused and dropped the the type also and recreaded once again as per before modification.
now in the table defination there is no type fro the column and showing as blank
how to delete the column or recompile
CREATE TABLE KAMSIT.CUSTOMER_TRANSACTION_DATA
(
MSISDN VARCHAR2(13 BYTE),
IMSI VARCHAR2(15 BYTE),
CONNECTION_TYPE NUMBER,
MSTYPE VARCHAR2(6 BYTE),
SUBSCR_NO VARCHAR2(10 BYTE),
ACCOUNT_NO VARCHAR2(10 BYTE),
ALUIN_ACTIVE_DATE DATE,
FIRST_CALL_MADE_TIME DATE,
ACTIVE_DATE DATE,
INACTIVE_DATE DATE,
BILLING_IMSI VARCHAR2(15 BYTE),
CURRENT_STATUS VARCHAR2(1 BYTE) DEFAULT 'C',
ALUIN_IMSI VARCHAR2(15 BYTE),
ALUIN_SUB_STATUS VARCHAR2(50 BYTE),
INSERT_DATE DATE DEFAULT sysdate,
TRANSACTION_TYPE KAMSIT.CUSTOMER_TRANSACTION_TYPE,
TRANSACTION_IMSI KAMSIT.CUST_IMSI_CHANGE,
ALUIN_STATUS VARCHAR2(1 BYTE) DEFAULT 'C',
IMEI VARCHAR2(20 BYTE),
TRANSACTION_INSTATUS
)
NESTED TABLE TRANSACTION_TYPE STORE AS TBL_CUSTOMER_TRANSACTIONS,
NESTED TABLE TRANSACTION_IMSI STORE AS TBL_TRANSACTION_IMSI
how to drop the column or set unused or rebuild the table

Not enough values while trying to insert data from table 1 to table 2

I want to add one column in table but I get error that table needs to be empty.
I create backup table using following command
CREATE TABLE attachments_backup
AS
SELECT * FROM attachments
When I create a backup table I insert data from attachments to attachments_backup
INSERT INTO attachments SELECT * FROM attachments_backup
Then I delete data from table 1 (attachments)
DELETE FROM attachments
I add column which I need to add in table attachment
ALTER TABLE attachments
ADD ChildrenDirectory VARCHAR(50) DEFAULT NULL
Right here problem occure. Since I add new column right now I can insert data from table 2 (attachment_backup) to table 1 (attachments)
I try something like this
INSERT INTO attachments VALUES (AtaId,Belongs_To,ClientId,File_path,Id,Image_Path,Lock_,Name,Project_Id,Type,Category) SELECT * FROM attachments_backup
But this solution doesn't work since I get error message "Not enought values"
SQL Error: ORA-00947: not enough values
00947. 00000 - "not enough values"
Does anyone now how to solve this kind of issue since I have no more idea ?
Attachments table
ATAID NUMBER(10,0)
BELONGS_TO NUMBER(10,0)
CLIENTID NUMBER(10,0)
FILE_PATH VARCHAR2(255 CHAR)
ID NUMBER(10,0)
IMAGE_PATH VARCHAR2(255 CHAR)
ISDELETED NUMBER(10,0)
LOCK_ CHAR(1 CHAR)
NAME VARCHAR2(255 CHAR)
PROJECT_ID NUMBER(10,0)
TYPE VARCHAR2(4000 CHAR)
CATEGORY VARCHAR2(20 BYTE)
CHILDRENDIRECTORY VARCHAR2(50 BYTE)
Attachments_backup
ATAID NUMBER(10,0)
BELONGS_TO NUMBER(10,0)
CLIENTID NUMBER(10,0)
FILE_PATH VARCHAR2(255 CHAR)
ID NUMBER(10,0)
IMAGE_PATH VARCHAR2(255 CHAR)
ISDELETED NUMBER(10,0)
LOCK_ CHAR(1 CHAR)
NAME VARCHAR2(255 CHAR)
PROJECT_ID NUMBER(10,0)
TYPE VARCHAR2(4000 CHAR)
CATEGORY VARCHAR2(20 BYTE)
Basically, you're doing it wrong.
Except for quick and dirty selects, don't use asterisk *. Something like this:
insert into a select * from b
just waits for error to happen. Always name all columns involved. Yes, it requires some more typing, but is safe. So:
insert into a (empno, ename, job, sal)
select empno, ename, job, sal
from b;
Welcome,
You can add new column to an existing table using an alter command, even if the table is not empty
To insert from table "A" to table "B" or vice-versa, you need to have exact number of columns to perform "select * " type insert

Oracle Trigger to loop and update field based on sysdate

I would like to make a trigger that can update a field (‘STATUS’) to Inactive when a vaccine is past its expiration date (‘EXPIRATION_DATE’).
Here is the current table structure:
**CREATE TABLE WAREHOUSE.VACCINE_INVENTORY (
VACCINE VARCHAR2(200 BYTE) NOT NULL,
RECEIPT_DATE DATE NOT NULL,
CONTAINER_SIZE VARCHAR2(200 BYTE),
QUANTITY NUMBER(6, 0),
REQUISITION NUMBER(6, 0),
FISCAL_YEAR NUMBER(4, 0),
RECEIVED_BY VARCHAR2(50 BYTE),
EXPIRATION_DATE DATE,
LOT_NUMBER VARCHAR2(30 BYTE) NOT NULL,
VENDOR VARCHAR2(200 BYTE),
STATUS VARCHAR2(10 BYTE),
CATALOG_NUMBER NUMBER(5, 0),
CONSTRAINT PK_VACC PRIMARY KEY (VACCINE, RECEIPT_DATE, LOT_NUMBER) USING INDEX TABLESPACE WAREHOUSE STORAGE**
So the idea is that if SYSDATE > EXPIRATION_DATE the expiration date should be changed from Active to Inactive.
I would assume I would need to create a Loop so that when the trigger is run, it will loop through all the records in the table and set each expired vaccine to Inactive.
I would greatly appreciate any help…
Thanks,
Matthew
Create an additional view to provide fields that depend on table columns and sysdate, e.g.
CREATE TABLE VACCINE_INVENTORY(VACCINE VARCHAR2(200 BYTE) NOT NULL,
-- ---
EXPIRATION_DATE DATE NOT NULL
-- ...
);
CREATE view VACCINE_INVENTORY_VW AS
select v.*,
case
when v.expiration_date < sysdate then
'I'
else
'A'
end as status
from VACCINE_INVENTORY v;

Tablespaces with interval partitioning

Is there any way to specify different tablespaces for each partition if I use interval partitioning?
My table is (it is just example, I have more columns in the table):
create table MY_TABLE
(
id NUMBER(20) not null,
type VARCHAR2(1 char) not null,
session_id NUMBER(12) not null,
date_of_beginning DATE not null,
account_number NUMBER not null
)
PCTFREE 1
PARTITION BY RANGE (date_of_beginning)
INTERVAL(NUMTOYMINTERVAL(1, ''MONTH''))
SUBPARTITION BY HASH(account_number) subpartitions 50
(
PARTITION p_1 VALUES LESS THAN (TO_DATE(''01.06.2015'', ''dd.mm.yyyy''))
)';
I want each partition to be stored in separate tablespase. Any ideas how can I achieve it? Maybe some trigger?
For other tables like this one, we have a job, which creates tablespace and partition in the beginning of the month. But this one creates partitions automatically because of intervals.

How do I create a partitioned table without initial partitions?

Say, I have the following DDL:
create table partition_test_table
(
id number(38,0) not null,
value varchar(255),
country_code varchar(2) not null,
creation_date date not null,
constraint pk_partition_test_table primary key (id)
)
partition by range ( creation_date )
subpartition by list ( country_code );
This doesn't work because it doesn't declare any initial partitions. How do I create a partitioned table without initial partitions? Is that even possible?
Thanks.

Resources