Storage Clause is getting skipped for LOB segment in Oracle 12c - oracle

Hi have created table which consist clob datatype :
CREATE TABLE MQ_GET_CLOB
(
SEQ_NO NUMBER NOT NULL,
MESSAGE_TEXT CLOB,
MESSAGE_LENGTH NUMBER NOT NULL,
STATUS VARCHAR2(15 BYTE)
)
TABLESPACE DATA_L1
LOB (MESSAGE_TEXT) STORE AS
(TABLESPACE DATA_L1
STORAGE (INITIAL 6144)
CHUNK 4000
NOCACHE LOGGING);
After creating table when I looked into Metadata , I found that LOB storage clause is getting skipped.
CREATE TABLE MQ_GET_CLOB
(
SEQ_NO NUMBER NOT NULL,
MESSAGE_TEXT CLOB,
MESSAGE_LENGTH NUMBER NOT NULL,
STATUS VARCHAR2(15 BYTE)
)
TABLESPACE DATA_L1
PCTUSED 40
PCTFREE 10
INITRANS 1
MAXTRANS 255
STORAGE (
PCTINCREASE 0
BUFFER_POOL DEFAULT
)
LOGGING
NOCOMPRESS
NOCACHE
NOPARALLEL
MONITORING;
Which leads to
ORA-01658: unable to create INITIAL extent for segment in tablespace
SYSAUX
I am not sure why table is using SYSAUX tablespace.
Whether anyone have faced same issue before ? This there something I have missed ?
Thanks.

Related

Indexing a ranged partition Oracle

I want to index a partition of my table, I'm not sure how to do it and I don't have access to my database atm.
The database is Oracle 11.
Would my code work?
CREATE TABLE MARKET.PARTTABLE
(
EXTRACT_DATE DATE NOT NULL,
LOAD_ID NUMBER(10) NOT NULL,
LOAD_DATE DATE NOT NULL,
NAME VARCHAR2(200 BYTE) NOT NULL
)
PARTITION BY RANGE (EXTRACT_DATE)
(
PARTITION PDEFAULT VALUES LESS THAN (MAXVALUE)
NOLOGGING
NOCOMPRESS
TABLESPACE MARKET_DAT
PCTFREE 0
INITRANS 1
MAXTRANS 255
STORAGE (
MAXSIZE UNLIMITED
BUFFER_POOL DEFAULT
FLASH_CACHE DEFAULT
CELL_FLASH_CACHE DEFAULT
)
CREATE INDEX NAME_PARTTABLE ON PARTTABLE(NAME)
)
NOCACHE
NOPARALLEL
MONITORING;
When I run this I get the following error:
ORA-14020: this physical attribute may not be specified for a table
partition
This indicates that I have a formatting issue, but I actually don't find any helpful documentation to index partition (or maybe I'm just too stupid to understand them).
EDIT:
I tried this:
CREATE TABLE MARKET.PARTTABLE
(
EXTRACT_DATE DATE NOT NULL,
LOAD_ID NUMBER(10) NOT NULL,
LOAD_DATE DATE NOT NULL,
NAME VARCHAR2(200 BYTE) NOT NULL
)
PARTITION BY RANGE (EXTRACT_DATE)
(
PARTITION PDEFAULT VALUES LESS THAN (MAXVALUE)
NOLOGGING
NOCOMPRESS
TABLESPACE MARKET_DAT
PCTFREE 0
INITRANS 1
MAXTRANS 255
STORAGE (
MAXSIZE UNLIMITED
BUFFER_POOL DEFAULT
FLASH_CACHE DEFAULT
CELL_FLASH_CACHE DEFAULT
)
)
NOCACHE
NOPARALLEL
MONITORING;
CREATE INDEX NAME_PARTTABLE ON PARTTABLE(NAME)
It worked, but I'm not sure if the index is now on the partition or if it is on the whole table. Could someone help me out?
Your second statement did not in fact create an INDEX on the partition.
Partitioned indexes should either be defined as LOCAL or GLOBAL.
Since what you are trying to create is a Non-Prefixed index( The leftmost column(s) of the index is not the partition key), better option is to go with a LOCAL INDEX
CREATE INDEX NAME_PARTTABLE ON PARTTABLE(NAME) LOCAL;
..but I'm not sure if the index is now on the partition or if
it is on the whole table.
You may query the data dictionary view ALL_PART_INDEXES or USER_PART_INDEXES to check for your index name. Normal non-partitioned indexes aren't shown from these views.
select * from USER_PART_INDEXES where index_name='NAME_PARTTABLE';
Partitioned Tables And Indexes

Conflict creating table with Index and Primary Key

I'm a veteran SQL Server dev, recently moved to a project requiring Oracle and I'm confused by the error [ORA-02260: table can have only one primary key] I'm getting on Oracle 11.
I'm attempting to create a reference table, with an index and a primary key.
However, getting errors that my column Partner_ID is already declared. I know I'm missing something simple, but the docs and other sources I've viewed here have not given me a clue. Please help me understand what I'm doing wrong.
Thank you
ALTER TABLE REF_PARTNER
DROP PRIMARY KEY CASCADE;
DROP TABLE REF_PARTNER CASCADE CONSTRAINTS;
CREATE TABLE REF_PARTNER
(
PARTNER_ID NUMBER(10) PRIMARY KEY NOT NULL,
GLOBAL_APPID VARCHAR2(256 BYTE) NOT NULL,
FRIENDLY_NAME VARCHAR2(256 BYTE) NOT NULL,
CREATE_DTS DATE,
MODIFIED_DTS DATE,
LAST_MODIFIED_USER VARCHAR2(40 BYTE)
)
TABLESPACE DATA_1
PCTUSED 0
PCTFREE 5
INITRANS 1
MAXTRANS 255
STORAGE (
INITIAL 1M
NEXT 1M
MAXSIZE UNLIMITED
MINEXTENTS 1
MAXEXTENTS UNLIMITED
PCTINCREASE 0
BUFFER_POOL DEFAULT
)
LOGGING
NOCOMPRESS
NOCACHE
MONITORING;
BEGIN
EXECUTE IMMEDIATE 'DROP SEQUENCE PARTNER_SEQ';
EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE SEQUENCE PARTNER_SEQ START WITH 1 INCREMENT BY 1 MINVALUE 1 NOMAXVALUE NOCYCLE CACHE 200;
--CREATE UNIQUE INDEX REF_PARTNER_IDX ON REF_PARTNER
--(PARTNER_ID)
--LOGGING
--TABLESPACE INDEX_1
--PCTFREE 10
--INITRANS 2
--MAXTRANS 255
--STORAGE (
-- INITIAL 64K
-- NEXT 64K
-- MAXSIZE UNLIMITED
-- MINEXTENTS 1
-- MAXEXTENTS UNLIMITED
-- PCTINCREASE 0
-- BUFFER_POOL DEFAULT
-- );
--ALTER TABLE REF_PARTNER ADD (
-- CONSTRAINT REF_PARTNER_PK
-- PRIMARY KEY
-- (PARTNER_ID)
-- USING INDEX REF_PARTNER_PK
-- ENABLE VALIDATE);
A assume the error you get is
ORA-01408: such column list already indexed.
This is because you create the table with partner_id as the primary key. This automatically creates a unique index on partner_id.
There is no need to create a unique key on partner_id after you declared it to be the primary key.

Migrating table with composite partition (Hash/Range) to different tablespace

Trying to move table tab from tablespace oldTs to newTs. There is a composite partition (Range/Hash) on tab. Hence, a direct "Alter-Table-Move-Tablespace" query won't work, need to migrate partition by partition. Below is the SQL of tab:
CREATE TABLE tab
(
col_1 char(6),
col_2 varchar2(4),
col_3 varchar2(5)
)
TABLESPACE oldTs PARTITION BY RANGE
(
"col_1"
)
SUBPARTITION BY HASH
(
"col_2"
)
SUBPARTITIONS 1
(
PARTITION "P201102" VALUES LESS THAN ('201103') PCTFREE 10 PCTUSED 0 INITRANS 1 MAXTRANS 255 STORAGE( BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "oldTs" NOCOMPRESS NOLOGGING ( SUBPARTITION "SYS_SUBP5223" TABLESPACE "oldTs" NOCOMPRESS , SUBPARTITION "SYS_SUBP5224" TABLESPACE "oldTs" NOCOMPRESS ),
PARTITION "P201103" VALUES LESS THAN ('201104') PCTFREE 10 PCTUSED 0 INITRANS 1 MAXTRANS 255 STORAGE( BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "oldTs" NOCOMPRESS NOLOGGING ( SUBPARTITION "SYS_SUBP5225" TABLESPACE "oldTs" NOCOMPRESS , SUBPARTITION "SYS_SUBP5226" TABLESPACE "oldTs" NOCOMPRESS )
);
There are several such monthly partitions, created a procedure which acquires all the partition names (such as P201102, P2001103) and generates an alter query for moving partitions.
For ex,
ALTER TABLE tab_name MOVE PARTITION P201102 TABLESPACE newTbs;
But, the query gives below error:
SQL Error: ORA-14257: cannot move partition other than a Range, List,
System, or Hash partition
Also, if you notice in P201102/P201103, each has two sub-partitions (SYS_SUBP5225 & SYS_SUBP5226 for P201103).
Require the correct syntax of alter statement for migrating partitions for the above scenario.
You can move subpartitions but not partitions which contains subpartitions. (Shortly, you can move segments.)
ALTER TABLE tab_name MOVE SUBPARTITION SYS_SUBP5225 TABLESPACE newTbs;
UPDATE: If you want to change where the new partitions are created then run the bellow ddl, which change an atribute of the table - where new partitions are created.
alter table tab_name modify default attributes tablespace newTbs;
UPDATE2: If you want to change where subpartitions are created for a partition, then run below which change an attribute of the partition - where new subpartitions are created:
alter table tab_name modify default attributes for partition P201102 tablespace newTbs;

Oracle SQL Developer 4.0 - How to remove double quotes in scripts

I'm running Oracle SQL Developer 4.0. When I script out a table, the owner, table name, column name, constraint name and etc are enclused with double quotes. I looked through Tools -> Preferences and was not able to find any option to turn it off. Does anyone know how to script a table without these quotes?
Thank you
I don't think you can do it using those methods. They are both using dbms_metata.get_ddl under the hood, it appears, and that doesn't have an option to not quote identifiers. Looks like export uses that package too; data modeller has an option to quote identifiers but not sure if that's useful to you.
You can get rid of them by querying from a worksheet if you want though, as long as the DDL is less than 32K. With default settings:
create table t42 (id number, str varchar2(10) default 'ABC',
constraint t42_pk primary key (id));
create index i42 on t42(str);
set long 1000
select dbms_metadata.get_ddl('TABLE', 'T42', user) from dual;
select dbms_metadata.get_dependent_ddl('INDEX', 'T42', user) from dual;
CREATE TABLE "STACKOVERFLOW"."T42"
( "ID" NUMBER,
"STR" VARCHAR2(10) DEFAULT 'ABC',
CONSTRAINT "T42_PK" PRIMARY KEY ("ID")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
TABLESPACE "USERS" ENABLE
) SEGMENT CREATION DEFERRED
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
TABLESPACE "USERS"
CREATE UNIQUE INDEX "STACKOVERFLOW"."T42_PK" ON "STACKOVERFLOW"."T42" ("ID")
PCTFREE 10 INITRANS 2 MAXTRANS 255
TABLESPACE "USERS"
CREATE INDEX "STACKOVERFLOW"."I42" ON "STACKOVERFLOW"."T42" ("STR")
PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
TABLESPACE "USERS"
With a little manipulation:
begin
dbms_metadata.set_transform_param(dbms_metadata.SESSION_TRANSFORM,
'PRETTY', false);
dbms_metadata.set_transform_param(dbms_metadata.SESSION_TRANSFORM,
'SQLTERMINATOR', true);
dbms_metadata.set_transform_param(dbms_metadata.SESSION_TRANSFORM,
'CONSTRAINTS_AS_ALTER', true);
dbms_metadata.set_transform_param(dbms_metadata.SESSION_TRANSFORM,
'SEGMENT_ATTRIBUTES', false);
end;
/
select replace(dbms_metadata.get_ddl('TABLE', 'T42', user), '"', null)
from dual;
select replace(dbms_metadata.get_dependent_ddl('INDEX', 'T42', user), '"', null)
from dual;
CREATE TABLE STACKOVERFLOW.T42 (ID NUMBER, STR VARCHAR2(10) DEFAULT 'ABC') ;
ALTER TABLE STACKOVERFLOW.T42 ADD CONSTRAINT T42_PK PRIMARY KEY (ID) ENABLE;
CREATE UNIQUE INDEX STACKOVERFLOW.T42_PK ON STACKOVERFLOW.T42 (ID) ;
CREATE INDEX STACKOVERFLOW.I42 ON STACKOVERFLOW.T42 (STR) ;

How to import Oracle (C)LOB into another tablespace

I'm importing a database dump from one Oracle 10g installation into another. The source has a layout with several tablespaces. The target has one default tablespace for the user I'm importing the dump into.
Everything works fine, for ordinary tables. The tables are relocated from their original tablespace to the user's default. The problem I'm facing, several tables contain CLOBs with explicit storage directives. That is, they name their storage tablespace. The imp command seems to be unable to relocate these CLOBs to the user's default tablespace.
Is there any hidden command line option for the imp command to relocate the CLOB storage to the user's default tablespace or even one named tablespace?
The error message ORACLE 959 looks like this:
IMP-00017: Nachfolgende Anweisung war wegen Oracle-Fehler 959 erfolglos:
"CREATE TABLE "IF_MDE_DATA_OUT" ("OID" NUMBER(10, 0) NOT NULL ENABLE, "CLIEN"
"T_OID" NUMBER(10, 0) NOT NULL ENABLE, "TS_CREATE" TIMESTAMP (6) NOT NULL EN"
"ABLE, "TS_UPDATE" TIMESTAMP (6) NOT NULL ENABLE, "OP_CREATE" VARCHAR2(30) N"
"OT NULL ENABLE, "OP_UPDATE" VARCHAR2(30) NOT NULL ENABLE, "IDENTIFIER" VARC"
"HAR2(50), "TRANSFERTYPE" VARCHAR2(20) NOT NULL ENABLE, "STORE" NUMBER(10, 0"
"), "DATUM" DATE, "STATE" NUMBER(3, 0) NOT NULL ENABLE, "DATA_OLD" LONG RAW,"
" "SUPPLIER" NUMBER(10, 0), "BUYER" NUMBER(10, 0), "GOODS_OUT_IDS" VARCHAR2("
"4000), "CUSTOM_FIELD" VARCHAR2(50), "DATA_ARCHIVE" BLOB, "DATA" BLOB) PCTF"
"REE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1"
" FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "DATA32M" LOGGING NOCOMP"
"RESS LOB ("DATA_ARCHIVE") STORE AS (TABLESPACE "DATA32M" ENABLE STORAGE IN"
" ROW CHUNK 8192 PCTVERSION 10 NOCACHE LOGGING STORAGE(INITIAL 65536 FREELI"
"STS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)) LOB ("DATA") STORE AS (TABLE"
"SPACE "DATA32M" ENABLE STORAGE IN ROW CHUNK 8192 PCTVERSION 10 NOCACHE LOGG"
"ING STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAUL"
"T))"
IMP-00003: ORACLE-Fehler 959 aufgetreten
ORA-00959: Tablespace 'DATA32M' nicht vorhanden
You could pre-create the table using the storage parameters you need, and set the import to ignore errors.
Like Karl, I recommend Datadump but use REMAP_TABLESPACE
If you are using Data Pump Dumps, you could try the remap_schema option to correct the tablespace.

Resources