ALTER TABLE MYTABLE TRUNCATE PARTITION P_2017_01;
For more details, check the documentation
Minimalistic Oracle contains a collection of practical examples from my encounters with Oracle technologies. When relevant, I also write about other technologies, like Linux or PostgreSQL. Many of the posts starts with "how to" since they derive directly from my own personal experience. My goal is to provide simple examples, so that they can be easily adapted to other situations.
Move method (cons_use_pk or cons_use_rowid): cons_use_rowid begin * ERROR at line 1: ORA-12008: error in materialized view refresh path ORA-01858: a non-numeric character was found where a numeric was expected ORA-06512: at "SYS.DBMS_REDEFINITION", line 75 ORA-06512: at "SYS.DBMS_REDEFINITION", line 3459 ORA-06512: at line 2
CREATE TABLE SCOTT.MYTABLE ( SEQ_NUM NUMBER Generated as Identity ( START WITH 9984 MAXVALUE 9999999999999999999999999999 MINVALUE 1 NOCYCLE CACHE 20 NOORDER NOKEEP) CONSTRAINT SYS_C0073650 NOT NULL, ENTRY_ID VARCHAR2(50 BYTE) NULL, ENAME VARCHAR2(100 BYTE) NULL, CREATED_DT TIMESTAMP(6) NULL, REVISION# INTEGER NULL, ACTIVE_YEAR INTEGER NULL, PERIOD VARCHAR2(10 BYTE) NULL, CONDITION VARCHAR2(50 BYTE) NULL, FN_ID VARCHAR2(11 BYTE) NULL ) TABLESPACE USERS;
CREATE TABLE SCOTT.MYTABLE_INTERIM ( SEQ_NUM NUMBER, ENTRY_ID VARCHAR2(50 BYTE), ENAME VARCHAR2(100 BYTE), CREATED_DT TIMESTAMP(6), REVISION# INTEGER, ACTIVE_YEAR INTEGER, PERIOD DATE, CONDITION VARCHAR2(50 BYTE), FN_ID VARCHAR2(11 BYTE) ) PARTITION BY RANGE (PERIOD) INTERVAL( NUMTOYMINTERVAL(1,'MONTH')) ( PARTITION P_INIT VALUES LESS THAN (TO_DATE('2015-01', 'YYYY-MM')) ) TABLESPACE USERS ;
select seq_num,TO_DATE(PERIOD,'YYYY-MM') from Scott.mytable fetch first 5 rows only;which resulted in
ORA-01858: a non-numeric character was found where a numeric was expected
select seq_num,to_date(to_char(TO_DATE(PERIOD),'YYYY-MM'),'YYYY-MM') from Scott.mytable fetch first 5 rows only;
begin DBMS_REDEFINITION.start_redef_table(uname=>'EVENT', orig_table=>'MYTABLE', int_table=>'MYTABLE_INTERIM', col_mapping =>'SEQ_NUM SEQ_NUM,ENTRY_ID ENTRY_ID,ENAME ENAME,CREATED_DT CREATED_DT,REVISION# REVISION#,ACTIVE_YEAR ACTIVE_YEAR,to_date(to_char(TO_DATE(PERIOD),''YYYY-MM''),''YYYY-MM'') PERIOD,CONDITION CONDITION,FN_ID FN_ID', options_flag=>dbms_redefinition.cons_use_pk); end; /
CREATE OR REPLACE TRIGGER logon_optimizer after logon on database begin if user in ('SCOTT','JACK','BOB') then execute immediate 'alter session set NLS_LANGUAGE="GERMAN"'; execute immediate 'alter session set "_optimizer_unnest_disjunctive_subq"= FALSE'; end if; end; /
Connect scott/tiger set lines 200 col parameter format a30 col value format a40 select * from nls_session_parameters; PARAMETER VALUE ------------------------------ ----------- NLS_LANGUAGE GERMAN NLS_TERRITORY NORWAY
select * from xxx * ERROR at line 1: ORA-00942: Tabelle oder View nicht vorhanden
SELECT 'create bigfile tablespace ' ||T.NAME || ' datafile ''/u02/oradata/proddb01' || LOWER(T.NAME) || '.dbf'' size 256M autoextend on next 128M maxsize unlimited extent management local segment space management auto encryption using ''' || E.ENCRYPTIONALG || ''' default storage(encrypt);' FROM V$TABLESPACE T, V$ENCRYPTED_TABLESPACES E WHERE T.TS# = E.TS# UNION SELECT 'create bigfile tablespace ' ||T.NAME || ' datafile ''/u02/oradata/proddb01' || LOWER(F.NAME) || ''' size 256M autoextend on next 128M maxsize unlimited extent management local segment space management auto;' FROM V$TABLESPACE T, V$DATAFILE F WHERE T.TS# = F.TS# AND T.NAME NOT IN ('SYSTEM','SYSAUX','UNDOTBS1','USERS') AND F.TS# NOT IN (SELECT TS# FROM V$ENCRYPTED_TABLESPACES);
SELECT t.name, NVL(e.encryptionalg, 'Not encrypted') algorithm FROM v$tablespace t LEFT OUTER JOIN v$encrypted_tablespaces e ON( t.ts# = e.ts# ) WHERE t.name not in ('SYSTEM','SYSAUX','UNDOTBS1','USERS');
SQL> select dbms_Stats.get_prefs('INCREMENTAL','SCOTT','EMP') "paramvalue" from dual; paramvalue -------------------- FALSE
SQL> exec dbms_stats.set_table_prefs(ownname=>'SCOTT',tabname=>'EMP',pname=>'INCREMENTAL',pvalue=>'TRUE');
SQL> select dbms_Stats.get_prefs('INCREMENTAL','SCOTT','EMP') "paramvalue" from dual; paramvalue -------------------- TRUE
SELECT OWNER,NAME,TYPE,NLS_LENGTH_SEMANTICS FROM DBA_PLSQL_OBJECT_SETTINGS WHERE OWNER IN ('USER1','USER2');
SELECT POS.OWNER,POS.NAME,POS.TYPE,POS.NLS_LENGTH_SEMANTICS, O.LAST_DDL_TIME,O.CREATED, O.STATUS FROM DBA_PLSQL_OBJECT_SETTINGS POS JOIN DBA_OBJECTS O ON (POS.NAME = O.OBJECT_NAME) AND POS.OWNER = 'SCOTT' ORDER BY NAME;
Select distinct mrc_name from schema_version_registry; Select distinct mrc_name from schema_version_registry * ERROR on line 1: ORA-01775: Looping chain of synonyms
SQL> SELECT owner, SYNONYM_NAME,TABLE_OWNER,TABLE_NAME from DBA_SYNONYMS where table_name='SCHEMA_VERSION_REGISTRY' OWNER SYNONYM_NAME TABLE_OWNER TABLE_NAME -------------------- -------------------------- -------------------- ---------------------------------------- PUBLIC SCHEMA_VERSION_REGISTRY SYSTEM SCHEMA_VERSION_REGISTRY
SQL> drop public synonym SCHEMA_VERSION_REGISTRY; Synonym dropped.