Thursday, August 30, 2012

Convert Comma delimited String into Rows

SELECT    REGEXP_SUBSTR(STR, '[^,]+', 1, LEVEL) WORDS
FROM       (SELECT 'AA,BB,CC,A,B,C'STR FROM DUAL)
CONNECT BY REGEXP_SUBSTR(STR, '[^,]+', 1, LEVEL) IS NOT NULL

Tuesday, August 21, 2012

Duplicate Rows

Select Duplicate rows only

SELECT * FROM  SB_TEST1 A
WHERE  ROWID > (SELECT MIN(ROWID) FROM SB_TEST1 B
                WHERE A.A=B.A)

SELECT *
FROM   SB_TEST1
WHERE  ROWID NOT IN (SELECT MAX(ROWID) FROM SB_TEST1 GROUP BY A)
  


Select all rows which considered having duplicate
 

SELECT *
FROM   SB_TEST1
WHERE  A IN (SELECT A FROM SB_TEST1
GROUP BY A HAVING COUNT (*) >1)

Friday, April 29, 2011

Find Decimal Part

SELECT REGEXP_SUBSTR(99999.0123456789, '[[:digit:]]+$')
FROM DUAL


--------------------------------------------------------------------------------
SELECT REGEXP_SUBSTR(TO_CHAR(99999.0123456789,'999999999.9999999999'), '[[:digit:]]+$')
FROM DUAL

Wednesday, January 19, 2011

Amount to Words by Rupees


Order of Trigger Firing

  • Before Statement trigger (If present)
  • Each row affected by the statement
    (a) Execute row level trigger (If present)
    (b) Execute the statement itself
    (c) Execute the after row level trigger (If Present)
  • After statement trigger (If Present)

Predefined Exceptions



An internal exception is raised automatically if your PL/SQL program violates an Oracle rule or exceeds a system-dependent limit. PL/SQL predefines some common Oracle errors as exceptions. For example, PL/SQL raises the predefined exception NO_DATA_FOUND if a SELECT INTO statement returns no rows.You can use the pragma EXCEPTION_INIT to associate exception names with other Oracle error codes that you can anticipate. To handle unexpected Oracle errors, you can use the OTHERS handler. Within this handler, you can call the functions SQLCODE and SQLERRM to return the Oracle error code and message text. Once you know the error code, you can use it with pragma EXCEPTION_INIT and write a handler specifically for that error.PL/SQL declares predefined exceptions globally in package STANDARD. You need not declare them yourself. Can wirte handlers for predefined exceptions by using the SQLCODE.
ZERO_DIVIDE -A program attempts to divide a number by zero.
VALUE_ERROR- An arithmetic, conversion, truncation, or size-constraint error occurs. For example, when your program selects a column value into a character variable, if the value is longer than the declared length of the variable, PL/SQL aborts the assignment and raises VALUE_ERROR. In procedural statements, VALUE_ERROR is raised if the conversion of a character string into a number fails. (In SQL statements, INVALID_NUMBER is raised.)

Wednesday, December 15, 2010

Where Current OF

  • If you plan on updating or deleting records that have been referenced by a Select For Update statement, you can use the Where Current Of statement.
  • When the session opens a cursor with the FOR UPDATE clause, all rowsin the return set will hold row-level exculsive locks. Other sessions can only query the rows, but they cannot update, delete, or select withFOR UPDATE.
  • Allows the developer to lock a set of Oracle rows for the duration of a transaction
  • Subqueries cannot have this clause