Saturday, November 28, 2009

Oracle RAC how to start or stop cluser database with srvctl command

These commands are useful when handling the Oracle RAC databases. They can be executed from any of the nodes in the cluster:

$ srvctl start database -d dbName
$ srvctl stop database -d dbName


$ srvctl start instance -d dbName -i dbName1
$ srvctl start instance -d dbName -i dbName2


$ srvctl stop instance -d dbName -i dbName1
$ srvctl stop instance -d dbName -i dbName2

Thursday, November 26, 2009

Oracle how to create table with "invisible" name

In Oracle it is possible to create a table with no name (just space):

create table " " 
   (col1 int,
     col2 varchar2(10));


Then you can use the following to select data:


select * from " ";

Monday, October 19, 2009

Oracle: How to create random test data multiple rows easy


To create a table with 100,000 rows with random values just type:


create table tableName (columnName1 number, columnName2 number);

insert into tableName (select rownum, dbms_random.value(1,100)
                        from dual
                      connect by level <= 100000);


commit;

Saturday, October 17, 2009

Oracle: how to page / paging result in select

Paging in Oracle is not as easy as one could think.
If you would like your query to return lets say 100 rows with the start at row 1300:

select * from (
  select rowum as rn, b.*
    from (select a.columnName1, a.columnName2
            from tableName a
           order by a.columnName1) b
        ) c
    where c.rn between 1300 and 1300 + 100

Oracle: How to avoid duplicate rows in query result while selecting from table

If you select data from one column in a table like this:

select columnName
  from tableName;


columnName
=========
A
A
A
B
B

you would get that columns data from all rows. If you would like to avoid / skip duplicates (and only get the distinct values) you could type:


select distinct columnName
  from tableName;


columnName
=========
A
B




Another approach is:


select columnName, count(*)
  from tableName
  group by columnName;


columnName   count(*)
=========    ========
A            3
B            2





Thursday, October 15, 2009

oracle sql skip rows



What is it really you want to do? Skip rows? Do you mean delete?

Or skipping rows while selecting?

select * from tablename where columnName != 'Peter';

Oracle: how to alter quota for a user

You can use the alter user-statement to change the amount of space that a user can utilize in a tablespace:

alter user userName quota 100M on temp;


alter user userName quota 0M on system;


If the user has the system privilege "unlimited tablespace" it overrides the quota on each tablespace and gives unlimited quota.