'My Works/Oracle'에 해당되는 글 40건

  1. 2010.06.10 [ORACLE] connect by 로 결과값 가로로 펼치기
  2. 2010.05.25 [ORACLE] EXEMPT ACCESS POLICY
  3. 2010.04.19 [ORACLE] CLOB -> BLOB function
  4. 2010.04.19 [ORACLE] LONG RAW -> BLOB -> CLOB
  5. 2010.04.12 [ORACLE] on update cascade - asktom
  6. 2010.04.09 [ORACLE] Upgrading from 9i to 11g and the implicit migration from RBO - Optimizer Dev Grp
  7. 2010.04.06 [ORACLE] How to CANCEL a query running in another session? - Tonel Poder
  8. 2010.04.01 [ORACLE] SQL*Plus 내의 copy 명령어
  9. 2010.03.11 [ORACLE] 숫자가 포함된 row 찾고자 할때
  10. 2010.03.11 [ORACLE] ORA-01841 발생 케이스 - Cause 이외

[ORACLE] connect by 로 결과값 가로로 펼치기

|
column viewname format a100

with tab
as
(
select '0001' code, 'A' name from dual union all
select '0001' code, 'B' name from dual union all
select '0001' code, 'C' name from dual union all
select '0002' code, 'D' name from dual union all
select '0002' code, 'A' name from dual union all
select '0003' code, 'F' name from dual union all
select '0003' code, 'E' name from dual union all
select '0003' code, 'B' name from dual union all
select '0003' code, 'C' name from dual
)
select x.code
      ,substr(max(sys_connect_by_path(x.name,', ')),2) viewname
  from (
       select code
             ,name
             ,row_number() over (partition by code order by code ,name) rn
         from tab
       ) x
 start with x.rn = 1
connect by prior x.code = x.code
   and prior x.rn = x.rn - 1
 group by x.code
/
connect by 앞에서 항상 약해지는 나 ㅡ.ㅜ
with tab
as
(
select '0001' code, 'A' name from dual union all
select '0001' code, 'B' name from dual union all
select '0001' code, 'C' name from dual union all
select '0002' code, 'D' name from dual union all
select '0002' code, 'A' name from dual union all
select '0003' code, 'F' name from dual union all
select '0003' code, 'E' name from dual union all
select '0003' code, 'B' name from dual union all
select '0003' code, 'C' name from dual
)
select x.code
      ,substr(xmlagg(xmlelement(x,' ,',x.name).extract('//text()')),3) viewnames
  from tab x
 group by x.code
/

connect by 안쓰고 같은 효과내는 방법 xml 쿼리도 공부해야겠음 ㅋㅋ
And

[ORACLE] EXEMPT ACCESS POLICY

|
EXEMPT ACCESS POLICY

Bypass fine-grained access control

Caution: This is a very powerful system privilege, as it lets the grantee bypass application-driven security policies. Database administrators should use caution when granting this privilege.

grant exempt access policy to dw;
revoke exempt access policy from dw;
강력하다 -_-;;
And

[ORACLE] CLOB -> BLOB function

|

CREATE OR REPLACE FUNCTION CLOB2BLOB (p_clob in CLOB)
return BLOB
is
-- transforming CLOB a BLOB
p_blob blob;
l_off number default 1;
l_amt number default 4096;
l_offWrite number default 1;
l_amtWrite number;
l_str varchar2(4096 char);
begin
DBMS_LOB.CREATETEMPORARY(p_blob, TRUE);
begin
loop
dbms_lob.read ( p_clob, l_amt, l_off, l_str );

l_amtWrite := utl_raw.length ( utl_raw.cast_to_raw( l_str) );
dbms_lob.write( p_blob, l_amtWrite, l_offWrite,
utl_raw.cast_to_raw( l_str ) );

l_offWrite := l_offWrite + l_amtWrite;

l_off := l_off + l_amt;
l_amt := 4096;
end loop;
exception
when no_data_found then
NULL;
end;
return p_blob;
end CLOB2BLOB;
/

And

[ORACLE] LONG RAW -> BLOB -> CLOB

|
-- long raw -> blob

create table blob_table_name
as
select
         to_lob(long_raw_col) as blob_col
  from long_raw_table_name
/

-- create blob2clob function

CREATE OR REPLACE FUNCTION "BLOB2CLOB" (b IN BLOB)
RETURN CLOB
IS
l_blob blob;
l_clob clob := 'x';
l_dest_offsset integer := 1;
l_src_offsset integer := 1;
l_lang_context integer := dbms_lob.default_lang_ctx;
l_warning integer;
BEGIN
  l_blob := b;
  IF dbms_lob.getlength(b) != 0 THEN
  DBMS_LOB.CONVERTTOCLOB
  ( dest_lob => l_clob
  , src_blob => l_blob
  , amount => dbms_lob.lobmaxsize
  , dest_offset => l_dest_offsset
  , src_offset => l_src_offsset
  , blob_csid => dbms_lob.default_csid
  , lang_context => l_lang_context
  , warning => l_warning
  );
  END IF;
RETURN l_clob;
END BLOB2CLOB;
/

-- blob --> clob

create table clob_table_name
as
select
          blob2clob(blob_col) as clob_col
  from blob_table_name
/
And

[ORACLE] on update cascade - asktom

|

UPDATE CASCADE PACKAGE


Generates needed package and triggers to support update cascade in Oracle without removing or infringing on DECLARITIVE RI.

This package supports:

  • Tables with multi-part primary keys (primary key(a,c,b))
  • Update cascade to many child tables from one parent
  • Self-referencing integrity such as that found in the SCOTT.EMP table (mgr->empno)
  • Is completely application transparent. The application does not know it is happening
  • Versions 7.0 and above of the database.
  • Tuned and optimized to fully avoid full table scans on all tables (complete with utility to show you un-indexed foreign keys in a schema, Cascading an update to un-indexed foreign keys can be bad).
This solution has the following restrictions:
  1. All foreign keys to the parent table must point to the primary key constraint of the parent table. They cannot point to a unique constraint on the parent table, they must point to the primary key.
  2. No other unique constraints/indexes may be in place on the parent table other then the primary key constraint.
  3. Updates to primary keys that do not generate 'new' primary keys are not currently supported. For example, take the standard DEPT table. The update statement "update dept set deptno = deptno+10" will not work whereas the update "update dept set deptno = deptno+1" will. The first update will change 10->20, 20->30 and so on. Problem is that 10->20 is not generating a 'new' primary key. On the other hand, deptno=deptno+1 does not have this problem since 10->11, 20->21 and so on.
    NOTE: an update that affects a single row will never suffer from this problem.
  4. the owner of the parent table must also be the owner of the child tables.
  5. the owner of the parent table must run the following package in their schema. This package must be installed for each user that wants to generate update cascade support. It may be dropped after the cascade support has been generated.
  6. the owner of the parent table must have been granted create procedure and create trigger. these priveleges may not be inherited from a role.

Installing, Using, and seeing how the demo works


This package consists of four SQL scripts
  • uc.sql
  • demobld.sql
  • unindex.sql
  • generate.sql

UC.SQL

UC.SQL should be run by any user wanting to implement update cascade. It will create
  • A package spec for update_cascade
  • A package body for update_cascade
Once this package is installed, you are able to implement update cascade on any table via the pl/sql call:
PROCEDURE update_cascade.on_table
 Argument Name                  Type                    In/Out Default?
 ------------------------------ ----------------------- ------ --------
 P_TABLE_NAME                   VARCHAR2                IN
 P_PRESERVE_ROWID               BOOLEAN                 IN     DEFAULT
 P_USE_DBMS_OUTPUT              BOOLEAN                 IN     DEFAULT
Input Name Default Usage
p-table-name NO DEFAULT is the name of the parent table
p-preserve-rowid TRUE affects the generation of the code used to implement the generated packages. If set to TRUE (the default) the rowid of the updated parent row will not change due to the update. If set to FALSE, the rowid of the updated row WILL change BUT the code executes in about 66% of the time.
p-use-dbms-output FALSE defaults to FALSE which means the update_cascade package will execute (create) the packages/triggers. If set to true, the generated code will be printed using dbms_output.put_line (make sure to set serveroutput on size 100000 before using TRUE if you want to see the code).

For example....
SQL> REM will do the default cascade support on
SQL> REM the dept table
SQL> REM ROWIDS will be preserved (unchanged).
SQL> REM Package will be created in the database
SQL> exec update_cascade.on_table( 'dept' )
SQL> REM will do the same as above but will not
SQL> REM preserve the rowids of the parent table 
SQL> REM (the rowids will change).  This version
SQL> REM runs in about 2/3 of the time of the first
SQL> REM one
SQL> exec update_cascade.on_table( 'dept', false )
SQL> REM will do the same as above but will not
SQL> REM preserve the rowids of the parent table 
SQL> REM (the rowids will change).  This version
SQL> REM runs in about 2/3 of the time of the first
SQL> REM one.  Also, the packages will be written
SQL> REM to the SCREEN, not into the database. 
SQL> exec update_cascade.on_table( 'dept', false, true )
The above would generate and compile all of the packages/triggers need to support cascading updates on the dept table to any other table. You would run this any time you
  • changed the primary key definition of the dept table
  • added a child table to the schema (eg: executed a create table and that table points to dept)
  • removed a child table from schema
NOTE: The user executing update_cascade must have been granted
  • CREATE TRIGGER
  • CREATE PROCEDURE
directly to themselves. They cannot just have the privilege via a role.

The other mode of calling update_cascade.on_table is as follows:

SQL> set feedback off
SQL> spool tmp.sql
SQL> exec update_cascade.on_table( p_table_name => 'dept', p_use_dbms_output =>TRUE )
SQL> spool off
The above would generate and print (as opposed to compile) all of the packages/triggers/views needed to support cascading update on the dept table to any other table. You would use this mode to
  • Avoid having to grant CREATE VIEW, CREATE TRIGGER, CREATE PROCEDURE directly to the person (they can get these priveleges via a role like DBA).
  • To inspect the generated code to understand what it does.
  • To generate a package that can be used to install update cascade support at another site without giving them the update_cascade package itself.

The other mode of calling update_cascade.on_table is as follows:

SQL> exec update_cascade.on_table( p_table_name => 'dept', p_preserve_rowid =>FALSE )
The above would generate faster versions of the udpate cascade packages. They run in 2/3 of the time of the default version but the rowid's of the updated parent records will change. This makes this version less desirable with FORMS. If you use forms heavily, use the default mode so that rowids are preserved. The triggers to cascade can get away with a lot less work in this mode. The triggers fire half the time they would in the default mode and an update that would normally fire and affect 2x the number of rows is not needed. The generated package code is streamlined as well (less actuall code is generated, procedural code not just updates).

DEMOBLD.SQL

This script creates one user and three tables in that users schema. The user is called UCDEMO. WARNING: This script does a "drop user ucdemo cascade". It is run as SYSTEM. Please review it before running it. Modify if you want. Once the script creates the user it will create six tables and populate them. The tables are:
  • DEPT with a primary key
  • EMP with a primar key, DECLARATIVE RI to DEPT, DECLARATIVE RI to EMP
  • PROJECTS with a primary key, DECLARATIVE RI to EMP
  • T1 with a three part primary key
  • T2 with a three part primary key and a three part foreign key to T1
  • T3 with a three part primary key and a three part foreign key to T2
To begin the demo, you might issue:
SQL> update dept set deptno=deptno+1;
update dept set deptno=deptno+1
       *
ERROR at line 1:
ORA-02292: integrity constraint (UCDEMO.SYS_C005184) violated - child record
found
Then to see the update cascade in action, you would:
SQL> @uc
 
Table created.
 
Table altered.
 
Package created.
 
Package body created.
SQL> exec update_cascade.on_table('dept');
 
PL/SQL procedure successfully completed.
 
SQL> 
SQL> select * from dept;
 
    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON
 
SQL> select empno, deptno from emp where deptno = 10;
 
     EMPNO     DEPTNO
---------- ----------
      7839         10
      7782         10
      7934         10
 
SQL> update dept set deptno = deptno+1;
 
4 rows updated.
 
SQL> select * from dept;
 
    DEPTNO DNAME          LOC
---------- -------------- -------------
        11 ACCOUNTING     NEW YORK
        21 RESEARCH       DALLAS
        31 SALES          CHICAGO
        41 OPERATIONS     BOSTON
 
SQL> select empno, deptno from emp where deptno in ( 10, 11 );
 
     EMPNO     DEPTNO
---------- ----------
      7839         11
      7782         11
      7934         11
 
SQL> 
As you can see, after the package is installed, the updates cascade successfully to the child tables. The effect of this is even more dramatic when you do it to the emp table. The MGR column of the EMP table points to the EMPNO column of the EMP table. In addition, the EMPNO column of the PROJECTS table points to the EMPNO column of the EMP table. The following scenario is a good demo of more complex integrity:
SQL> select empno, mgr from emp;
 
     EMPNO        MGR
---------- ----------
      7839
      7698       7839
      7782       7839
      7566       7839
      7499       7698
      7521       7698
      7654       7698
      7902       7566
      7369       7902
      7788       7566
      7844       7698
      7876       7788
      7900       7698
      7934       7782

14 rows selected.

SQL> update emp set empno = 8000 where empno = 7698;
update emp set empno = 8000 where empno = 7698
 *
ERROR at line 1:
ORA-02292: integrity constraint (UCDEMO.SYS_C005186) violated - child record
found
 
 
SQL> exec update_cascade.on_table('emp')
 
PL/SQL procedure successfully completed.
 
SQL> update emp set empno = 8000 where empno = 7698;
 
1 row updated.
 
SQL> select empno, mgr from emp;
 
     EMPNO        MGR
---------- ----------
      7839
      7782       7839
      7566       7839
      7499       8000
      7521       8000
      7654       8000
      7902       7566
      7369       7902
      7788       7566
      7844       8000
      7876       7788
      7900       8000
      7934       7782
      8000       7839
 
14 rows selected.
 

UNINDEX.SQL

The lack of an index on a foreign key will adversely impact the performance of a cascading update. For example, the emp table is created via:
CREATE TABLE EMP
(EMPNO NUMBER(4) primary key,
 ENAME VARCHAR2(10),
 JOB VARCHAR2(9),
 MGR NUMBER(4) references emp,
 HIREDATE DATE,
 SAL NUMBER(7,2),
 COMM NUMBER(7,2),
 DEPTNO NUMBER(2) references dept);

The MGR column and the DEPTNO column are not indexed by default. So, for example, if one were to issue:
SQL> @unindex.sql


STAT TABLE_NAME                     COLUMNS              COLUMNS
---- ------------------------------ -------------------- --------------------
**** EMP                            MGR
ok   EMP                            DEPTNO               DEPTNO
ok   PROJECTS                       EMPNO                EMPNO, PROJ_NO
ok   T2                             A                    A, B
ok   T3                             A, B                 A, B, C
 
SQL> 

The four **** indicate that MGR is a foreign key in the EMP table that is not indexed. It should be (also see chapter 6 in the server application developers guide for other reasons why un-indexed foreign keys are bad).

GENERATE.SQL

This is a simple script that will generate all of the needed update_cascade.on_table( 'table_name' ) statements that need to be executed for all parent tables in a schema. For example, in the demo account it would create a spool file that contains:
SQL> @src="" update_cascade="" generate="" dept="" emp="" t1="" prompt="" update="" cascade="" on="" table:="" execute="" update_cascade.on_table(="" t2="" )="">

HOW it works:


When you update the primary key of a parent table, you might want to cascade the update to the children. This is hard to do for many reasons and can be problematic. This package works around the lack of an update cascade option.

This package uses three triggers to perform it magic.

  • A before update trigger; used to reset some package variables
  • A before update, for each row trigger; used to capture the before and after images of the primary keys in pl/sql tables. It also 'undoes' the update to the primary key.
  • An After update trigger that does the following steps:
    • 'Clones' the parent records with their new primary key, eg: insert into parent select NEW_KEY, other_cols from parent where CURRENT_KEY = ( SELECT OLD_KEY FROM DUAL) for example, given "update dept set deptno=deptno+1", this would insert the values of 11, 21, 31, 41 into the dept table. 11 would have the values in the rest of the columns that 10 had. 21 would look like 20 and so on.
    • If p_preserve_rowids = TRUE, then the primary keys of the row that was cloned and the clone would be flip flopped. For example, if you issue: update dept set deptno = 11 where deptno = 10 we would make 10 become the new value 11 and 11 become the old value 10.
    • Re-Parents the child records in all subordinate tables. Performs the equivalent of: update child set fkey = ( select new_key from DUAL ) where fkey = ( select old_key from DUAL )
    • It then removes the 'cloned' parent records or the record with the old primary key value.

A look at the code

The follow annotated code is the generated packages and triggers you would create by generating support for the dept table.

The following package spec is what would be generated for the typical 'DEPT' table found in the scott schema (when declaritive RI is used). See the annotations in the spec for a description of what each entry means and how it is used. The annotations are not found in the generated code, the generated code is not commented.

This generated code preserves rowids. The code that preserves rowids will be in bold. This code would not be present in the generated package if rowid preservation was disabled.


SQL> exec update_cascade.on_table('dept',true,true);
The following is a typical package specification generated for a table. The package spec name is always u || TABLE_NAME || p. The package name is in mixed case (to prevent collisions with other user objects).
	create or replace package "uDEPTp"
	as
	--
Rowcnt is used to collect the number of rows processed by a given update statement. It is reset in the uDEPTp.reset routine in a before update trigger. The 'inTrigger' variable is used to prevent recursive firing of triggers when p_preserve_rowid = TRUE;
	    rowCnt    number default 0;
	    inTrigger boolean default FALSE;
	--
For each element in the primary key, a table type will be declared and then an array of that type will be declared to 1.) hold the before image, 2.) the after image, and 3.) an empty array used to zero out the previous two arrays.
	    type C1_type is table of "DEPT"."DEPTNO"%type index by binary_integer;
	--
	    empty_C1 C1_type;
	    old_C1   C1_type;
	    new_C1   C1_type;
	--
	--
Reset is the routine fired by the BEFORE UPDATE trigger that resets the rowcnt variable and empties out the arrays from the previous invocation.
	    procedure reset;
	--
Do cascade is the work horse routine. It performs the actual cascade when fired from an AFTER UPDATE trigger.
	    procedure do_cascade;
	--
Add Entry simply increments the rowcnt and collects the before/after images of the primary keys. It also 'undoes' the update to the primary key by accessing the :new and :old variables.
	    procedure add_entry
	    (
	         p_old_C1 in "DEPT"."DEPTNO"%type
	        ,p_new_C1 in out "DEPT"."DEPTNO"%type
	     );
	--
	end "uDEPTp";
/

This is the package body generated. It implements the above specification
	create or replace package body "uDEPTp"
	as
	--
	    procedure reset
	    is
	    begin
	--
This line is present in all routines when p_preserve_rowids = TRUE. It prevents recursive firing of the triggers.
	        if ( inTrigger ) then return; end if;
	--
	        rowCnt := 0;
	        old_C1 := empty_C1;
	        new_C1 := empty_C1;
	    end reset;
	--
	    procedure add_entry
	    (
	         p_old_C1 in "DEPT"."DEPTNO"%type
	        ,p_new_C1 in out "DEPT"."DEPTNO"%type
	     )
	    is
	    begin
	--
	        if ( inTrigger ) then return; end if;
	--
This code saves the before and after images in pl/sql tables and 'undoes' the primary key update by setting the new columns back to the old columns.
	        if (
	             p_old_C1 <> p_new_C1
	         ) then
	        rowCnt := rowCnt + 1;
	        old_C1( rowCnt ) := p_old_C1;
	        new_C1( rowCnt ) := p_new_C1;
	        p_new_C1 := p_old_C1;
	        end if;
	    end add_entry;
	--
	    procedure do_cascade
	    is
	    begin
	--
	        if ( inTrigger ) then return; end if;
	        inTrigger := TRUE;
	--
For every row that was updated we will perform the clone, cascade and delete....
	        for i in 1 .. rowCnt loop
This insert clones the parent row, duping the old values with the new primary key.
	            insert into DEPT (
	             "DEPTNO"
	            ,"DNAME","LOC") select
	             new_C1(i)
	            ,"DNAME","LOC"
	            from "DEPT" a
	            where ( "DEPTNO" ) =
	                  ( select  old_C1(i)
	                      from dual );
	--
This code is generated only when p_preserve_rowids=true and will flip-flop the old and new primary keys, hence preserving the rowid of the original parent.
	            update "DEPT" set
	            (  "DEPTNO" ) =
	            ( select
	                 decode( "DEPTNO", old_c1(i), new_c1(i), old_c1(i) )
	              from dual )
	            where (  "DEPTNO" ) =
	                  ( select  new_C1(i)
	                      from dual )
	               OR (  "DEPTNO" ) =
	                  ( select  old_C1(i)
	                      from dual );
	--
Do a cascade update to all children tables.
	            update "EMP" set
	            (  "DEPTNO" ) =
	            ( select   new_C1(i)
	                from dual )
	            where (  "DEPTNO" ) =
	                  ( select   old_C1(i)
	                    from dual );
	--
Removing the old primary key value.
	            delete from "DEPT"
	             where (  "DEPTNO" ) =
	                   ( select  old_C1(i)
	                       from dual);
	        end loop;
	--
	        inTrigger := FALSE;
	        reset;
	   exception
	       when others then
	          inTrigger := FALSE;
	          reset;
	          raise;
	    end do_cascade;
	--
	end "uDEPTp";
/

Lastly, we have the three triggers placed on the parent table to effect the update cascade. The first trigger simply 'resets' the package variables above.
create or replace trigger "uc$DEPT_bu"
before update of
    "DEPTNO"
on "DEPT"
begin "uc$DEPT_pkg".reset; end;



The next trigger, the for each row trigger, simply calls add_entry for each changed row.
create or replace trigger "uc$DEPT_bufer"
before update of
    "DEPTNO"
on "DEPT"
for each row
begin
   "uc$DEPT_pkg".add_entry(
       :old."DEPTNO"
      ,:new."DEPTNO"
      );
end;
The last trigger, calls do_cascade to effect the change
create or replace trigger "uc$DEPT_au"
after update of
    "DEPTNO"
on "DEPT"
begin "uc$DEPT_pkg".do_cascade; end;
http://asktom.oracle.com/~tkyte/update_cascade/index.html
And

[ORACLE] Upgrading from 9i to 11g and the implicit migration from RBO - Optimizer Dev Grp

|

Monday, December 21, 2009

Upgrading from 9i to 11g and the implicit migration from RBO

Now that Oracle Database 11g Release 2 is out, more and more folks are considering upgrading to 11g. However, if you are currently on Oracle 9i then you will have to tackle both the upgrade to a new release and the migration from the Rule-Based Optimizer (RBO) to the Cost-based Optimizer (CBO). The RBO was de-supported in Oracle Database 10g, so in Oracle Database 11g you must use the CBO.

Thanks to SQL Plan Management (SPM), originally discussed in our January post, you can handle the upgrade and the migration with ease. By loading the original RBO plans into SPM you can ensure the Optimizer won’t change the execution plans during an upgrade and the implicit migration from RBO to CBO.

In fact, there are two possible approaches you can take.

Option 1 – Bulk loading SPM
Typically when we discuss bulk loading plans into SPM we use SQL Tuning Sets (introduced in Oracle Database 10g) to capture the existing execution plans. However, in Oracle Database 9i we didn’t have SQL Tuning Sets so the only way to capture the existing execution plan is to use Stored Outlines. There are two ways to capture Stored Outlines, you can either manually create one for each SQL statement using the CREATE OUTLINE command (can be tricky) or let Oracle automatically create a Stored Outline for each SQL statement that is executed. Below are the steps needed to let Oracle automatically create the Stored Outlines for you and then migrate them to SPM.

1. Start a new session and issue the following command to switch on the automatic capture of a Stored Outline for each SQL statement that gets parsed from now on until you explicitly turn it off.

SQL > ALTER SYSTEM set CREATE_STORED_OUTLINES=OLDPLAN;

NOTE: Ensure that the user for which the Stored Outlines are to be created has the CREATE ANY OUTLINE privilege. If they don’t the Stored Outlines will not be captured.

2. Now execute your workload either by running your application or manually issuing SQL statements.

NOTE: if you manually issue the SQL statements ensure you use the exact SQL text used by the application, if it uses bind variables you will have to use them also.

3. Once you have executed your critical SQL statements you should turn off the automatic capture by issuing the following command:

SQL > ALTER SYSTEM set CREATE_STORED_OUTLINES=false;

4. To confirm you have captured the necessary Stored Outlines issue the following SQL statement.

SQL> SELECT name, sql_text, category FROM user_outlines;

NOTE: Each Stored Outline should have the OLDPLAN category.

5. The actual Stored Outlines are stored in the OUTLN schema. Before you upgrade you should export this schema as a backup.

exp outln/outln file=soutline.dmp owner=outln rows=y

6. Once upgraded to Oracle Database 11g Release 2 you can migrate stored outlines for one or more SQL statements to SQL plan baselines using DBMS_SPM.MIGRATE_STORED_OUTLINE or through Oracle Enterprise Manager (EM). You can specify which stored outline(s) to be migrated based on the outline name, SQL text, or outline category, or migrate all stored outlines in the system to SQL plan baselines. Below is an example of migrating all of the plan for the OLDPLAN category and an example of migrating all Stored Outlines in the OH schema.

SQL> variable report clob;

-- Migrate the Stored Outlines in the OLDPLAN category
SQL> exec :report:=DBMS_SPM.MIGRATE_STORED_OUTLINE( attribute_name=>'CATEGORY',
attribute_value => 'OLDPLAN');

-- Migrate all Stored Outlines
SQL> exec :report:=DBMS_SPM.MIGRATE_STORED_OUTLINE( attribute_name=>'ALL');


Option 2 – Automatically loading SPM
If you are unable to capture Stored Outlines for all of your SQL statements prior to the upgrade, you can set the parameter OPTIMIZER_MODE to RULE and automatically capture the RBO plan into SPM after the upgrade. Below are the necessary steps to automatically capture the RBO plans into SPM.

NOTE: OPTIMIZER_MODE=RULE is not supported in Oracle Database 11g; the code has only been left in Oracle to enable easy migrations from RBO to CBO. We do not recommended you use OPTIMIZER_MODE=RULE as a long term strategy in Oracle Database 11g as the code can be removed at any time now that it is de-supported.

1. Enable RBO by setting the init.ora parameter OPTIMIZER_MODE to RULE.

SQL > ALTER SYSTEM set OPTIMIZER_MODE=RULE;

2. Enable automatic plan capture by setting the init.ora parameter OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES to TRUE (default FALSE). With automatic plan capture enabled, the SPM repository will be automatically populated for any repeatable SQL statement.

SQL > ALTER SYSTEM set OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES = TRUE;

3. Wait for SPM to capture SQL statements executed by the application.

4. Once all of the SQL plan baselines have been created using the RBO plan, switch automatic plan capture back to the default value by setting the init.ora parameter OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES to FALSE.

SQL > ALTER SYSTEM set OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES = FALSE;

5. Switch from RBO to CBO by setting init.ora parameter OPTIMIZER_MODE to ALL_ROWS (default). Although CBO might produce alternative execution plans those plans will not be used until they have been verified to perform as well as or better than the existing RBO plans.

SQL > ALTER SYSTEM set OPTIMIZER_MODE=ALL_ROWS;

It is possible to verify each of the new CBO plans manually using, either the PL/SQL package DBMS_SPM or Enterprise Manager DB Control or you can set up a DBMS Scheduler job to check for the presence of new execution plans and automatically run the verification job for these plans.

More information on what to expect from the Optimizer when upgrading to Oracle 11g can be found in this whitepaper and more information on SQL Plan Management can be found in this whitepaper.



http://optimizermagic.blogspot.com/2009/12/ugrading-from-9i-to-11g-and-implicit.html
And

[ORACLE] How to CANCEL a query running in another session? - Tonel Poder

|

http://blog.tanelpoder.com/2010/02/17/how-to-cancel-a-query-running-in-another-session/

kill -URG 29086

kill -s SIGURG 29086

kill -s SIGINT 29086

kill -2 29086

And

[ORACLE] SQL*Plus 내의 copy 명령어

|
SQL> copy
usage: COPY FROM <db> TO <db> <opt> <table> { (<cols>) } USING <sel>
  <db>   : database string, e.g., scott/tiger@d:chicago-mktg
  <opt>  : ONE of the keywords: APPEND, CREATE, INSERT or REPLACE
  <table>: name of the destination table
  <cols> : a comma-separated list of destination column aliases
  <sel>  : any valid SQL SELECT statement
A missing FROM or TO clause uses the current SQL*Plus connection.

 LOB, LONG 다 되는 강력한 녀석...
And

[ORACLE] 숫자가 포함된 row 찾고자 할때

|
with tabs
as
(
select 'aaa1234' col_nm from dual
union all
select 'bbbbbbb' col_nm from dual
union all
select 'ccc6754' col_nm from dual
union all
select 'ddd09574' col_nm from dual
)
select col_nm, translate(col_nm,'0123456789'||col_nm,'0123456789') get_num from tabs
And

[ORACLE] ORA-01841 발생 케이스 - Cause 이외

|
SQL> select to_char(to_date(' '),'YYYYMMDD') from dual;
select to_char(to_date(' '),'YYYYMMDD') from dual
                       *
ERROR at line 1:
ORA-01841: (full) year must be between -4713 and +9999, and not be 0
Elapsed: 00:00:00.01

에러 메시지에서 보여주는 Cause 외의 사유도 존재할 수 있다는 예일까?
And
prev | 1 | 2 | 3 | 4 | next