Showing posts with label Oracle Database 10g. Show all posts
Showing posts with label Oracle Database 10g. Show all posts

Monday, 11 August 2008

Oracle Database : Space used in the flash recovery area

Here is a small script adopted from the book "RMAN Recipes for Oracle 11g" by Darl Kuhn, Sam R. Alapati and Arup Nanda. This script when run in from SQL Plus, will display the amount of used space in the current database flash recovery area.

SET PAGESIZE 66;
SET LINESIZE 80;

REPHEADER PAGE CENTER 'Flash Recovery Area Usage';

COLUMN FILE_TYPE FORMAT a20;
COLUMN FILE_TYPE HEADING 'File Type';

COLUMN USED_MB HEADING 'Used MBytes';
COLUMN USED_MB FORMAT 999999.99;
COLUMN RECLAIMABLE_MB HEADING 'Reclaimable Mbytes';
COLUMN RECLAIMABLE_MB FORMAT 9999999.99;

COLUMN NUMBER_OF_FILES HEADING 'Number of files';

BREAK ON REPORT
COMPUTE SUM LABEL 'Totals:' OF USED_MB RECLAIMABLE_MB ON REPORT;

SELECT
  rau.file_type,
  rfd.space_used * rau.percent_space_used / 1024 / 1024 as USED_MB,
  rfd.space_reclaimable * rau.percent_space_reclaimable / 1024 / 1024 as RECLAIMABLE_MB,
  rau.number_of_files as NUMBER_OF_FILES
FROM
  v$recovery_file_dest rfd, v$flash_recovery_area_usage rau;

Hre is a sample output run against a newly created 11g database

                            Flash Recovery Area Usage

File Type            Used MBytes Reclaimable Mbytes Number of files
-------------------- ----------- ------------------ ---------------
CONTROL FILE              716.17                .00               1
REDO LOG                11649.70                .00               3
ARCHIVED LOG            31957.11             391.11              10
BACKUP PIECE            79272.10                .00               2
IMAGE COPY                   .00                .00               0
FLASHBACK LOG                .00                .00               0
FOREIGN ARCHIVED LOG         .00                .00               0
                     ----------- ------------------
Totals:                123595.09             391.11

The concept is very simple. Oracle provides two views for retrieving information about the flash recovery area. One is the v$recovery_file_dest that contains information about the flash recovery area associated with the current database. A select * on this view will give us an output like the following :

SQL> select * from v$recovery_file_dest;

NAME
--------------------------------------------------------------------------------
SPACE_LIMIT SPACE_USED SPACE_RECLAIMABLE NUMBER_OF_FILES
----------- ---------- ----------------- ---------------
/u01/app/oracle/flash_recovery_area
 2147483648 1668797952          93845504              16

This view provides the total number of used and reclaimable bytes from the flash recovery area. The next view named v$flash_recovery_area_usage, provided percentage information about each type of file that can be stored in the flash recovery area. Doing a select * on this view gives up the following results.

SQL> set linesize 100;
SQL> select * from v$flash_recovery_area_usage

FILE_TYPE            PERCENT_SPACE_USED PERCENT_SPACE_RECLAIMABLE NUMBER_OF_FILES
-------------------- ------------------ ------------------------- ---------------
CONTROL FILE                        ,45                         0               1
REDO LOG                           7,32                         0               3
ARCHIVED LOG                      20,08                      4,37              10
BACKUP PIECE                      49,81                         0               2
IMAGE COPY                            0                         0               0
FLASHBACK LOG                         0                         0               0
FOREIGN ARCHIVED LOG                  0                         0               0

... so the next logical thing in order to get something meaningful out of these is to join them and this is what the initial script does. Since the v$recovery_file_dest view has only one column, all columns of the v$flash_recovery_area_usage view refer this hence the no need for a where clause in the script's sql.

Saturday, 23 February 2008

Oracle 11g How to determine the database character set

This is only a quick note for something I keep forgetting. So to determine the oracle database character set use the following simple SQL statement.

   select *
      from v$nls_parameters
      where parameter='NLS_CHARACTERSET'

Monday, 11 February 2008

Oracle 10g Killing open sesions

We have a client program that leaves lots of open sessions. These sessions take up server resources and we wanted to find a way to locate and kill them.

Thanks to Natasa Oikonomidou from Softworks who provided the code, I ended up with the following solution:

Create a the following procedure on the sys schema.

create or replace
PROCEDURE inactive_session_killer
IS
  now DATE;
BEGIN
  now := sysdate;
  FOR rec IN
    (SELECT sid,
       serial#,
       username,
       schemaname,
       osuser,
       terminal,
       machine,
       PROGRAM,
       status,
       type,
       saddr,
       logon_time,
       now - last_call_et / 86400 last_activity
     FROM v$session
     WHERE username = 'XXXXX'   -- user name of open session "leaver"
           AND type = 'USER')
  LOOP

    IF rec.last_activity <( now  - 8 / 24) THEN
      -- inactive for more than 8 hours
      -- you can keep a log table here: inserrt into ...
      EXECUTE IMMEDIATE 'alter system kill session ''' ||  
                                        rec.sid || ',' || 
                                        rec.serial#    || 
                                        ''' immediate';

    END IF;

  END LOOP;
END;

Using SQLPlus or SQL Developer execute the following

 
VARIABLE jobno number;
BEGIN
   DBMS_JOB.SUBMIT(:jobno, 'inactive_session_killer;', SYSDATE, 'SYSDATE + 1/24');    -- runs every hour
   commit;
END;

... and that does it.

Wednesday, 12 December 2007

Oracle 10g SQL Mass rebuild and move the indexes of a specified user

Here is a function that rebuilds or coalesces the indexes of a specified user.If asked to rebuild the indexes then you can supply a table space to move the rebuild indexes into.

The function takes three parameters :

  • user_name : The name of the user whose indexes are to be updated
  • rebuild_type : Ether C or R to indicate Coalesce or Rebuild operation
  • tablespace_name : Optional parameter to indicate where to move the indexes in case of rebuild

The function should be executed by a user with DBA privileges and this code is as follows

create or replace PROCEDURE rebuild_user_indexes( user_name IN VARCHAR2, 
                                rebuild_type IN VARCHAR2, 
                                tablespace_name IN VARCHAR2 DEFAULT NULL) 
AS
  full_index_name VARCHAR2(100);
  index_command VARCHAR2(10);
  sql_str VARCHAR2(100);
  
  total_indexes Integer;
  updated_indexes Integer;
  
  CURSOR get_index_cursor IS
    SELECT index_name, index_type 
    FROM dba_indexes
    WHERE owner = user_name AND
          index_type in ( 
              'BITMAP', 
              'NORMAL', 
              'FUNCTION-BASED NORMAL', 
              'FUNCTION-BASED DOMAIN');
      
BEGIN
  /* check initial parameters */
  IF rebuild_type <> 'R' AND rebuild_type <> 'C' THEN
    raise_application_error( -20999, 'rebuild type should be "C" or "R"');
  ELSIF rebuild_type = 'R' THEN
    index_command := ' Rebuild';
    /* if a rebuild tablespace is also defined */
    IF tablespace_name <> '' THEN
      index_command := index_command || ' tablespace ' || tablespace_name;
    END IF;
  ELSE
    index_command := ' Coalesce';
  END IF;
  
  total_indexes := 0;
  updated_indexes := 0;
  /* get all indexes that belong to the specified user */
  FOR r IN get_index_cursor LOOP
    total_indexes := total_indexes + 1; 
    dbms_output.put_line( total_indexes || ' ' || 
                          r.index_name || ' ' || 
                          r.index_type);

    /* Coalescing works only on normal B-Tree indexes, 
     * while rebuilding works with everything.
     */    
    IF (rebuild_type = 'R') OR 
       (rebuild_type = 'C' AND instr( r.index_type, 'NORMAL') > 0) THEN
      
      full_index_name := user_name || '.' || r.index_name;
      sql_str := 'alter index ' || full_index_name || index_command;
      
      BEGIN
        /* attempt to modify the index */
        EXECUTE IMMEDIATE sql_str;
        updated_indexes := updated_indexes + 1;
      EXCEPTION
        WHEN OTHERS THEN
          /* display the command and the error that occured during index 
           * update 
           */
          dbms_output.put_line( sql_str);
          dbms_output.put_line( sqlcode || ' ' || sqlerrm);
          /* continue working */
          NULL;
      END;
    END IF;
  END LOOP;
    
  /* report results */
  dbms_output.put_line( 'Indexes examined :' || total_indexes);
  dbms_output.put_line( 'Indexes Updated  :' || updated_indexes);
END rebuild_user_indexes; 

Thanks to SQLDeveloper running the function can is as easy as copying and pasting the following in SQLPlus.

DECLARE
  USER_NAME VARCHAR2(200);
  REBUILD_TYPE VARCHAR2(200);
  TABLESPACE_NAME VARCHAR2(200);
BEGIN
  USER_NAME := NULL;       -- add your user here, for example 'HR'
  REBUILD_TYPE := NULL;    -- either 'C' or 'R'
  TABLESPACE_NAME := NULL; -- optional new tablespace name if desired

  REBUILD_USER_INDEXES(
    USER_NAME => USER_NAME,
    REBUILD_TYPE => REBUILD_TYPE,
    TABLESPACE_NAME => TABLESPACE_NAME
  );
END;

Note

The above code provides a very simplistic approach to index rebuilding as it rebuilds all indexes of a user. In order to determine the indexes in your database that would really benefit from rebuilding you need to run the script available from Oracle Metalink Note:122008.1.

Wednesday, 28 November 2007

Where is the Oracle Database alert log located ?

This is something I keep forgetting so I think that I may as well add it here.

On my Linux system the alert log is located in $ORACLE_HOME/admin/$ORACLE_SID/bdump while the exact same path -- with "\" instead of "/" -- is used for Windows.

The directory where the alert.log found is determined by the background_dump_dest initialization parameter: So the ultimate way to find it is by issuing an SQL command like :

select value 
    from v$parameter 
    where name = 'background_dump_dest';

Needless to say that the alert.log's name is alert.log and that it is a simple text file that can be opened using any text editor and that you can delete it or shrink it online.

Tuesday, 3 July 2007

Oracle Table containing the list of all countries

I wanted to create a table containing all country codes and countries.so I set off looking for the list of all two letter country codes. I have to admit that today was my lucky day since I ended up finding not only the list but also ready made SQL code to create and populate a MySQL table ready to cut and paste into your PHPMyAdmin SQL window. The link for the MySQL version can be found here

The truth of the matter was that I needed this for Oracle, so cutting, pasting and dining a bit of editing resulted to the following code :


CREATE TABLE COUNTRY (
 COUNTRY_ID NUMBER(*,0) NOT NULL ENABLE,
 COUNTRY_CODE VARCHAR2(10 BYTE) NOT NULL ENABLE,
 COUNTRY VARCHAR2(4000 BYTE) NOT NULL ENABLE,
 CURRENCY VARCHAR2(4 BYTE),
 CONSTRAINT "COUNTRY_PK" PRIMARY KEY (COUNTRY_ID) ENABLE,
 CONSTRAINT "COUNTRY_CODE_UNIQUE" UNIQUE (COUNTRY_CODE) ENABLE
);

-- INSERTING into COUNTRY
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (1,'ac','Ascension Island',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (2,'ad','Andorra',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (3,'ae','United Arab Emirates',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (4,'af','Afghanistan',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (5,'ag','Antigua and Barbuda',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (6,'ai','Anguilla',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (7,'al','Albania',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (8,'am','Armenia',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (9,'an','Netherlands Antilles',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (10,'ao','Angola',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (11,'aq','Antartica',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (12,'ar','Argentina',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (13,'as','American Samoa',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (14,'au','Australia',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (15,'aw','Aruba',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (16,'az','Azerbaijan',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (17,'ba','Bosnia and Herzegovina',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (18,'bb','Barbados',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (19,'bd','Bangladesh',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (20,'be','Belgium',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (21,'bf','Burkina Faso',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (22,'bg','Bulgaria',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (23,'bh','Bahrain',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (24,'bi','Burundi',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (25,'bj','Benin',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (26,'bm','Bermuda',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (27,'bn','Brunei Darussalam',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (28,'bo','Bolivia',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (29,'br','Brazil',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (30,'bs','Bahamas',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (31,'bt','Bhutan',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (32,'bv','Bouvet Island',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (33,'bw','Botswana',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (34,'by','Belarus',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (35,'bz','Belize',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (36,'ca','Canada',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (37,'cc','Cocos (Keeling) Islands',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (38,'cd','Congo, Democratic People''s Republic',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (39,'cf','Central African Republic',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (40,'cg','Congo, Republic of',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (41,'ch','Switzerland',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (42,'ci','Cote d''Ivoire',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (43,'ck','Cook Islands',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (44,'cl','Chile',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (45,'cm','Cameroon',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (46,'cn','China',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (47,'co','Colombia',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (48,'cr','Costa Rica',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (49,'cu','Cuba',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (50,'cv','Cap Verde',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (51,'cx','Christmas Island',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (52,'cy','Cyprus',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (53,'cz','Czeck Republic',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (54,'de','Germany',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (55,'dj','Djibouti',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (56,'dk','Denmark',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (57,'dm','Dominica',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (58,'do','Dominican Republic',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (59,'dz','Algeria',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (60,'ec','Ecuador',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (61,'ee','Estonia',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (62,'eg','Egypt',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (63,'eh','Western Sahara',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (64,'er','Eritrea',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (65,'es','Spain',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (66,'et','Ethiopia',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (67,'fi','Finland',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (68,'fj','Fiji',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (69,'fk','Falkland Islands (Malvina)',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (70,'fm','Micronesia, Federal State of',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (71,'fo','Faroe Islands',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (72,'fr','France',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (73,'ga','Gabon',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (74,'gd','Grenada',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (75,'ge','Georgia',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (76,'gf','French Guiana',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (77,'gg','Guernsey',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (78,'gh','Ghana',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (79,'gi','Gibraltar',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (80,'gl','Greenland',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (81,'gm','Gambia',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (82,'gn','Guinea',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (83,'gp','Guadeloupe',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (84,'gq','Equatorial Guinea',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (85,'gr','Greece',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (86,'gs','South Georgia and the South Sandwich Islands',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (87,'gt','Guatemala',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (88,'gu','Guam',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (89,'gw','Guinea-Bissau',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (90,'gy','Guyana',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (91,'hk','Hong Kong',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (92,'hm','Heard and McDonald Islands',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (93,'hn','Honduras',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (94,'hr','Croatia/Hrvatska',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (95,'ht','Haiti',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (96,'hu','Hungary',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (97,'id','Indonesia',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (98,'ie','Ireland',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (99,'il','Israel',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (100,'im','Isle of Man',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (101,'in','India',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (102,'io','British Indian Ocean Territory',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (103,'iq','Iraq',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (104,'ir','Iran (Islamic Republic of)',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (105,'is','Iceland',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (106,'it','Italy',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (107,'je','Jersey',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (108,'jm','Jamaica',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (109,'jo','Jordan',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (110,'jp','Japan','Yen');
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (111,'ke','Kenya',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (112,'kg','Kyrgyzstan',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (113,'kh','Cambodia',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (114,'ki','Kiribati',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (115,'km','Comoros',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (116,'kn','Saint Kitts and Nevis',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (117,'kp','Korea, Democratic People''s Republic',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (118,'kr','Korea, Republic of',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (119,'kw','Kuwait',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (120,'ky','Cayman Islands',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (121,'kz','Kazakhstan',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (122,'la','Lao, People''s Democratic Republic',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (123,'lb','Lebanon',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (124,'lc','Saint Lucia',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (125,'li','Liechtenstein',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (126,'lk','Sri Lanka',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (127,'lr','Liberia',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (128,'ls','Lesotho',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (129,'lt','Lithuania',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (130,'lu','Luxembourg',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (131,'lv','Latvia',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (132,'ly','Libyan Arab Jamahiriya',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (133,'ma','Morocco',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (134,'mc','Monaco',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (135,'md','Moldova, Republic of',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (136,'mg','Madagascar',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (137,'mh','Marshall Islands',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (138,'mk','Macedonia, Former Yugoslav Republic',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (139,'ml','Mali',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (140,'mm','Myanmar',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (141,'mn','Mongolia',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (142,'mo','Macau',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (143,'mp','Northern Mariana Islands',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (144,'mq','Martinique',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (145,'mr','Mauritania',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (146,'ms','Montserrat',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (147,'mt','Malta',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (148,'mu','Mauritius',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (149,'mv','Maldives',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (150,'mw','Malawi',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (151,'mx','Mexico',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (152,'my','Malaysia',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (153,'mz','Mozambique',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (154,'na','Namibia',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (155,'nc','New Caledonia',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (156,'ne','Niger',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (157,'nf','Norfolk Island',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (158,'ng','Nigeria',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (159,'ni','Nicaragua',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (160,'nl','Netherlands',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (161,'no','Norway',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (162,'np','Nepal',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (163,'nr','Nauru',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (164,'nu','Niue',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (165,'nz','New Zealand',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (166,'om','Oman',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (167,'pa','Panama',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (168,'pe','Peru',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (169,'pf','French Polynesia',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (170,'pg','Papua New Guinea',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (171,'ph','Philippines',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (172,'pk','Pakistan',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (173,'pl','Poland',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (174,'pm','St. Pierre and Miquelon',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (175,'pn','Pitcairn Island',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (176,'pr','Puerto Rico',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (177,'pt','Portugal',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (178,'pw','Palau',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (179,'py','Paraguay',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (180,'qa','Qatar',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (181,'re','Reunion Island',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (182,'ro','Romania',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (183,'ru','Russian Federation',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (184,'rw','Rwanda',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (185,'sa','Saudi Arabia',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (186,'sb','Solomon Islands',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (187,'sc','Seychelles',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (188,'sd','Sudan',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (189,'se','Sweden',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (190,'sg','Singapore',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (191,'sh','St. Helena',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (192,'si','Slovenia',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (193,'sj','Svalbard and Jan Mayen Islands',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (194,'sk','Slovak Republic',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (195,'sl','Sierra Leone',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (196,'sm','San Marino',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (197,'sn','Senegal',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (198,'so','Somalia',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (199,'sr','Suriname',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (200,'st','Sao Tome and Principe',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (201,'sv','El Salvador',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (202,'sy','Syrian Arab Republic',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (203,'sz','Swaziland',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (204,'tc','Turks and Ciacos Islands',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (205,'td','Chad',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (206,'tf','French Southern Territories',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (207,'tg','Togo',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (208,'th','Thailand',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (209,'tj','Tajikistan',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (210,'tk','Tokelau',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (211,'tm','Turkmenistan',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (212,'tn','Tunisia',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (213,'to','Tonga',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (214,'tp','East Timor',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (215,'tr','Turkey',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (216,'tt','Trinidad and Tobago',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (217,'tv','Tuvalu',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (218,'tw','Taiwan',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (219,'tz','Tanzania',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (220,'ua','Ukraine',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (221,'ug','Uganda',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (222,'uk','United Kingdom',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (223,'gb','United Kingdom',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (224,'um','US Minor Outlying Islands',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (225,'us','United States',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (226,'uy','Uruguay',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (227,'uz','Uzbekistan',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (228,'va','Holy See (City Vatican State)',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (229,'vc','Saint Vincent and the Grenadines',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (230,'ve','Venezuela',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (231,'vg','Virgin Islands (British)',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (232,'vi','Virgin Islands (USA)',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (233,'vn','Vietnam',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (234,'vu','Vanuatu',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (235,'wf','Wallis and Futuna Islands',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (236,'ws','Western Samoa',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (237,'ye','Yemen',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (238,'yt','Mayotte',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (239,'yu','Yugoslavia',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (240,'za','South Africa',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (241,'zm','Zambia',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (242,'zr','Zaire',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (243,'zw','Zimbabwe',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (250,'at','Austria',null);
Insert into COUNTRY (COUNTRY_ID,COUNTRY_CODE,COUNTRY,CURRENCY) values (251,'ps','Palestine',null);

Enjoy ..

Monday, 26 February 2007

Automatic configuration of SQL Plus on start-up

This is something I picked up from Oracle PL/SQL Programming by Steven Fewerstein and Bill Prybil.

When you start sqlplus the program reads configuration data from two files:
  • $ORACLE_HOME/sqlplus/admin/glogin.sql
  • ./login.sql
Since starting sqlplus from a directory that always contains an appropriate login.sql file isn't always possible, Bill recommends editing the glogin.sql. This is what the last lines my glogin sql look like :
-- Additional Settings by Bill Prybil
SET LINESIZE 132
SET PAGESIZE 999

-- Change the editor to vi if you don't do that sqlplus will use the editor from the $EDITOR
-- environment variable 
DEFINE _EDITOR = /usr/bin/vim

-- Format columns commonly retrieved from data dictionary
COLUMN segment_name FORMAT A30 WORD_WRAPP
COLUMN object_name FORMAT A30 WORD_WRAPP

-- set the sql prompt
SET SQLPROMPT "_USER'@'_CONNECT_IDENTIFIER >"

Thursday, 8 February 2007

Oracle 10g SQL Script to list the connected users

OK, I know that EM can give you the same result in much prettier form, but let's keep that just in case.

SET LINESIZE 200
SET PAGESIZE 66

SELECT s.username, s.logon_time, s.machine, s.osuser, s.program
FROM v$session s, v$process p, sys.v_$sess_io si
WHERE s.paddr = p.addr(+) AND si.sid(+) = s.sid AND s.type='USER';

Saturday, 3 February 2007

Oracle 10g Moving Data across tablespaces

Moving a table named my_table to a new tablespace named dest_data is a new feature of Oracle 10g and can be accomplished using the following command in SQLPlus:
SQL> alter table my_table move tablespace my_data;
Moving an index to a different table space is performed as follows :
SQL>alter index my_index rebuild tablespace my_data;

Friday, 2 February 2007

Oracle 10g on Linux Shell Variables required for proper operation

This is an extract from the .profile of the oracle user on a Linux machine (running SLES9) where Oracle 10g Release 2 (10.2.0.1.0) database enterprise edition is already installed. The variables required for correct operation of the database are the following
#
# Oracle Database 10g client related entries
#
export ORACLE_OWNER=oracle
export ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1

export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/ctx/lib
export LIB_PATH=$LD_LIBRARY_PATH:/usr/lib
export NLS_LANG=AMERICAN_GREECE.EL8ISO8859P7
export NLS_DATE_FORMAT='DD-MM-YYYY HH24:MI:SS'
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/ctx/bin:$ORACLE_HOME/OPatch:$PATH
export ORACLE_SID=mydb
Notes
  1. NLS_DATE_FORMAT is to allow rman display time information when listing backups
  2. NLS_LANG is to allow oracle software to display messages in a specific language (here American English), use regional settings for a specific country (Greece) and handle data encoded in a specific format (here iso8859-7).
  3. Forgetting to set the LD_LIBRARY_PATH has proved the root of many evil things
  4. The same values can also be used for installations of an oracle application server version 10.1.3.x. Just remove the $ORACLE_HOME/ctx/lib for the $LD_LIBRARY_PATH variable