'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와 그 변경 시간 찾기.
0116:49:53 SQL> create table check_dml_time    
0216:50:22   2  (
0316:50:24   3   fix_column varchar2(10)
0416:50:38   4  ,test_column varchar2(10)
0516:50:49   5  )
0616:50:50   6  ;
07 
08Table created.
09 
10Elapsed: 00:00:00.02
1116:50:51 SQL> insert into check_dml_time values ('FIX','FIRST');
12 
131 row created.
14 
15Elapsed: 00:00:00.01
1616:51:21 SQL> commit;
17 
18Commit complete.
19 
20Elapsed: 00:00:00.01
2116:51:23 SQL> select created, last_ddl_time from user_objects where object_name = upper('check_dml_time');
22 
23CREATED           LAST_DDL_TIME
24----------------- -----------------
2520100726 16:50:51 20100726 16:50:51
26 
271 row selected.
28 
29Elapsed: 00:00:00.02
3016:52:01 SQL> select ora_rowscn from check_dml_time;
31 
32          ORA_ROWSCN
33--------------------
34      11466381392945
35 
361 row selected.
37 
38Elapsed: 00:00:00.01
3916:52:31 SQL> select scn_to_timestamp(ora_rowscn) from check_dml_time;
40 
41SCN_TO_TIMESTAMP(ORA_ROWSCN)
42---------------------------------------------------------------------------
432010/07/26 16:51:23
44 
451 row selected.
46 
47Elapsed: 00:00:00.01
4816:53:31 SQL> update check_dml_time
4916:53:43   2     set test_column = 'UPDATED'
5016:53:50   3  ;
51 
521 row updated.
53 
54Elapsed: 00:00:00.01
5516:53:55 SQL> commit;
56 
57Commit complete.
58 
59Elapsed: 00:00:00.01
6016:54:00 SQL> select scn_to_timestamp(ora_rowscn) from check_dml_time;
61 
62SCN_TO_TIMESTAMP(ORA_ROWSCN)
63---------------------------------------------------------------------------
642010/07/26 16:53:59
65 
661 row selected.
67 
68Elapsed: 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 환경에서도 ""로 감싸줘야 에러없이 생성가능합니다.


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

[ORACLE] 비율 관련

|
01WITH test AS
02(
03SELECT '40' code, 30 cnt FROM dual
04UNION ALL SELECT '30', 50 FROM dual
05UNION ALL SELECT '10', 20 FROM dual
06)
07SELECT code
08, SUM(cnt) cnt
09, RATIO_TO_REPORT(SUM(cnt)) OVER(PARTITION BY GROUPING(code)) * 100 ratio
10FROM test
11GROUP BY ROLLUP(code)
12;
And

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

|
01column viewname format a100
02 
03with tab
04as
05(
06select '0001' code, 'A' name from dual union all
07select '0001' code, 'B' name from dual union all
08select '0001' code, 'C' name from dual union all
09select '0002' code, 'D' name from dual union all
10select '0002' code, 'A' name from dual union all
11select '0003' code, 'F' name from dual union all
12select '0003' code, 'E' name from dual union all
13select '0003' code, 'B' name from dual union all
14select '0003' code, 'C' name from dual
15)
16select x.code
17      ,substr(max(sys_connect_by_path(x.name,', ')),2) viewname
18  from (
19       select code
20             ,name
21             ,row_number() over (partition by code order by code ,name) rn
22         from tab
23       ) x
24 start with x.rn = 1
25connect by prior x.code = x.code
26   and prior x.rn = x.rn - 1
27 group by x.code
28/
connect by 앞에서 항상 약해지는 나 ㅡ.ㅜ
01with tab
02as
03(
04select '0001' code, 'A' name from dual union all
05select '0001' code, 'B' name from dual union all
06select '0001' code, 'C' name from dual union all
07select '0002' code, 'D' name from dual union all
08select '0002' code, 'A' name from dual union all
09select '0003' code, 'F' name from dual union all
10select '0003' code, 'E' name from dual union all
11select '0003' code, 'B' name from dual union all
12select '0003' code, 'C' name from dual
13)
14select x.code
15      ,substr(xmlagg(xmlelement(x,' ,',x.name).extract('//text()')),3) viewnames
16  from tab x
17 group by x.code
18/
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.

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

[ORACLE] CLOB -> BLOB function

|
01CREATE OR REPLACE FUNCTION CLOB2BLOB (p_clob in CLOB)
02return BLOB
03is
04-- transforming CLOB a BLOB
05p_blob blob;
06l_off number default 1;
07l_amt number default 4096;
08l_offWrite number default 1;
09l_amtWrite number;
10l_str varchar2(4096 char);
11begin
12DBMS_LOB.CREATETEMPORARY(p_blob, TRUE);
13begin
14loop
15dbms_lob.read ( p_clob, l_amt, l_off, l_str );
16 
17l_amtWrite := utl_raw.length ( utl_raw.cast_to_raw( l_str) );
18dbms_lob.write( p_blob, l_amtWrite, l_offWrite,
19utl_raw.cast_to_raw( l_str ) );
20 
21l_offWrite := l_offWrite + l_amtWrite;
22 
23l_off := l_off + l_amt;
24l_amt := 4096;
25end loop;
26exception
27when no_data_found then
28NULL;
29end;
30return p_blob;
31end CLOB2BLOB;
32/
And

[ORACLE] LONG RAW -> BLOB -> CLOB

|
01-- long raw -> blob
02 
03create table blob_table_name
04as
05select
06         to_lob(long_raw_col) as blob_col
07  from long_raw_table_name
08/
09 
10-- create blob2clob function
11 
12CREATE OR REPLACE FUNCTION "BLOB2CLOB" (b IN BLOB)
13RETURN CLOB
14IS
15l_blob blob;
16l_clob clob := 'x';
17l_dest_offsset integer := 1;
18l_src_offsset integer := 1;
19l_lang_context integer := dbms_lob.default_lang_ctx;
20l_warning integer;
21BEGIN
22  l_blob := b;
23  IF dbms_lob.getlength(b) != 0 THEN
24  DBMS_LOB.CONVERTTOCLOB
25  ( dest_lob => l_clob
26  , src_blob => l_blob
27  , amount => dbms_lob.lobmaxsize
28  , dest_offset => l_dest_offsset
29  , src_offset => l_src_offsset
30  , blob_csid => dbms_lob.default_csid
31  , lang_context => l_lang_context
32  , warning => l_warning
33  );
34  END IF;
35RETURN l_clob;
36END BLOB2CLOB;
37/
38 
39-- blob --> clob
40 
41create table clob_table_name
42as
43select
44          blob2clob(blob_col) as clob_col
45  from blob_table_name
46/
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