quinta-feira, 26 de novembro de 2009

ORA-01658: Unable to create INITIAL extent for segment in tablespace

You are trying to create a new object, but the initial extent does not fit into the tablespace specified.

There is not enough space left inside the tablespace either due to the datafiles being full, autoextend which is not set at datafile level or due to a disk which's full.

You'll have to check the size of the datafiles attached to the tablespace and check whether they can autoextend or not..
Alternatively you can specify a smaller size for the initial extent.


1.

2.

3.

select file_name, bytes, autoextensible, maxbytes
from dba_data_files
where tablespace_name='TABLESPACE_NAME'



Either add more datafiles to the tablespace, set the autoextensible flag or enlarge the datafile(s).

To add more space to a file issue following command:


1.

alter database datafile 'C:\ORACLE\ORADATA\TOOLS01.DBF' resize 1000m;


To turn on the autoextend feature on a datafile use following command:

1.

2.

alter database datafile 'C:\ORACLE\ORADATA\TOOLS01.DBF' autoextend on next 100m maxsize 2000m;


To add a new datafile to the tablespace use following command:


1.

2.

alter tablespace TOOLS add datafile 'C:\ORACLE\ORADATA\TOOLS02.DBF' autoextend on next 100m maxsize 2000m;











quarta-feira, 25 de novembro de 2009

Apagando Tablespace


1.
2.
3.

DROP TABLESPACE SYNCHRO_DAD
INCLUDING CONTENTS AND DATAFILES
CASCADE CONSTRAINTS;


Permissões necessárias



1.
2.
3.
-- Grant role privileges
grant connect to SYNCHRO with admin option;
grant dba to SYNCHRO with admin option;
grant resource to SYNCHRO with admin option;


1.
2.
3.
4.
5.
6.
7.
-- Grant system privileges
grant create procedure to SYNCHRO with admin option;
grant create sequence to SYNCHRO with admin option;
grant create synonym to SYNCHRO with admin option;
grant create table to SYNCHRO with admin option;
grant create trigger to SYNCHRO with admin option;
grant create view to SYNCHRO with admin option;
grant unlimited tablespace to SYNCHRO with admin option;

Problema com OO4O

Problema com Oracle Objects for Ole.

Ao executar o aplicativo ocorreu um erro onde a mensagem dizia mais ou menos:
Impossível Inicializar o Oracle Objects for Olé, verifique a instalação...

O problema foi resolvido quando o objeto oip10.dll foi registrado

1.
regsvr32 <caminho\> oip10.dll

Dropando objetos de um usuário

Normally, it is simplest to drop and add the user. This is the preferred method if you have system or sysdba access to the database.

If you don't have system level access, and want to scrub your schema, the following sql will produce a series of drop statments, which can then be executed.

 
1.
2.
3.
select 'drop '||object_type||' '|| object_name||  
DECODE(OBJECT_TYPE,'TABLE',' CASCADE CONSTRAINTS;',';')
from user_objects
 


Then, I normally purge the recycle bin to really clean things up. To be honest, I don't see a lot of use for oracle's recycle bin, and wish i could disable it... but anyway:


1.
purge recyclebin;
 


This will produce a list of drop statements. Not all of them will execute - if you drop with cascade, dropping the PK_* indices will fail. But in the end, you will have a pretty clean schema.
Confirm with:

1.
select * from user_objects


terça-feira, 24 de novembro de 2009

External Tables

A partir do Oracle 9i foi criado o conceito de EXTERNAL TABLES, ou seja, você cria uma tabela baseado num arquivo texto no sistema operacional e pode fazer consultas SQL nessa tabela (ou seja, diretamente no arquivo texto como se fosse uma tabela)
Agora a partir do oracle 10g é possível também criar um arquivo texto baseado numa tabela do banco usando o novo driver de Data Pump existente.


A possibilidade de gravar um arquivo texto se limita ao CREATE TABLE AS SELECT apenas. Não é permitido fazer UPDATE, DELETE ou INSERT numa external table.

Vamos a um exemplo:

01.
02.
03.
04.
05.
06.
07.
08.
09.
10.
11.
12.
13.
14.
15.
16.
17.
18.
SQL> CREATE DIRECTORY external_directory AS
'c:\oracle\admin\betatwo\directory';

SQL> GRANT READ, WRITE ON DIRECTORY external_directory
TO scott;
SQL> CREATE TABLE emp_history_ext
(ename, retire_date,
last_retirement_pay_date, pay_amount)
ORGANIZATION EXTERNAL
( TYPE oracle_datapump
  DEFAULT DIRECTORY external_directory
LOCATION ('emp_history_01.exp', 'emp_history_02.exp') )
parallel
AS
SELECT a.ename, b.retire_date,
b.last_retirement_pay_date, b.pay_amount
FROM emp a, retire_pay b
WHERE a.empno=b.empno;




















Primeiramente, criamos um DIRECTORY e damos permissão de leitura e escrita. Isso apenas é requerido caso o usuário que criou o diretório não é o usuário que vai criar a external table. Após isso, criamos uma external table que será populada com o SELECT informado!


Após a criação, basta fazer a consulta diretamente no arquivo texto:

01.
02.
03.
04.
05.
SQL> SELECT * FROM emp_history_ext;

ENAME      RETIRE_DA LAST_RETI PAY_AMOUNT
---------- --------- --------- ----------
SMITH      25-NOV-03 15-DEC-03       1000









A criação dessa external table resulta na criação de um arquivo texto no sistema operacional com os dados informados no SELECT. Também é gerado um arquivo de LOG no mesmo diretório:
01.
02.
03.
04.
05.
06.
C:\> dir c:\oracle\admin\betatwo\directory
 Volume in drive C has no label.
 Volume Serial Number is 3CE9-7321
 Directory of c:\oracle\admin\betatwo\directory
12/15/2003 07:52  PM      90    EMP_HISTORY_EXT_2528_1760.log
12/15/2003 07:52  PM   1,808    emp_history.exp











Outras informações:
Quando você dropa uma external table os arquivos textos continuam no sistema operacional! Isso pode ser um problema pois caso você execute novamente o comando pra recriar a external table, os arquivos já existirão e ocasionará um ERRO. Você deve excluir esses arquivos manualmente