Notes by Dr. Xi
Displaying notes 51 - 60
Created by Dr. Xi on February 06, 2010 00:38:29
Last update: February 06, 2010 00:39:01
From Oracle doc: DBA_FREE_SPACE describes the free extents in all tablespaces in the database. Note that if a datafile (or entire tablespace) is offline in a locally managed tablespace, you will not see any extent information. If an object has extents in an online file of the tablespace, you will see extent information about the offline datafile. However, if the object is entirely in the offline file, a query of this view will not return any records. SQL> select tablespace_name, count(*) free_extends, sum(blocks) total_blocks 2 from dba_free_space 3 group by tablespace_name; TABLESPACE_NAME FREE_EXTENDS TOTAL_BLOCKS ------------------------------ ------------ ------------ SYSAUX 84 5616 USERS 1 12376 SYSTEM 2 904 UNDO 13 14016 SQL>
Created by Dr. Xi on February 06, 2010 00:25:00
Last update: February 06, 2010 00:26:50
Solution: grant unlimited tablespace to <user> or alter user <user_name> quota 250m on <tablespace_name> Example: SQL> create table customer ( 2 id number(9), 3 name varchar2(40)); create table customer ( * ERROR at line 1: ORA-01950: no privileges on tablespace 'SYSTEM' SQL> quit Disconnected from Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production C:\>sqlplus system@xe SQL*Plus: Release 10.1.0.5.0 - Production on Fri Feb 5 18:19:08 2010 Copyright (c) 1982, 2005, Oracle. All rights reserved. Enter password: Connected to: Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production SQL> grant unlimited tablespace to jpa; Grant succeeded. SQL> quit Disconnected from Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production C:\>sqlplus jpa@xe SQL*Plus: Release 10.1.0.5.0 - Production on Fri Feb 5 18:20:42 2010 Copyright (c) 1982, ...
Created by Dr. Xi on February 06, 2010 00:15:01
This query lists the tablespaces in Oracle: SQL> select * from v$tablespace; TS# NAME INC BIG FLA ENC ---------- ------------------------------ --- --- --- --- 0 SYSTEM YES NO YES 1 UNDO YES NO YES 2 SYSAUX YES NO YES 4 USERS YES NO YES 3 TEMP NO NO YES SQL>
Created by Dr. Xi on February 05, 2010 23:53:17
SQL> select sys_context('userenv', 'current_schema') from dual; SYS_CONTEXT('USERENV','CURRENT_SCHEMA') ------------------------------------------------------------------------------- JPA SQL> alter session set current_schema = sys; Session altered. SQL> select sys_context('userenv', 'current_schema') from dual; SYS_CONTEXT('USERENV','CURRENT_SCHEMA') ------------------------------------------------------------------------------- SYS SQL>
Created by Dr. Xi on February 04, 2010 00:21:05
Last update: February 04, 2010 00:22:09
The table DBA_DATA_FILES contains information about data files used in an Oracle database. The table DBA_SEGMENTS describes the storage allocated for all segments in the database. SQL> select sum(bytes)/1024/1024 SIZE_MB from dba_data_files; SIZE_MB ---------- 905 SQL> select sum(bytes)/1024/1024 SIZE_MB from dba_segments; SIZE_MB ---------- 646.375 SQL>
Created by Dr. Xi on February 03, 2010 19:32:30
Last update: February 04, 2010 16:30:49
This happens when you don't have connectivity to the Oracle server. This could be that the server is not up or you are blocked because of some firewall rules. A typical session looked like this: C:\>sqlplus scott/tiger@xe SQL*Plus: Release 10.1.0.5.0 - Production on Wed Feb 3 13:27:41 2010 Copyright (c) 1982, 2005, Oracle. All rights reserved. ERROR: ORA-12170: TNS:Connect timeout occurred Enter user-name: scott@xe Enter password: ERROR: ORA-12170: TNS:Connect timeout occurred Use tnsping to confirm the cause: C:\>tnsping xe TNS Ping Utility for 32-bit Windows: Version 10.1.0.5.0 - Production on 03-FEB-2 010 11:54:02 Copyright (c) 1997, 2003, Oracle. All rights reserved. Used parameter files: C:\work\globaltnsnames\sqlnet.ora Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (Host ...
Created by Dr. Xi on February 03, 2010 19:26:35
Last update: February 04, 2010 16:53:04
This seemed to happen when Oracle does not know which instance to connect to. Instead of telling you that you didn't give enough information, Oracle decides that you are better informed by telling you that it's a "protocol adapter error". In the following I didn't give the SID, nor did I set LOCAL: C:\>sqlplus scott/tiger SQL*Plus: Release 10.1.0.5.0 - Production on Wed Feb 3 11:52:43 2010 Copyright (c) 1982, 2005, Oracle. All rights reserved. ERROR: ORA-12560: TNS:protocol adapter error Enter user-name: ERROR: ORA-12560: TNS:protocol adapter error Enter user-name: ERROR: ORA-12560: TNS:protocol adapter error SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus It does seem to give the right information on Linux: $ sqlplus scott/tiger SQL*Plus: Release 10.1.0.5.0 - Production on Thu Feb ...
Created by Dr. Xi on February 03, 2010 17:44:14
When you start sqlplus withoud SID, Oracle says that you connect to the default database you created during installation. What if I installed multiple databases and I forgot which one is default? Is there a way to find out which is the current default? I wasn't able to find an answer. But there are a couple of ways to change the default by setting a couple of environment variables. The bad news is: the variables are different depending on which platform you are on. Unix If you are on Unix and the database is local, set these two variables: export ORACLE_HOME=/app/oracle/product/10.2.0/db_1 export ORACLE_SID=orcl If the database is remote, set TWO_TASK : export TWO_TASK=orcl Windows If you are on Windows, set LOCAL : set LOCAL=orcl Of ...
Created by Dr. Xi on February 03, 2010 03:48:00
The ORA-06512 code is not the actual error. It merely indicates on which line the error occurred. The real error precedes ORA-06512 . For example: ERROR at line 1: ORA-29400: data cartridge error IMG-00714: internal error ORA-28579: network error during callback from external procedure agent ORA-06512: at "ORDSYS.ORDIMGEXTCODEC_PKG", line 164 ORA-06512: at "ORDSYS.ORDIMGEXTCODEC_PKG", line 160 ORA-06512: at line 1 ORA-06512: at "ORDSYS.ORDIMG_PKG", line 525 ORA-06512: at "ORDSYS.ORDIMAGE", line 59 ORA-06512: at "TKIDIUSER.IMG_PROCESSCOPY", line 12 ORA-06512: at "TKIDIUSER.TKIDIPCU_MAIN", line 57 ORA-06512: at line 1
Created by Dr. Xi on February 03, 2010 03:29:42
Last update: February 03, 2010 03:31:02
You can use the java.util.Calendar.add method to do date arithmetics. All calculations are straigntforward except for adding or subtracting months. import java.text.*; import static java.util.Calendar.*; public class TestCalendar { private static final DateFormat FORMAT = new SimpleDateFormat("MM/dd/yyyy"); public static void main(String[] args) throws Exception { Calendar c = Calendar.getInstance(); c.set(DAY_OF_MONTH, 1); System.out.println("Initial Date: " + FORMAT.format(c.getTime())); c.add(DAY_OF_MONTH, -1); System.out.println("One Day Ago: " + FORMAT.format(c.getTime())); c.add(MONTH, 1); System.out.println("One Month Later: " + FORMAT.format(c.getTime())); c.add(MONTH, 1); System.out.println("Another Month Later: " + FORMAT.format(c.getTime())); } } The output is: C:\>java TestCalendar Initial Date: 02/01/2010 One Day Ago: 01/31/2010 One Month Later: 02/28/2010 Another Month Later: 03/28/2010 You started from January month end, advancing two months, you are no longer at month end. Use this trick to advance from onth ...