יום ראשון, דצמבר 17, 2006

Regulaer experssions = Tips

You can do wonderful stuff with regular expressions , here are some useful items :

  • select regexp_substr('ORA-06512: at "ECTEL_ADMIN.ERR", line 20 ORA-06512: at "ECTEL_ADMIN.ERR", line 89 ORA-06512: at "FRAUD_OWNER.RULES_MGR", line 1932 ORA-06512: at "FRAUD_OWNER.ALERT_MGR", line 611 ','[^'||chr(10)||']+\Z',1,1) from dual;

    This get the last line , it look for all lines string with chr(10) - which represent end of previous line , and ended with \Z which represent end of string .

יום שני, אוקטובר 23, 2006

Look in a list of values with Like

Let say , you've a table of values , and you want to a list of records which answer those records and like (support of wildcard) .
The sql to do it is like the follow :

select dt.tablespace_name
from dba_tablespaces dt
where not exists
(select 1 from br_content bc where dt.tablespace_name like bc.component_name and job_id = 1 )


Note the order of the tablespace_name and component_name.


יום רביעי, ספטמבר 06, 2006

INSERT with select example

SQL> insert into giy values((select 900 from dual),(select 902 from actions));

1 row inserted

-- Must be single row query
SQL> insert into giy values((select 900 from dual),(select 902 from users));

insert into giy values((select 900 from dual),(select 902 from users))

ORA-01427: single-row subquery returns more than one row


SQL>
commit;


Commit complete

יום שני, אוגוסט 07, 2006

How to change database charsets

In order to the change database charset do the following:


Please note this procdure may corrupt database which is not supported by the new charset.


Login as sys to the oracle :

  • SHUTDOWN IMMEDIATE;
  • STARTUP MOUNT;
  • ALTER SYSTEM ENABLE RESTRICTED SESSION;
  • ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0;
  • ALTER SYSTEM SET AQ_TM_PROCESSES=0;
  • ALTER DATABASE OPEN;
  • ALTER DATABASE CHARACTER SET INTERNAL_USE ;
  • SHUTDOWN IMMEDIATE;
  • STARTUP;

יום חמישי, יולי 20, 2006

How to create new file system in sun solaries

STEP 1 -

unix>format
FORMAT MENU:
disk - select a disk
type - select (define) a disk type
partition - select (define) a partition table
current - describe the current disk
format - format and analyze the disk
repair - repair a defective sector
label - write label to the disk
analyze - surface analysis
defect - defect list management
backup - search for backup labels
verify - read and display labels
save - save new disk/partition definitions
inquiry - show vendor, product and revision
volname - set 8-character volume name
! - execute , then return
quit

format>p

PARTITION MENU:
0 - change `0' partition
1 - change `1' partition
2 - change `2' partition
3 - change `3' partition
4 - change `4' partition
5 - change `5' partition
6 - change `6' partition
7 - change `7' partition
select - select a predefined table
modify - modify a predefined partition table
name - name the current table
print - display the current table
label - write partition map and label to the disk
! - execute , then return
quit
partition>p
Part Tag Flag Cylinders Size Blocks
0 unassigned wm 0 0 (0/0/0) 0
1 unassigned wu 0 0 (0/0/0) 0
2 unassigned wu 0 0 (0/0/0) 0
3 unassigned wm 0 0 (0/0/0) 0
4 unassigned wm 0 0 (0/0/0) 0
5 unassigned wm 0 0 (0/0/0) 0
6 usr wm 36 - 50397 368.86GB (50362/0/0) 773560320
7 unassigned wm 0 0 (0/0/0) 0

Step 2
p>0
Part Tag Flag Cylinders Size Blocks
0 unassigned wm 0 0 (0/0/0) 0

Enter partition id tag[unassigned]:
Enter partition permission flags[wm]:
Enter new starting cyl[0]:
Enter partition size[0b, 0c, 0e, 0.00mb, 0.00gb]: 0
p>quit

step 3
format>volname UR
format>quit

step 4
unix> newfs /dev/dsk/c3t3d4s0
newfs: construct a new file system /dev/rdsk/c3t3d4s0: (y/n)? y
Warning: 3072 sector(s) in last cylinder unallocated
/dev/rdsk/c3t3d4s0: 773852160 sectors in 125953 cylinders of 48 tracks, 128
sectors
377857.5MB in 7873 cyl groups (16 c/g, 48.00MB/g, 5824 i/g)
super-block backups (for fsck -F ufs -o b=#) at:
32, 98464, 196896, 295328, 393760, 492192, 590624, 689056, 787488, 885920,
Initializing cylinder groups:
...............................................................................
..............................................................................
super-block backups for last 10 cylinder groups at:
772971424, 773069856, 773168288, 773266720, 773365152, 773463584, 773562016,
773660448, 773758880, 773849120

step 4
unix>mount /dev/dsk/c3t3d4s0 /u01/app/oracle/oradata/PERF2/ARCH

יום חמישי, יוני 22, 2006

Waiting on enq:JI

I got an installation which got the following problem:
the user has done the following :
  • update all_cases set desc='aaa' where id=2;
  • commit <--- this statment got hang for about 5 mintunes.
The reason for that is because we have a materialize view on commit on the this table.
This materialized view is doing a full refresh due to some wrong declaration. This cause the wait above.

יום ראשון, יוני 18, 2006

How to build databases on \\netstore3\db

We’ve storage to keep all the database files. The only account which is permitted to access this account is ECTEL\dba



It order for oracle database to access the files you need to do the following :

• Login with local administrator to the db machine – add user ectel\dba to administrator group (need to be done only once )
• Login with this user(ectel\dba) to machine which the database software installed.
• When creating database files use absolute path (\\netstore3\db\database\dbname
• Run dbca and choose the option to create scripts only; a batch file named .bat will be created.
• Edit the batch file and put a remark on the line where the script .sql is run.
• Run the first part of the batch file , which creates the directories and run oradim to create the service.
• Change the oracle service properties to logon with ectel\dba account
• Stop and restart the service
• Run the rest of the batch file (comment in the part already run).
• After the database is created, you need also to change the listener service to logon with ectel/dba.
Otherwise it will not be possible to connect to the database with tns.
• If other Oracle instances run on the machine: you also have to change their service so it logon with ectel/dba

יום חמישי, מאי 25, 2006

Using DBCA - Part I

DBCA - Database Configuration Assistant

Everyone know about the GUI interface , here i will try to show how to use the command line interface.

Deleting database

dbca -progressOnly -deleteDatabase -sourceDB -sysDBAPassword
This will start the deletion of the database , It will ask for confirmation.

יום שלישי, מאי 16, 2006

Switching To Archivelog in 10g

  1. Show parameter parallel_max_servers (write down old value)
  2. alter system set parallel_max_servers=0 scope=both;
  3. shutdown immediate
  4. startup restrict mount
  5. Alter database archicvelog ; (no need to use archive log start)
  6. alter system set parallel_max_servers= scope=both;
  7. shutdown immediate
  8. startup

יום ראשון, אפריל 02, 2006

Application securiny - Part I

Secure the oracle password :

You can use wallet to stone encrypted passwords without any application code changes.

Here are the steps to implement wallet connections:

1. Create the wallet directory and objects

mkstore -wrl -create


2. Insert a new database alias to be used

mkstore -wrl -createCredential

3. Configure the sqlnet.ora (oracle client ) to use the wallet settings

(add the following lines )

NAMES.DIRECTORY_PATH= (EZCONNECT, TNSNAMES)
WALLET_LOCATION =
(SOURCE = (METHOD = FILE) (
METHOD_DATA = (DIRECTORY =
) ) )
SQLNET.WALLET_OVERRIDE = TRUE

4. Test the connection using sqlplus /@db_connect_sting


For more information has a look here.




יום שלישי, מרץ 07, 2006

ORACLE sort comp : NLS_SORT nls_comp v$nls_parameters binary

The sort and comp (like between) migth work differently.


-- Two examples:


-- First example:

DROP TABLE TEST;

CREATE TABLE TEST ( entity VARCHAR2(4));

INSERT INTO TEST VALUES('a');

INSERT INTO TEST VALUES('0');

INSERT INTO TEST VALUES('A');

INSERT INTO TEST VALUES('1');

COMMIT;

-- sort and comp are the same:

ALTER SESSION SET nls_sort = BINARY;

ALTER SESSION SET nls_comp=BINARY;

-- 10g feature in 9i default

SELECT * FROM TEST ORDER BY entity;

SELECT * FROM TEST WHERE entity > 'A';

-- sort and comp are different:

ALTER SESSION SET nls_sort = 'German';

SELECT ENTITY from TEST order by ENTITY ;

SELECT entity "This should return 0,1" FROM TEST WHERE entity > 'A';

-- Make the comp behave like the sort:

ALTER SESSION SET nls_comp='ANSI';

SELECT entity "now ok" FROM TEST WHERE entity > 'A';

-- Second example:

DROP TABLE TEST;

CREATE TABLE TEST ( entity VARCHAR2(4));

INSERT INTO TEST VALUES('a');

INSERT INTO TEST VALUES('0');

INSERT INTO TEST VALUES('A');

INSERT INTO TEST VALUES('1');

COMMIT;

CREATE OR REPLACE VIEW yy AS

select min(entity) min_entity,MAX(ENTITY) max_entity

from (SELECT ENTITY from TEST order by ENTITY )

group by floor ( ROWNUM/2 );

ALTER SESSION SET nls_sort = BINARY;

SELECT ENTITY from TEST order by ENTITY ;

select * FROM yy;

SELECT * FROM TEST,yy WHERE entity BETWEEN min_entity AND max_entity ;

ALTER SESSION SET nls_sort = 'German';

SELECT ENTITY from TEST order by ENTITY ;

select * FROM yy;

SELECT * FROM TEST,yy WHERE entity BETWEEN min_entity AND max_entity ;

The output :

SQL>SELECT * FROM TEST ORDER BY entity;

ENTI

----

a

A

0

1

SQL>SELECT * FROM TEST WHERE entity > 'A';

ENTI

----

0

1

SQL>-- sort and comp are different:

SQL>ALTER SESSION SET nls_sort = 'German';

Session altered.

SQL>SELECT ENTITY from TEST order by ENTITY ;

ENTI

----

0

1

A

a

SQL>SELECT entity "This should return 0,1" FROM TEST WHERE entity > 'A';

This

----

a

SQL>-- Make the comp behave like the sort:

SQL>ALTER SESSION SET nls_comp='ANSI';

Session altered.

SQL>SELECT entity "now ok" FROM TEST WHERE entity > 'A';

now

----

0

1

SQL>CREATE OR REPLACE VIEW yy AS

2 select min(entity) min_entity,MAX(ENTITY) max_entity

3 from (SELECT ENTITY from TEST order by ENTITY )

4 group by floor ( ROWNUM/2 );

View created.

SQL>ALTER SESSION SET nls_sort = BINARY;

Session altered.

SQL>SELECT ENTITY from TEST order by ENTITY ;

ENTI

----

0

1

A

a

SQL>select * FROM yy;

MIN_ MAX_

---- ----

1 A

a a

0 0

SQL>SELECT * FROM TEST,yy WHERE entity BETWEEN min_entity AND max_entity ;

ENTI MIN_ MAX_

---- ---- ----

a a a

A 1 A

1 1 A

0 0 0

SQL>ALTER SESSION SET nls_sort = 'German';

Session altered.

SQL>SELECT ENTITY from TEST order by ENTITY ;

ENTI

----

a

A

0

1

SQL>select * FROM yy;

MIN_ MAX_

---- ----

0 A

1 1

a a

SQL>SELECT * FROM TEST,yy WHERE entity BETWEEN min_entity AND max_entity ;

ENTI MIN_ MAX_

---- ---- ----

1 1 1

a a a

SQL>

SQL>

יום חמישי, מרץ 02, 2006

FAQ - in FraudView 8.0

  1. How to roll partitions
    --> Login as ectel_admin
    --> exec dbms_scheduler.run_job('ECT_DBM_PARTITION_CLEANUP_ J')

יום חמישי, פברואר 02, 2006

Analtic functions

one of my friend ask how to get the lower value of partition :

SELECT TABLE_OWNER,TABLE_NAME,PARTITION_POSITION,PARTITION_NAME
, LAG(PARTITION_NAME,1) OVER (ORDER BY PARTITION_NAME) BEFORE_PARTITION_NANE
, LAG(PARTITION_POSITION,1) OVER (ORDER BY PARTITION_POSITION) BEFORE_PARTITION
FROM all_tab_partitions WHERE table_name='UR_PROBE' AND table_owner='DBWR'

יום חמישי, ינואר 26, 2006

Working with XMLS


Updating XML
  • update im_config set current_data = updateXML(current_data, '/a/*[@x=2]text()', 'two') where ID='TEST';
  • (using clob)
    declare newURL varchar2(300):='http://ServerName/businessobjects/enterprise115/desktoplaunch/InfoView/logon/logon.do';
    begin
    update ui_settings a set a.xml =
    updateXML(xmltype(a.xml),'/MENUS/BUTTON/MENU[@TITLE=''Reports'']/@URL',newURL).getclobval()
    where a.data_type='menus';
    end;
Inserting BIG XML

  • declare
    vrow xmltype:= xmltype(' < !-- put xml here --> ');
    begin
    delete MyXmlTab where PK_ID=1;
    insert into MyXmlTab(PK_ID,myxml) values (1,vrow);
    end;
    /

Searching XML

SELECT --e, VALUE(hd),
EXTRACT(e, 'HotList/@ID').GETSTRINGVAL(),
EXTRACT(e, 'HotList/@NAME').GETSTRINGVAL(),
EXTRACT(VALUE(hd), 'HotListData/@ID').GETSTRINGVAL(),
EXTRACT(VALUE(hd), 'HotListData/@VALUE').GETSTRINGVAL()
FROM
(
SELECT VALUE(e) e
FROM GIY1 P,
TABLE(XMLSEQUENCE(EXTRACT(p.A, '/KS/Hotlists/Group/HotList'))) e),
TABLE(
XMLSEQUENCE(EXTRACT(e, 'HotList/HotListData')))(+) hd






יום רביעי, ינואר 25, 2006

Enable flashback database

One Time Setting

  • shutdown immediate
  • startup mount
  • alter database archivelog;
  • alter system set db_recovery_File_dest_Size=5G scope=both;
  • alter system set db_recovery_File_dest='E:\oracle\recovery' scope=both;
  • alter database flashback on;
  • alter database open;

Before applying changes/tests scripts :

  • CREATE RESTORE POINT ZeroBaseData GUARANTEE FLASHBACK DATABASE;

Do the changes
create table mytest (a number);
insert into mytest values (1);
commit;
select * from mytest;


Rollback if needed ...
  • shutdown immediate
  • startup mount
  • find existing restore points by this query: select * from v$restore_point;
  • flashback database to restore point zerobasedata;
  • alter database open resetlogs;
  • select * from mytest;