print_table

Just do underline : this is not mine, it was developed and published by Tome Kyte here:

link

I just post it there in case world finishes and asktom dissapears:

create or replace procedure print_table( p_query in varchar2 )
AUTHID CURRENT_USER
is
l_theCursor integer default dbms_sql.open_cursor;
l_columnValue varchar2(4000);
l_status integer;
l_descTbl dbms_sql.desc_tab;
l_colCnt number;
begin
execute immediate
'alter session set
nls_date_format=''dd-mon-yyyy hh24:mi:ss'' ';

dbms_sql.parse( l_theCursor, p_query, dbms_sql.native );
dbms_sql.describe_columns
( l_theCursor, l_colCnt, l_descTbl );

for i in 1 .. l_colCnt loop
dbms_sql.define_column
(l_theCursor, i, l_columnValue, 4000);
end loop;

l_status := dbms_sql.execute(l_theCursor);

while ( dbms_sql.fetch_rows(l_theCursor) > 0 ) loop
for i in 1 .. l_colCnt loop
dbms_sql.column_value
( l_theCursor, i, l_columnValue );
dbms_output.put_line
( rpad( l_descTbl(i).col_name, 30 )
|| ': ' ||
l_columnValue );
end loop;
dbms_output.put_line( '-----------------' );
end loop;
execute immediate
'alter session set nls_date_format=''dd-MON-rr'' ';
exception
when others then
execute immediate
'alter session set nls_date_format=''dd-MON-rr'' ';
raise;
end;
/

The above, you would run as:

exec print_table( 'select * from T where a = ''X'' ' );

(note the doubling of the quotes for character string constants!!)

In Oracle8.0 and before, I use this sqlplus script instead:

declare
l_theCursor integer default dbms_sql.open_cursor;
l_columnValue varchar2(4000);
l_status integer;
l_descTbl dbms_sql.desc_tab;
l_colCnt number;

procedure execute_immediate( p_sql in varchar2 )
is
BEGIN
dbms_sql.parse(l_theCursor,p_sql,dbms_sql.native);
l_status := dbms_sql.execute(l_theCursor);
END;
begin
execute_immediate( 'alter session set nls_date_format=
''dd-mon-yyyy hh24:mi:ss'' ');
dbms_sql.parse( l_theCursor,
replace( '&1', '"', ''''),
dbms_sql.native );

dbms_sql.describe_columns( l_theCursor,
l_colCnt, l_descTbl );

for i in 1 .. l_colCnt loop
dbms_sql.define_column( l_theCursor, i,
l_columnValue, 4000 );

end loop;

l_status := dbms_sql.execute(l_theCursor);

while ( dbms_sql.fetch_rows(l_theCursor) > 0 ) loop
for i in 1 .. l_colCnt loop
dbms_sql.column_value( l_theCursor, i,
l_columnValue );
dbms_output.put_line
( rpad( l_descTbl(i).col_name,
30 ) || ': ' || l_columnValue );
end loop;
dbms_output.put_line( '-----------------' );
end loop;
execute_immediate( 'alter session set nls_date_format=
''dd-MON-yy'' ');
exception
when others then
execute_immediate( 'alter session set
nls_date_format=''dd-MON-yy'' ');
raise;
end;
/

Install AsmLib on Oracle Linux 7

There is a slight change of how to install Asmlib on OL7 comparing to previous versions of linux. Before we use e.g. oracleasmlib-2.0.4-1.el5.i386.rpm install plus oracleasmlib-support.
In OL7 when we tries this, OS wont be able to load module.

To fix it :
yum install kmod-oracleasm
yum install oracleasm-support

Golde Gate – Full schema replication

We have two servers with Oracle 12c installed there, database and gg installed:

gg1.com, database gg1, GG HOME: /u01/app/oracle/product/ogg_src

gg2.com, database gg2, GG HOME: /u01/app/oracle/product/ogg_trg

SOURCE DB PREPARATION:

  1. Turn on archivelog
  2. alter database add supplemental log data;
  3. alter system set recyclebin=off
  4. Create golden gate schema:
    1. create user man_gg_src identified by oracle default tablespace gg_tbs quota unlimited on gg_tbs;
    2. grant CREATE SESSION, CONNECT, RESOURCE, ALTER ANY TABLE, ALTER SYSTEM, CREATE TABLE, DBA, LOCK ANY TABLE, SELECT ANY TRANSACTION, FLASHBACK ANY TABLE to man_gg_src;
    3. grant execute on utl_file to man_gg_src;
    4. @$GG_HOME/marker_setup.sql
    5. @$GG_HOME/ddl_setup.sql
    6. @$GG_HOME/role_setup.sql
    7. grant GGS_GGSUSER_ROLE to man_gg_src;
    8. @$GG_HOME/ddl_enable.sql
    9. $./ggsciGGSCI  1> EDIT PARAMS ./GLOBALS

      GGSCHEMA MAN_GG_SRC

    10. Create source schema (the one that will be replicated to target):
      1. create user source identified by source default tablespace users temporary tablespace temp;
      2. grant connect,resource,unlimited tablespace to source;
    11. Start manager :
      1. GGSCI (gg1.com) 3> start manager
        Manager started.
    12. Create LOCAL EXTRACT:
      1. [oracle@gg1 dirprm]$ cat lext1.prm
        extract lext1
        userid MAN_GG_SRC, password radek01
        exttrail /u01/app/oracle/product/ogg_src/dirdat/le
        ddl include mapped objname source.*;
        table source.*;
      2. GGSCI (gg1.com as MAN_GG_SRC@gg1) 7> ADD SCHEMATRANDATA source2016-06-23 12:50:20 INFO OGG-01788 SCHEMATRANDATA has been added on schema source.

        2016-06-23 12:50:21 INFO OGG-01976 SCHEMATRANDATA for scheduling columns has been added on schema source.

        GGSCI (gg1.com as MAN_GG_SRC@gg1) 9> add extract lext1, tranlog, begin now
        EXTRACT added.

        GGSCI (gg1.com as MAN_GG_SRC@gg1) 12> add exttrail /u01/app/oracle/product/ogg_src/dirdat/le, extract lext1
        EXTTRAIL added.

    13. Create DATAPUMP extract
      1. [oracle@gg1 dirprm]$ cat pump*
        EXTRACT pump1
        USERID MAN_GG_SRC, PASSWORD radek01
        RMTHOST gg2, MGRPORT 7809
        RMTTRAIL /u01/app/oracle/product/ogg_trg/dirdat/le
        PASSTHRU
        table source.*;
      2. GGSCI (gg1.com as MAN_GG_SRC@gg1) 14> add extract pump1, exttrailsource /u01/app/oracle/product/ogg_src/dirdat/le, begin now
        EXTRACT added.add rmttrail /u01/app/oracle/product/gg/dirdat/le, extract pump1

DESTINATION DB PREPARATION:

  1. Create user target
  2. Modify mgr.prm adding line

PORT 7809
ACCESSRULE, PROG *, IPADDR <SRC IP ADDRESS>, ALLOW

  1. GGSCI  4> EDIT PARAMS ./GLOBALS
    CHECKPOINTTABLE     target.checkpoint
  2. Restart manager
  3. GGSCI  5> dblogin userid target
    Password:
    Successfully logged into database.GGSCI  6> add checkpointtable target.checkpoint

    Successfully created checkpoint table target.checkpoint.

  4. [oracle@gg2 dirprm]$ cat rep*
    REPLICAT rep1
    ASSUMETARGETDEFS
    USERID target, PASSWORD radek01
    discardfile /u01/app/oracle/product/ogg_trg/rep1_discard.txt, append, megabytes 100
    map source.*, target target.*;
  5. add replicat rep1, exttrail /u01/app/oracle/product/gg/dirdat/le, begin now

First Golden Gate run – Data Pump (2)

  1. Start/check manager on destination node
    GGSCI (gg2.com) 2> dblogin userid system password radek01
    Successfully logged into database.
    GGSCI (gg2.com as system@gg2) 3> info manager
    Manager is running (IP port gg2.com.7809, Process ID 49037).
  2. Create parameter file on source node
    [oracle@gg1 dirprm]$ cat pemant1.prm
    Extract PEMANT1
    ——————————————————————-
    — Data Pump for MAN_GG_SRC.T1
    ——————————————————————-
    PassThru
    RmtHost gg2.com, MgrPort 7809
    RmtTrail dirdat/le
    Table MAN_GG_SRC.T1 ;
  3. Start data pump extract:
    GGSCI (gg1.com as system@gg1) 2> add extract pemant1 exttrailsource dirdat/le
    EXTRACT added.
    GGSCI (gg1.com as system@gg1) 3> ADD RMTTRAIL dirdat/le, EXTRACT pemant1, megabytes 100
    RMTTRAIL added.
    GGSCI (gg1.com as system@gg1) 4> start extract pemant1
    Sending START request to MANAGER …
    EXTRACT PEMANT1 starting
    GGSCI (gg1.com as system@gg1) 5> info extract pemant1
    EXTRACT PEMANT1 Last Started 2016-06-22 23:36 Status RUNNING
    Checkpoint Lag 00:00:00 (updated 00:06:18 ago)
    Process ID 117381
    Log Read Checkpoint File dirdat/le000000000
    First Record RBA 0

First Golden Gate run – Direct Initial Load (3)

  1. This is initial load that bypass any trail files, it extract data from source db and load it directly to destination.
  2. Create destination user:
    SQL> create user man_gg_dst identified by radek01 default tablespace users;
    User created.
    SQL> grant create session to man_gg_dst;
    Grant succeeded.
    SQL> alter user man_gg_dst quota unlimited on users;
    User altered.
    SQL> grant create table to man_gg_dst;
    Grant succeeded.
    SQL>
  3. Create inital load extract
    [oracle@gg1 dirprm]$ cat iemant1.prm
    ——————————————————————-
    — Initial Load of *MANT1
    ——————————————————————-
    Extract IEMANT1
    SETENV (NLS_LANG = AMERICAN_AMERICA.WE8MSWIN1252)
    USERID system@gg1, PASSWORD radek01
    RmtHost gg2.com, mgrport 7809
    RmtTask Replicat, Group DEMANT1
    Table MAN_GG_SRC.T1;
  4. Create initial load replicat:
    [oracle@gg2 dirprm]$ cat dem*
    Replicat DEMANT1
    ——————————————————————-
    — Initial load replicat for MAN_GG_SRC.T1
    ——————————————————————-
    SETENV (NLS_LANG = AMERICAN_AMERICA.WE8MSWIN1252)
    USERID system@gg2, PASSWORD radek01
    AssumeTargetDefs
    Map MAN_GG_SRC.T1, Target MAN_GG_DST.T1 ;
    GGSCI (gg2.com) 1> dblogin userid system password radek01
    Successfully logged into database.
    GGSCI (gg2.com as system@gg2) 2> ADD REPLICAT DEMANT1, SPECIALRUN
    REPLICAT added.
  5. Start Initial Load extract
    GGSCI (gg1.com as system@gg1) 13> start extract iemant1
    Sending START request to MANAGER …
    EXTRACT IEMANT1 starting
  6. If there is an error like this in ggserr.log
     ERROR   OGG-01201  Oracle GoldenGate Capture for Oracle, iemant1.prm:  Error reported by MGR : Access denied.

    there is a need to modify manager settings on destination adding this:

    [oracle@gg2 dirprm]$ cat mgr*
    PORT 7809
    ACCESSRULE, PROG *, IPADDR 192.168.78.66, ALLOW
  7. and restart manager on destination, than start extract iemant1
  8. When finish, check report for details:
    view report DEMANT1

First Golden Gate run – Setup LOCAL EXTRACT (1)

I have two vm : Oracle Linux 7, 12c databases installed on both with one instance on each:

server1: gg1.com. instance gg1, GG HOME: /u01/app/oracle/product/ogg_src

server2: gg2.com. instance gg2, GG HOME: /u01/app/oracle/product/ogg_trg

 

  1. Create sample user and table on source:
    SQL> create user man_gg_src identified by gg01 default tablespace users;
    User created.
    SQL> alter system set enable_goldengate_replication=true;
    System altered.
    SQL> grant create session to man_gg_src;
    Grant succeeded.
    SQL> grant create table to man_gg_src;
    Grant succeeded.
    SQL> alter user man_gg_src quota unlimited on users;
    User altered.
    SQL> grant select any dictionary to man_gg_src;
    Grant succeeded.
    SQL> conn man_gg_src/gg01
    Connected.
    SQL> create table t1 as select * from dba_tables where rownum<1;
    Table created.
    SQL> select count(*) from t1;
    COUNT(*)
    ———-
    0
    SQL> alter table t1 add primary key (owner, table_name);
    Table altered.
  2. Enable Database-Level Suplemental Logging:
    [oracle@gg1 ogg_src]$ sqlplus “/ as sysdba”
    SQL*Plus: Release 12.1.0.2.0 Production on Wed Jun 22 13:24:40 2016
    Copyright (c) 1982, 2014, Oracle. All rights reserved.
    Connected to:
    Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 – 64bit Production
    With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
    SQL> SELECT SUPPLEMENTAL_LOG_DATA_MIN FROM V$DATABASE;
    SUPPLEME
    ——–
    NO
    SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
    Database altered.
    SQL> SELECT SUPPLEMENTAL_LOG_DATA_MIN FROM V$DATABASE;
    SUPPLEME
    ——–
    YES
  3. Enable Table-Level Suplemental Logging:
    [oracle@gg1 ogg_src]$ ggsci
    Oracle GoldenGate Command Interpreter for Oracle
    Version 12.2.0.1.1 OGGCORE_12.2.0.1.0_PLATFORMS_151211.1401_FBO
    Linux, x64, 64bit (optimized), Oracle 12c on Dec 12 2015 02:56:48
    Operating system character set identified as UTF-8.
    Copyright (C) 1995, 2015, Oracle and/or its affiliates. All rights reserved.
    GGSCI (gg1.com) 1> dblogin userid system password radek01
    Successfully logged into database.
    GGSCI (gg1.com as system@gg1) 3> add trandata man_gg_src.t1
    Logging of supplemental redo data enabled for table MAN_GG_SRC.T1.
    TRANDATA for scheduling columns has been added on table ‘MAN_GG_SRC.T1’.
    TRANDATA for instantiation CSN has been added on table ‘MAN_GG_SRC.T1’.
    GGSCI (gg1.com as system@gg1)
  4. Start manager:
    GGSCI (gg1.com as system@gg1) 5> info manager
    Manager is DOWN!
    GGSCI (gg1.com as system@gg1) 6> start manager
    Manager started.
    GGSCI (gg1.com as system@gg1) 7> info manager
    Manager is running (IP port gg1.com.7809, Process ID 101205).
  5.  Create Local Extract parameter file
    [oracle@gg1 dirprm]$ pwd
    /u01/app/oracle/product/ogg_src/dirprm
    [oracle@gg1 dirprm]$ cat lemant1.prm
    ——————————————————————-
    — Local extract for MAN_GG_SRC.T1 table
    ——————————————————————-
    Extract LEMANT1
    SETENV (NLS_LANG = AMERICAN_AMERICA.WE8MSWIN1252)
    SETENV (ORACLE_HOME = “/u01/app/oracle/product/12.1.0/dbhome_1”)
    SETENV (ORACLE_SID = gg1)
    USERID system@gg1, PASSWORD radek01
    ExtTrail dirdat/le
    Table MAN_GG_SRC.T1;
  6. Adding Local Extract and Local Extrail
    [oracle@gg1 ogg_src]$ ggsci
    Oracle GoldenGate Command Interpreter for Oracle
    Version 12.2.0.1.1 OGGCORE_12.2.0.1.0_PLATFORMS_151211.1401_FBO
    Linux, x64, 64bit (optimized), Oracle 12c on Dec 12 2015 02:56:48
    Operating system character set identified as UTF-8.
    Copyright (C) 1995, 2015, Oracle and/or its affiliates. All rights reserved.
    GGSCI (gg1.com) 1> dblogin userid system password radek01
    Successfully logged into database.
    GGSCI (gg1.com as system@gg1) 2> add extract lemant1, tranlog, begin now
    EXTRACT added.
    GGSCI (gg1.com as system@gg1) 3> add exttrail dirdat/le, extract lemant1, megabytes 100
    EXTTRAIL added.
    GGSCI (gg1.com as system@gg1) 4>
  7. Run Local Extract
    GGSCI (gg1.com as system@gg1) 17> start extract lemant1
    Sending START request to MANAGER …
    EXTRACT LEMANT1 starting
    GGSCI (gg1.com as system@gg1) 18> info extract lemant1
    EXTRACT LEMANT1 Last Started 2016-06-22 15:39 Status RUNNING
    Checkpoint Lag 00:25:09 (updated 00:00:00 ago)
    Process ID 104316
    Log Read Checkpoint Oracle Redo Logs
    2016-06-22 15:13:53 Seqno 16, RBA 12107280
    SCN 0.0 (0)

 

 

 

How to install ORACLE TEXT to existing database

dbca -silent -configureDatabase  -SourceDB etransd -sysDBAUsername sys -sysDBAPassword dbpwd -addDBOption ORACLE_TEXT

Preparing to Configure Database
4% complete
8% complete
40% complete
Adding Oracle Text
44% complete
45% complete
46% complete
47% complete
48% complete
49% complete
50% complete
70% complete
80% complete
Completing Database Configuration
100% complete

Adaptive cursor sharing

create table t1_cs (id number, val1 varchar2(50);

SQL>
declare
val1 varchar2(10);
begin
for i in 1..101000 loop
if mod(i,2)=0 then
val1 := ‘A’;
else
val1 := ‘B’;
end if;
insert into T1_CS values(i,val1);
end loop;
commit;
end;
/

PL/SQL procedure successfully completed.

SQL> insert into t1_cs values(1001,’C’);

1 row created.

SQL> commit;

Commit complete.
SQL> create index t1_cs_idx on t1_cs(val1);

Index created.

SQL> exec dbms_stats.gather_table_stats(ownname=>’SYS’,tabname=>’T1_CS’,method_opt=>’FOR ALL COLUMNS SIZE 254′,estimate_percent=>100);

SQL> select distinct val1, count(*) from t1_cs group by val1;

VAL1 COUNT(*)
————————————————– ———-
B 50500
A 50500
C 1

PL/SQL procedure successfully completed.

SQL> SELECT column_name, histogram FROM user_tab_cols WHERE table_name = ‘T1_CS’;

COLUMN_NAM HISTOGRAM
———- —————
ID FREQUENCY
VAL1 HEIGHT BALANCED
NO BIND VARIABLES:
++++++++++++++++++

SQL> select max(id) from t1_cs where val1=’B’;

MAX(ID)
———-
99999

SQL> select * from table(dbms_xplan.display_cursor);

PLAN_TABLE_OUTPUT
————————————————————————————————————————————————————————————————————————————————————————————————————
SQL_ID cchzuth7d6zy0, child number 1
————————————-
select max(id) from t1_cs where val1=:”SYS_B_0″

Plan hash value: 1405449973

—————————————————————————-
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
—————————————————————————-
| 0 | SELECT STATEMENT | | | | 43 (100)| |
| 1 | SORT AGGREGATE | | 1 | 7 | | |
|* 2 | TABLE ACCESS FULL| T1_CS | 50500 | 345K| 43 (38)| 00:00:01 |
—————————————————————————-

Predicate Information (identified by operation id):
—————————————————

2 – filter(“VAL1″=:SYS_B_0)
———————————————————-
SQL> select max(id) from t1_cs where val1=’C’;

MAX(ID)
———-
1001

SQL> select * from table(dbms_xplan.display_cursor);

PLAN_TABLE_OUTPUT
————————————————————————————————————————————————————————————————————————————————————————————————————
SQL_ID cchzuth7d6zy0, child number 2
————————————-
select max(id) from t1_cs where val1=:”SYS_B_0”

Plan hash value: 3509633565

————————————————————————————————–
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
————————————————————————————————–
| 0 | SELECT STATEMENT | | | | 2 (100)| |
| 1 | SORT AGGREGATE | | 1 | 7 | | |
| 2 | TABLE ACCESS BY INDEX ROWID BATCHED| T1_CS | 1 | 7 | 2 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN | T1_CS_IDX | 1 | | 1 (0)| 00:00:01 |
————————————————————————————————–

Predicate Information (identified by operation id):
—————————————————

3 – access(“VAL1″=:SYS_B_0)
++++++++++++++++++++++++++++++++++++++++++++++++++
BIND VARIABLES :
++++++++++++++++++++++++++++++++++++++++++++++++++

SQL> variable var_bind varchar2;
SQL> exec :var_bind := ‘A’;

PL/SQL procedure successfully completed.

SQL> select max(id) from t1_cs where val1=:var_bind;

MAX(ID)
———-
100000

SQL> select * from table(dbms_xplan.display_cursor);

PLAN_TABLE_OUTPUT
————————————————————————————————————————————————————————————————————————————————————————————————————
SQL_ID a18jhjcy0djku, child number 0
————————————-
select max(id) from t1_cs where val1=:var_bind

Plan hash value: 1405449973

—————————————————————————-
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
—————————————————————————-
| 0 | SELECT STATEMENT | | | | 43 (100)| |
| 1 | SORT AGGREGATE | | 1 | 7 | | |
|* 2 | TABLE ACCESS FULL| T1_CS | 50500 | 345K| 43 (38)| 00:00:01 |
—————————————————————————-

Predicate Information (identified by operation id):
—————————————————

2 – filter(“VAL1″=:VAR_BIND)
SQL> SELECT sql_id, child_number, is_bind_sensitive, is_bind_aware
FROM v$sql
WHERE sql_id=’a18jhjcy0djku’;

SQL_ID CHILD_NUMBER I I
————- ———— – –
a18jhjcy0djku 0 Y N

is_bind_sensitive : optimizer knows it may be required to reoptimize due to binds…..
is_bind_aware : but haven’t done it yet
SQL> variable var_bind varchar2;
SQL> exec :var_bind := ‘C’;

PL/SQL procedure successfully completed.

SQL> select max(id) from t1_cs where val1=:var_bind;

MAX(ID)
———-
1001

SQL> select * from table(dbms_xplan.display_cursor);

PLAN_TABLE_OUTPUT
————————————————————————————————————————————————————————————————————————————————————————————————————
SQL_ID a18jhjcy0djku, child number 1
————————————-
select max(id) from t1_cs where val1=:var_bind

Plan hash value: 3509633565

————————————————————————————————–
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
————————————————————————————————–
| 0 | SELECT STATEMENT | | | | 2 (100)| |
| 1 | SORT AGGREGATE | | 1 | 7 | | |
| 2 | TABLE ACCESS BY INDEX ROWID BATCHED| T1_CS | 1 | 7 | 2 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN | T1_CS_IDX | 1 | | 1 (0)| 00:00:01 |
————————————————————————————————–

Predicate Information (identified by operation id):
—————————————————

3 – access(“VAL1″=:VAR_BIND)
SQL> SELECT sql_id, child_number, is_bind_sensitive, is_bind_aware
FROM v$sql
WHERE sql_id=’a18jhjcy0djku’; 2 3

SQL_ID CHILD_NUMBER I I
————- ———— – –
a18jhjcy0djku 0 Y N
a18jhjcy0djku 1 Y Y

SQL> SELECT * FROM v$sql_cs_selectivity WHERE sql_id = ‘a18jhjcy0djku’;

ADDRESS HASH_VALUE SQL_ID CHILD_NUMBER PREDICATE RANGE_ID LOW HIGH CON_ID
—————- ———- ————- ———— —————————————- ———- ———- ———- ———-
00000000B1B17EA8 1007076954 a18jhjcy0djku 1 =VAR_BIND 0 0.000009 0.000011 0

Manual plan evolution in 12c

Lets assume we want manualy evolve one of plan, which was added to SPM, but is not accepted

First we need to get know sql_handle and plan_name

SQL> select sql_handle,plan_name,created,enabled,accepted,fixed,adaptive
2 from DBA_SQL_PLAN_BASELINES
3 where sql_text like ‘SELECT PDKCOO, PDDOCO, PDDCTO, PDSFXO, PDLNID, PDMCU, PDCO, PDOKCO, PDOORN, PDOCTO, PDOGNO, PDRKCO, PDRORN, PDRCTO, PDRLLN, PDDMCT, PDDM%’
4 order by 3 desc
5 ;
SQL_HANDLE PLAN_NAME CREATED ENA ACC FIX ADA
——————– —————————— —————————— — — — —
SQL_7fbbb870b3e43aa7 SQL_PLAN_7zfxsf2ty8fp7eee61a1d 06-JUN-16 04.34.23.000000 AM YES NO NO NO
SQL_f75b2f7d2c3a4191 SQL_PLAN_gfqtggnq3nhcj685a7485 06-JUN-16 03.55.59.000000 AM YES YES NO NO
SQL_d5f9729283e89e27 SQL_PLAN_dbybkka1yj7j77e3e220c 06-JUN-16 03.53.54.000000 AM YES NO NO NO

Now we need to do 3 steps:

Create evolving task:

SQL> variable tsk_name varchar2(50)
SQL> variable exec_name varchar2(50)
SQL> execute :tsk_name := dbms_spm.create_evolve_task(sql_handle=>’SQL_7fbbb870b3e43aa7′,plan_name=>’SQL_PLAN_7zfxsf2ty8fp7eee61a1d’);
PL/SQL procedure successfully completed.

Execute task:

SQL> execute :exec_name := dbms_spm.execute_evolve_task(task_name=>:tsk_name);
PL/SQL procedure successfully completed.

Show result:

declare
c_out clob;
begin
c_out := dbms_spm.report_evolve_task(task_name=>’TASK_5461′,type=>’TEXT’,execution_name=>’EXEC_5614′);
dbms_output.put_line(c_out);
end;
/
begin
dbms_spm.accept_sql_plan_baseline(task_name=>:tsk_name, object_id=><>, task_owner=><>);
end
/