2008-08-28 Thu
The SQL function TRIM has been around since Oracle 8i and maybe earlier. TRIM enables you to trim characters from a character string. The following examples demonstrate its usage and show you a few little known features of this simple function.
Remove leading and trailing blank spaces:
SQL> SELECT TRIM (' mystring ') FROM dual;
TRIM('MY
--------
mystring
Remove any leading characters equal to ‘x’:
SQL> SELECT TRIM (LEADING 'x' FROM 'xxmystringxx') FROM dual;
TRIM(LEADI
----------
mystringxx
Remove any trailing characters equal to ‘x’:
SQL> SELECT TRIM (TRAILING 'x' FROM 'xxmystringxx') FROM dual;
TRIM(TRAIL
----------
xxmystring
Removes leading and trailing characters equal to ‘x’:
SQL> SELECT TRIM (BOTH 'x' FROM 'xxmystringxx') FROM dual;
TRIM(BOT
--------
mystring
Removes leading and trailing characters equal to ‘x’ (Same as BOTH):
SQL> SELECT TRIM ('x' FROM 'xxmystringxx') FROM dual;
TRIM('X'
--------
mystring
My usage of this function has mostly been to trim blanks from both ends of a string. How about you?
Related functions: RTRIM and LTRIM.
---
Related Articles at Eddie Awad's Blog:
- Yet Another Oracle Social Network in the Works
- Oracle REF CURSOR and ColdFusion
- Cool SQL function: EXTRACT
- Previously Undocumented LNNVL SQL Function Buggy
- SYS_CONTEXT in Oracle
Update 2: H-Store: A Next Generation OLTP DBMS is the project implementing the ideas in this paper: The goal of the H-Store project is to investigate how these architectural and application shifts affect the performance of OLTP databases, and to study what performance benefits would be possible with a complete redesign of OLTP systems in light of these trends. Our early results show that a simple prototype built from scratch using modern assumptions can outperform current commercial DBMS offerings by around a factor of 80 on OLTP workloads.
Update: interesting related thread on Lamda the Ultimate.
A really fascinating paper bolstering many of the anti-RDBMS threads the have popped up on the intertube lately. The spirit of the paper is found in the following excerpt:
In summary, the current RDBMSs were architected for the business data processing market in a time of different user interfaces and different hardware characteristics. Hence, they all include the following System R architectural features:
* Disk oriented storage and indexing structures
* Multithreading to hide latency
* Locking-based concurrency control mechanisms
* Log-based recovery
Update 33: Amazon announces Elastic Block Store (EBS), which provides lots of normal looking disk along with value added features like snapshots and snapshot copying. But database's may find EBS too slow. RightScale tells us Why Amazon’s Elastic Block Store Matters.
Update 32: You can now get all attributes for a property when querying. Previously only the ID was returned and the attributes had to be returned in separate calls. This makes the programmer's job a lot simpler. Artificial levels of parallelization code can now be dumped.
Update 31: Amazon fixes a major hole in SimpleDB by adding the ability to sort query results. Previously developers had to sort results by hand which was a non-starter for many. Now you can do basic top 10 type queries with ease.
Update 30: Amazon SimpleDB - A distributed, highly-scalable, light-weight, query-able, attribute store by Sebastian Stadil. It introduces the CAP theorem and the basics of SimpleDB. Sebastian does a lot of great work in the AWS world and in what must be his limited free time, runs the AWS Meetup group.
2008-08-27 Wed
Or, “Missing information in the MySQL Manual”.
Just earlier today, I was using POW(), which I’ve grown quite fond of, simply because it makes life easier. I prefer using it like SELECT 512*POW(1024,2) to find out the number of bytes to put in a variable, for example.
First, let’s take a look at the POW function:
Name: 'POW' Description: Syntax: POW(X,Y) Returns the value of X raised to the power of Y.
Okay, so it gives us a value; but what about the data type? Let’s take 512*POW(1024,2) as an example.
5067 (blogs) > SELECT 512*POW(1024,2) AS example; +-----------+ | example | +-----------+ | 536870912 | +-----------+ 1 row in set (0.00 sec)
What is that? Well, it sure does look like an INT at this point, doesn’t it?
While Checking the status of database resources, ASM was shown as UNKNOWN on one node of a two node RAC.
$ crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora.orcl.db application ONLINE ONLINE rac1
ora....11.inst application ONLINE ONLINE rac1
ora....SM1.asm application ONLINE ONLINE rac1
ora....DC.lsnr application ONLINE ONLINE rac1
ora....idc.gsd application ONLINE ONLINE rac1
ora....idc.ons application ONLINE ONLINE rac1
ora....idc.vip application ONLINE ONLINE rac1
ora....SM2.asm application ONLINE UNKNOWN rac2
ora....C2.lsnr application ONLINE ONLINE rac2
ora....dc2.gsd application ONLINE ONLINE rac2
ora....dc2.ons application ONLINE ONLINE rac2
ora....dc2.vip application ONLINE ONLINE rac2
Following error was coming while trying to start the +ASM2 instance with SRVCTL:
$srvctl start asm -n rac2
PRKS-1009 : Failed to start ASM instance "+ASM2" on node "rac2",
[CRS-0223: Resource 'ora.rac2.ASM2.asm' has placement error.]
While trying to start the same with crs_start :
$ crs_start -f ora.rac2.ASM2.asm
CRS-1028: Dependency analysis failed because of:
'Resource in UNKNOWN state: ora.rac2.ASM2.asm'
CRS-0223: Resource 'ora.rac2.ASM2.asm' has placement error
There are two ways to come out of this UNKNOWN state of resources:
1. Start the resource from sqlplus
2. Use crs_stop -f to clear the state of database resources.
$ export ORACLE_HOME=+ASM2 $ sqlplus "/ as sysdba" SQL > startup Diskgroup mounted
It will go fine and the +ASM2 instnace will be started.
$ crs_stop -f ora.rac2.ASM2.asm
This will clear the UNKNOWN state and will make the resource as OFFLINE.
Now start the resource as:
$ srvctl start asm -n rac2
After using this check the status :
$ crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora.orcl.db application ONLINE ONLINE rac1
ora....11.inst application ONLINE ONLINE rac1
ora....SM1.asm application ONLINE ONLINE rac1
ora....DC.lsnr application ONLINE ONLINE rac1
ora....idc.gsd application ONLINE ONLINE rac1
ora....idc.ons application ONLINE ONLINE rac1
ora....idc.vip application ONLINE ONLINE rac1
ora....SM2.asm application ONLINE ONLINE rac2
ora....C2.lsnr application ONLINE ONLINE rac2
ora....dc2.gsd application ONLINE ONLINE rac2
ora....dc2.ons application ONLINE ONLINE rac2
ora....dc2.vip application ONLINE ONLINE rac2
Related Posts
The process of adding a node to a 11.1 RAC is very similar to the 10.2 process described in Part 5 of this series. For this reason, this post will just focus on what has changed between the 2 versions. Here is the complete series up to now:
- Installation of 10.2 And 11.1 Databases
- Patches of 10.2 And 11.1 databases
- Cloning Software and databases
- Install a 10.2 RAC Database
- Add a Node to a 10.2 RAC database
- Remove a Node from a 10.2 RAC database
- Install a 11.1 RAC Database
- Add a Node to a 11.1 RAC database (This post!)
- Remove a Node from a 11.1 RAC database
- A ton of other stuff you should know
Before you start
Make sure you’ve kept a copy of the voting disk and that you have a backup of the OCR. Check that the locations for all the components to be installed, i.e.: Inventory, Clusterware, ASM, database software, OCR, Voting Disks, and data files, are writable. Confirm that all the prerequisites are met for the node and for the whole cluster with the node to be added.
Refer to the Oracle Clusterware Administration and Deployment Guide
11g Release 1 (11.1) - 4 Adding and Deleting Oracle Clusterware Homes
and the Oracle Real Application Clusters Administration and Deployment Guide
11g Release 1 (11.1) - 9 Adding and Deleting Oracle RAC from Nodes on Linux and UNIX Systems for the complete reference of how to perform these steps.
Many of us would have come across RDA (Remote Diagnostic Agent) while working on a ticket with Oracle support. In case you have not heard about it, I would recommend to go through Metalink Note:314422.1 - Remote Diagnostic Agent (RDA) 4 - Getting Started
RDA captures System Information such as OS,Hardware Details (like number of CPU and amount of RAM),OS error log,OS Monitoring tool output (like vmstat,TOP,etc). This can be handy in case you do not know the command or the location of the OS logs.Similary you can find Database version,Database Patch inventory,Database Alert log and trace files.
This can help save lot of time as you need not remember all OS commands to capture the information.
Similarly RDA also collects Database Performance Statistics like OS Statistics (CPU,Memory and Disk I/O Stats) along with TOP SQL, Locking and Latch statistics. In case of 10g, it generates AWR Report (60 mins) and ADDM report based on captured Snapshots. All this information can be helpful for diagnosing a Performance Problem.
There is one more use of RDA which not many people are aware of. i.e RDA Health Check / Validation Engine (HCVE). HCVE Engine can be used to perform Pre-Install checks for Oracle Database and Oracle Application server on Unix system (At time of writing this article, this functionality is not available on windows)
To run this , you need to execute rda.sh -T hcve e.g I need to validate if I can install Oracle 10gR2 on my OEL4 (Linux x86).
$ ./rda.sh -T hcve Processing HCVE tests ... Available Pre-Installation Rule Sets: 1. Oracle Database 10g R1 (10.1.0) PreInstall (Linux-x86) 2. Oracle Database 10g R1 (10.1.0) PreInstall (Linux AMD64) 3. Oracle Database 10g R1 (10.1.0) PreInstall (IA-64 Linux) 4. Oracle Database 10g R2 (10.2.0) PreInstall (Linux AMD64) 5. Oracle Database 10g R2 (10.2.0) PreInstall (IA-64 Linux) 6. Oracle Database 10g R2 (10.2.0) PreInstall (Linux-x86) 7. Oracle Database 11g R1 (11.1.0) PreInstall (Linux AMD64) 8. Oracle Database 11g R1 (11.1.0) PreInstall (Linux-x86) 9. Oracle Application Server 10g (9.0.4) PreInstall (Linux) 10. Oracle Application Server 10g R2 (10.1.2) PreInstall (Linux) 11. Oracle Application Server 10g R3 (10.1.3) PreInstall (Linux AMD64) 12. Oracle Application Server 10g R3 (10.1.3) PreInstall (IA-64 Linux) 13. Oracle Application Server 10g R3 (10.1.3) PreInstall (Linux-x86) 14. Oracle Portal PreInstall (Generic) Available Post-Installation Rule Sets: 15. Oracle Portal PostInstall (generic) 16. RAC 10G DB and OS Best Practices (Linux) 17. Data Guard PostInstall (Generic) Enter the HCVE rule set number Hit 'Return' to accept the default (1) > 6 Enter value for < Planned ORACLE_HOME location or if set > Hit 'Return' to accept the default ($ORACLE_HOME) > /u01/app/oracle Test "Oracle Database 10g R2 (10.2.0) PreInstall (Linux-x86)" executed at Wed Aug 27 15:12:18 2008 Test Results ~~~~~~~~~~~~ ID NAME RESULT VALUE ===== ==================== ====== ======================================== 10 OS Certified? PASSED Adequate 20 User in /etc/passwd? PASSED userOK 30 Group in /etc/group? PASSED GroupOK 40 Input ORACLE_HOME RECORD /u01/app/oracle 50 ORACLE_HOME Valid? PASSED OHexists 60 O_H Permissions OK? PASSED CorrectPerms 70 Umask Set to 022? PASSED UmaskOK 80 LDLIBRARYPATH Unset? FAILED IsSet 100 Other O_Hs in PATH? FAILED OratabEntryInPath 110 oraInventory Permiss PASSED oraInventoryOK 120 /tmp Adequate? PASSED TempSpaceOK 130 Swap (in MB) RECORD 1051 140 RAM (in MB) FAILED 1001 150 Swap OK? FAILED InsufficientSwap 160 Disk Space OK? PASSED DiskSpaceOK 170 Kernel Parameters OK PASSED KernelOK 180 Got ld,nm,ar,make? PASSED ld_nm_ar_make_found 190 ulimits OK? FAILED StackTooSmall MaxLockMemTooSmall 200 EL4 RPMs OK? PASSED EL4rpmsOK 204 RHEL3 RPMs OK? PASSED NotRedHat 205 RHEL4 RPMs OK? PASSED NotRedHat 209 SUSE SLES9 RPMs OK? PASSED NotSuSE 212 Patch 3006854 Instal PASSED NotRHEL3 214 ip_local_port_range PASSED ip_local_port_rangeOK 220 Tainted Kernel? PASSED NotVerifiable 230 Other OUI Up? PASSED NoOtherOUI Result file: /home/oracle/rda/output/RDA_HCVE_A201DB10R2_lnx_res.htm
I also tried out option “RAC 10G DB and OS Best Practices (Linux)” which is part of Post Install but for some reason some of the components failed.
Enter the HCVE rule set number Hit 'Return' to accept the default (1) > 16 Enter the password for 'SYSTEM': Please re-enter it to confirm: Test "RAC 10G DB and OS Best Practices (Linux)" executed at Wed Aug 27 17:26:33 2008 Test Results ~~~~~~~~~~~~ ID NAME RESULT VALUE ===== ==================== ====== ======================================== 10 ORA_CRS_HOME RECORD /u01/app/crs 100 Database Name RECORD orcl 102 Database Version RECORD 10.2.0.4.0 104 Interconnect Network RECORD 106 DB Block Size RECORD 8192 108 DB File Multiblock R RECORD 16 120 Max Commit Propagati PASSED 0 130 SYS.AUDSES$ Cache Si PASSED 10000 132 SYS.IDGEN1$ Cache Si FAILED 20 140 Parallel Execution M FAILED 2148 150 Min Parallel Servers RECORD 1 152 Min Parallel Servers FAILED 0 200 $ORA_CRS_HOME Define PASSED Found 210 Remote Access PASSED All loaded 220 _USR_ORA_DEBUG / CRS FAILED blrraclnx1:? blrraclnx2:? 230 _USR_ORA_DEBUG / ORA FAILED blrraclnx1:? blrraclnx2:? 240 rmem_max PASSED OK 250 UDP Buffer Size PASSED OK 260 wmem_max PASSED OK 270 rmem_default PASSED OK 280 wmem_default PASSED OK 290 Sysrq Magic Keys PASSED OK 300 Oracle Executable Li PASSED linked 310 hangcheck-timer FAILED blrraclnx1:Unknown blrraclnx2:Unknown 320 aio-max-size Setting FAILED blrraclnx1:Unknown blrraclnx2:Unknown 330 Memory (32-bit) PASSED OK 340 Swap (32-bit) FAILED [blrraclnx1:]Swap<2RAM [blrraclnx2:]S..> 350 Swap (64-bit) PASSED OK 360 Patch List PASSED Complete Result file: /home/oracle/rda/output/RDA_HCVE_P400RAC_lnx_res.htm
We can find details about prescribed values at
https://metalink.oracle.com/metalink/plsql/docs/HCVE_P400RAC_lnx.htm
e.g To fix SYS.IDGEN1$ Cache Size, we need to set cache size for sequence SYS.IDGEN1$ greater than or equal to 10,000.
SQL> alter sequence SYS.IDGEN1$ cache 10200; Sequence altered.
Now we see that SYS.IDGEN1$ requirement is passed
132 SYS.IDGEN1$ Cache Si PASSED 10200
Refer Note:250262.1 - RDA 4 - Health Check / Validation Engine Guide for more information on HCVE.
Related Posts
2008-08-26 Tue
mysql> CREATE TABLE `t1` (
-> `col1` tinyint(4) DEFAULT NULL,
-> `id` int(11) NOT NULL DEFAULT '0' COMMENT 'min=1,max=65535',
-> PRIMARY KEY (`id`)
-> ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Query OK, 0 rows affected (0.00 sec)
mysql> alter table t1 drop column id,
-> add column id int auto_increment primary key;
ERROR 1089 (HY000): Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys
This is a regression in 5.0 (and 5.1, I didn't try 6) that was reported almost one year ago. This alter table works just fine in 4.1 and there isn't any reason it should complain about 'prefix index length' when there are no prefix indexes involved.
Ask MySQL to fix this regression in 5.0 before 5.1 GA.
http://bugs.mysql.com/bug.php?id=31031
Can't get enough cloud computing? Then you must really be a glutton for punishment! But just in case, here are some cloud computing resources, collected from various sources, that will help you transform into a Tesla silently flying solo down the diamond lane.
Meta Sources
Specific Blogs
Many more below the fold.
2008-08-25 Mon
As part of a project of Technocation, Inc I took a whole bunch of videos at OSCon 2008. The conference was about a month ago, and about 2 weeks ago I’d finished processing and uploading all the videos, but it was only today where I had the 5-6 hours I needed to finish posting all the video, and making this matrix of video.
The video may not be the quality that the O’Reilly folks took and put up on blip tv’s OSCon site, but all the videos here are freely downloadable or playable in your browser.