Wednesday, May 23, 2012

UTL_INADDR ORA-29257:host [ip or name] unknown

In Oracle there is UTL_INADDR package that is an API to access host name and ip address of server.
Usage

select UTL_INADDR.get_host_name('host_name') from dual;
select UTL_INADDR.get_address_name('ip_address') from dual;


SET serveroutput on
BEGIN
  DBMS_OUTPUT.PUT_LINE(UTL_INADDR.GET_HOST_NAME);  -- get local host name
  DBMS_OUTPUT.PUT_LINE(UTL_INADDR.GET_HOST_ADDRESS);  -- get local IP addr
END;
/


If host_name or ip_address is null, this function returns local host hostname or ip.
If hostname or IP can't be resolved, error ORA-29257:host [ip or name] unknown is returned.

Thursday, May 17, 2012

impdp ORA-39083 ORA-00959


At import time you can get these errors:

ORA-39083: Object type INDEX failed to create with error:
ORA-00959: tablespace 'IDX' does not exist

In this case use REMAP_TABLESPACE=IDX:[destination tablespace]
If you have multiple tablespaces, for each use
REMAP_TABLESPACE=[source tablespace]:[destination tablespace]

Example:

impdp user/passsword@sid directory=dir remap_schema=schema_source_schema:dest_schema remap_tablespace=tab1:tab remap_tablespace=tab2:tab dumpfile=file.dmp logfile=file.log

Monday, May 14, 2012

ORA-01756: quoted string not properly terminated

Obviously, the cause of this error is missing some quotes in writing statement:


oerr ora 1756
01756, 00000, "quoted string not properly terminated"
// *Cause:
// *Action:

example:

SQL> select dbms_stats.create_extended_stats(null,'tab,'(x,y)') from dual;
ERROR:
ORA-01756: quoted string not properly terminated

Cause: string tab is not terminated with quote
Action: put quote to avoid error

11g Extended statistics

To take advantages from statistics on group of columns, you can use extended statistics.


SQL> select count(*) from tab;

  COUNT(*)
----------
   1003241

SQL> select column_name, num_distinct, num_nulls, histogram from user_tab_col_statistics
  2  where table_name='TAB';

COLUMN_NAME                    NUM_DISTINCT  NUM_NULLS HISTOGRAM
------------------------------ ------------ ---------- ---------------
X                                         5          0 NONE
Y                                         5          0 NONE

SQL> select dbms_stats.create_extended_stats(null,'tab','(x,y)') from dual;

DBMS_STATS.CREATE_EXTENDED_STATS(NULL,'TAB','(X,Y)')
--------------------------------------------------------------------------------
SYS_STUYPW88OE302TFVBNC6$MMQXE

SQL> select column_name, num_distinct, num_nulls, histogram from user_tab_col_statistics
  2  where table_name='TAB';

COLUMN_NAME                    NUM_DISTINCT  NUM_NULLS HISTOGRAM
------------------------------ ------------ ---------- ---------------
X                                         5          0 NONE
Y                                         5          0 NONE


SQL> select * from user_stat_extensions;

TABLE_NAME                     EXTENSION_NAME
------------------------------ ------------------------------
EXTENSION
--------------------------------------------------------------------------------
CREATO DRO
------ ---
TAB                            SYS_STUYPW88OE302TFVBNC6$MMQXE
("X","Y")
USER   YES


SQL>  exec dbms_stats.gather_table_stats(null,'tab');

PL/SQL procedure successfully completed.

SQL>  select column_name, num_distinct, num_nulls, histogram from user_tab_col_statistics
  2  where table_name='TAB';

COLUMN_NAME                    NUM_DISTINCT  NUM_NULLS HISTOGRAM
------------------------------ ------------ ---------- ---------------
SYS_STUYPW88OE302TFVBNC6$MMQXE            5          0 NONE
X                                         5          0 NONE
Y                                         5          0 FREQUENCY