'Oracle'에 해당되는 글 13건

  1. 2013.05.13 [Oracle] 인스턴스 추가/변경/삭제 - 글 작성중
  2. 2010.07.26 [ORACLE] select last rows
  3. 2010.06.15 [ORACLE] Windows CMD창 SQL*Plus에서 DB LINK 생성시 발생할 수 있는 에러
  4. 2010.06.10 [ORACLE] 비율 관련
  5. 2010.06.10 [ORACLE] connect by 로 결과값 가로로 펼치기
  6. 2010.05.25 [ORACLE] EXEMPT ACCESS POLICY
  7. 2010.04.19 [ORACLE] CLOB -> BLOB function
  8. 2010.04.19 [ORACLE] LONG RAW -> BLOB -> CLOB
  9. 2010.04.09 [ORACLE] Upgrading from 9i to 11g and the implicit migration from RBO - Optimizer Dev Grp
  10. 2010.04.06 [ORACLE] How to CANCEL a query running in another session? - Tonel Poder

[Oracle] 인스턴스 추가/변경/삭제 - 글 작성중

|

DBCA를 활용하는 방법과 수동으로 하는 방법이 있습니다.

And

[ORACLE] select last rows

|
oracle table에서 마지막 변경된 row와 그 변경 시간 찾기.
16:49:53 SQL> create table check_dml_time     
16:50:22   2  (
16:50:24   3   fix_column varchar2(10)
16:50:38   4  ,test_column varchar2(10)
16:50:49   5  )
16:50:50   6  ;

Table created.

Elapsed: 00:00:00.02
16:50:51 SQL> insert into check_dml_time values ('FIX','FIRST');

1 row created.

Elapsed: 00:00:00.01
16:51:21 SQL> commit;

Commit complete.

Elapsed: 00:00:00.01
16:51:23 SQL> select created, last_ddl_time from user_objects where object_name = upper('check_dml_time');

CREATED           LAST_DDL_TIME
----------------- -----------------
20100726 16:50:51 20100726 16:50:51

1 row selected.

Elapsed: 00:00:00.02
16:52:01 SQL> select ora_rowscn from check_dml_time;

          ORA_ROWSCN
--------------------
      11466381392945

1 row selected.

Elapsed: 00:00:00.01
16:52:31 SQL> select scn_to_timestamp(ora_rowscn) from check_dml_time;

SCN_TO_TIMESTAMP(ORA_ROWSCN)
---------------------------------------------------------------------------
2010/07/26 16:51:23

1 row selected.

Elapsed: 00:00:00.01
16:53:31 SQL> update check_dml_time 
16:53:43   2     set test_column = 'UPDATED'
16:53:50   3  ;

1 row updated.

Elapsed: 00:00:00.01
16:53:55 SQL> commit;

Commit complete.

Elapsed: 00:00:00.01
16:54:00 SQL> select scn_to_timestamp(ora_rowscn) from check_dml_time;

SCN_TO_TIMESTAMP(ORA_ROWSCN)
---------------------------------------------------------------------------
2010/07/26 16:53:59

1 row selected.

Elapsed: 00:00:00.00

Tested : Oracle Database 10g Enterprise Edition Release 10.2.0.4.0

원문 링크 : http://laurentschneider.com/wordpress/2006/08/select-last-rows.html
And

[ORACLE] Windows CMD창 SQL*Plus에서 DB LINK 생성시 발생할 수 있는 에러

|
생성하고자 하는 DB LINK의 password에 마지막 문자에 !가 있는 경우 windows cmd 창에서 SQL*Plus로는 에러가 나는 경우가 있습니다.

Unix 환경에서도 ""로 감싸줘야 에러없이 생성가능합니다.


CREATE PUBLIC DATABASE LINK db_link_nm
CONNECT TO id IDENTIFIED BY "password!"
USING db_service_nm;

And

[ORACLE] 비율 관련

|
WITH test AS
(
SELECT '40' code, 30 cnt FROM dual
UNION ALL SELECT '30', 50 FROM dual
UNION ALL SELECT '10', 20 FROM dual
)
SELECT code
, SUM(cnt) cnt
, RATIO_TO_REPORT(SUM(cnt)) OVER(PARTITION BY GROUPING(code)) * 100 ratio
FROM test
GROUP BY ROLLUP(code)
;

And

[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] 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
prev | 1 | 2 | next