String concatenation aggregation methods

This article describes method to aggregate and concatenate strings.

CREATE TABLE test_tbl
(
 grp_id   NUMBER,
 elm_id   NUMBER,
 elm_name VARCHAR2(25)
);

INSERT INTO test_tbl
SELECT 1, LEVEL, 'my name 1_'||LEVEL 
FROM dual 
CONNECT BY level < 5;

INSERT INTO test_tbl
SELECT 2, LEVEL, 'my name 2_'||LEVEL
FROM dual
CONNECT BY LEVEL < 5;

INSERT INTO test_tbl
SELECT 3, LEVEL, 'my name 3_'||LEVEL
FROM dual
CONNECT BY LEVEL < 1001;

COMMIT;

We have following data

SELECT * FROM test_tbl
ORDER BY 1, 2;

    GRP_ID     ELM_ID ELM_NAME                
---------- ---------- -------------------------
         1          1 my name 1_1              
         1          2 my name 1_2              
         1          3 my name 1_3              
         1          4 my name 1_4              
         2          1 my name 2_1              
         2          2 my name 2_2              
         2          3 my name 2_3              
         2          4 my name 2_4
         3          1 my name 3_1              
...
         3       1000 my name 3_1000

and purpose is to covert it to following layout

TEST_ID  CONVERTED
-------- ------------------------------------------------
      1  my name 1_1,my name 1_2,my name 1_3,my name 1_4
      2  my name 2_1,my name 2_2,my name 2_3,my name 2_4
      3  my name 3_1,...                    ,my name 3_1000

Continue reading

Status in AUD$ ACTION#

If you want to filter and analyze your audit data from AUD$ table you need to scan data using ACTION# column. It keeps information about audit actions but is NUMERIC columns. To find out meaning of the column check AUDIT_ACTIONS table

So using simple join between AUD# and AUDIT_ACTIONS tables filter data as you want

SELECT *
  FROM sys.aud$
 WHERE ntimestamp# > SYSDATE - 7
  AND action# IN (
        SELECT action 
          FROM audit_actions
        WHERE name IN 
          ('ALTER USER',
           'CREATE USER',
           'DROP USER'));

List of all audit actions

SELECT action, name 
  FROM audit_actions
ORDER BY 1;

Continue reading

Patch terminology in Oracle databases

This article in short explain patch terminology used by Oracle.

New Name Old Name Description
Interim Patch PSE, MLR, Exception release, One-Off, x-fix, Hotfix, Security One-Off A patch containing one or more fixes made available to customers who cannot wait until the next patch set or new product release to get a fix.
Diagnostic Patch Diagnostic Patch, test Patch, Fix Verification Binary (FVB), e-fix An interim patch created specifically to diagnose a problem and not to fix a bug.
Bundle Patch Maintenance Pack, Service Pack, MLRs, Cumulative Patch, Update Release, Bundle Patch An iterative, cumulative patch that is issued between patch sets. Bundle patches usually include only fixes, but some may include minor enhancements. Examples are the Database Windows Bundles and SOA Bundle Patches.
Patch Set Update (PSU)
Patch Set Update (PSU) A quarterly patch that contains the most critical fixes for the applicable product, allowing customers to apply one patch to avoid many problems.
Security Patch Update (SPU)
Critical Patch Update (CPU) An iterative, cumulative patch consisting of security fixes. Formerly known as Critical Patch Update.Note that the program name which delivers SPUs will still be called Critical Patch Update, as defined below:

Oracle’s program for quarterly release of security fixes. Patches released as part of this program may be Patch Set Updates, Security Patch Updates, and Bundle Patches. Regardless of the patch type, the patches are cumulative.

 

Have a fun 🙂
Tomasz

Finding source code in Oracle

Finding source code written by a developer is typical task executed by a DBA or a developer.

Generally there are two basic methods to get source code:

  • select code from dictionary views – quick, simple, can return part of code, complicated to generate properly DDL
  • generate code using DBMS_METADATA package – very powerful, returns full code, easy to generate DDL code

Continue reading

NOLOGGING and recovery in Oracle

In Oracle Database NOLOGGING option used together with DIRECT mode speeds up transactions executed in a database because it limits information that Oracle writes about such transactions into redo logs and finally impacts size of generated archivelogs.

unrecoverable_transactions_1

That’s because Oracle just writes basic information about executed transaction without modified data to redo logs. Such transactions are called UNRECOVERABLE because in case of database recovery archivelogs don’t have real data only informations about executed transactions.

It can impact later restores and this article shows it.

Continue reading

SWITCHOVER, FAILOVER physical standby database Oracle Database 12C release 1 (12.1)

This article presents SWITCHOVER and FAILOVER methods available for physical standby database in Oracle Database 12C release 1.

This article is based on following article: Configure physical standby database Oracle Database 12C release 1 (12.1)

Optional step – Turn on flashback logs on standby and primary database

  • Flashback on primary – Useful however not necessary to test FAILOVER. It allows to restore previous primary database to consistent state just before FAILOVER so it can be used as standby again
--primary database
SYS@ORA12C> 
ALTER DATABASE FLASHBACK ON;

SELECT flashback_on
FROM v$database;

FLASHBACK_ON
------------------
YES
  • Flashback on standby – enables to switch standby database to READ WRITE. Standby database still receives changes from primary database but doesn’t apply them as long as standby work in READ WRITE mode. To turn flashback on standby database recover process must be turned off.
--standby database
SYS@SORA12C> 

--cancel recovery mode and turn on flashback log
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
ALTER DATABASE FLASHBACK ON;

SELECT flashback_on
FROM v$database;

FLASHBACK_ON
------------------
YES

--restore recovery mode
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE 
DISCONNECT FROM SESSION;

Continue reading