пятница, 23 октября 2015 г.

Update BLOB

set define off
DECLARE
   vb1 CLOB :=
'long text';
   vb2 CLOB :=
                'long text';
   vb3 CLOB :=
                'long text';
   vb CLOB := vb1||vb2||vb3;
   vb_upd BLOB;
FUNCTION convert_clob_to_blob (pclob CLOB) RETURN BLOB
  IS
    lblob              BLOB;
    ldest_offset    INTEGER := 1;
    lsource_offset INTEGER := 1;
    llang_context  INTEGER := dbms_lob.default_lang_ctx;
    lwarning        INTEGER := dbms_lob.warn_inconvertible_char;
  BEGIN
    dbms_lob.createtemporary (lblob, TRUE);

    dbms_lob.converttoblob (dest_lob    => lblob,
                                              src_clob    => pclob,
                                              amount      => dbms_lob.lobmaxsize,
                                              dest_offset => ldest_offset,
                                              src_offset  => lsource_offset,
                                              blob_csid   => dbms_lob.default_csid,
                                              lang_context=> llang_context,
                                              warning     => lwarning);
    RETURN lblob;
END convert_clob_to_blob;
BEGIN
   vb_upd := convert_clob_to_blob(vb);
   UPDATE tab SET BLOB_COL = vb_upd
   WHERE ...;
   COMMIT;
END;



/  

Privilegies

It is useful to find out full hierarchy of privileges by grantee. I have attached the scripts to do it.

privs_role_all_by_grantee.sql
privs_sys_all_by_grantee.sql
privs_tab_all_by_grantee.sql

Startup history

set pagesize 3000
set lines 300
col HOST_NAME format a30
col PLATFORM_NAME format a30
col STARTUP_TIME format a21
col DB_NAME format a9
select DBID
     , TO_CHAR(STARTUP_TIME, 'yyyy.mm.dd hh24:mi:ss') STARTUP_TIME
     , HOST_NAME
     , DB_NAME
     , PLATFORM_NAME
from DBA_HIST_DATABASE_INSTANCE
order by STARTUP_TIME;     

вторник, 6 августа 2013 г.

What is the diff in 2 explain plans: diff_plan_cursor

0) Generate the diff plan report
We have sql_id gu7rvn4s4rb0m, and 2 child cursors 0 and 2
variable v clob
set serveroutput on
set autoprint on
set lines 150
exec :v := dbms_xplan.diff_plan_cursor('gu7rvn4s4rb0m', 0, 2);
http://stads59.us.oracle.com:8080/orarep/plandiff/all?task_id=119&format=html&method=qbreg

PL/SQL procedure successfully completed.


V
--------------------------------------------------------------------------------
TASK_119

Display the report, 2 options:
1) Display the report via XML DB
--open http port if needed, if you are on test/dev environment
exec dbms_xdb.SETHTTPPORT(8080);
--replacing url by local hostname
http://<db host name>:8080/orarep/plandiff/all?task_id=119&format=html&method=qbreg

2) Display in sqlplus
--report in text format, or replace format=html or format=xml
set define off;
set long 999999999
set pagesize 3000
select dbms_report.get_report(
        '/orarep/plandiff/all?task_id=119&format=text&method=qbreg')
from dual;

DBMS_REPORT.GET_REPORT('/ORAREP/PLANDIFF/ALL?TASK_ID=119&FORMAT=TEXT&METHOD=QBRE
--------------------------------------------------------------------------------
General Information
-------------------------------------------------------------------------------

 Task Information:                      Workload Information:
 -------------------------------------  -------------------------------------
  Task Name    : TASK_119
  Task Owner   : SYS
  Description  : diff_plan_cursor

Report Details: SQL Plan Comparison Query Block Diff
------------------------------------------------
| Query Block | SQL Plan 1 | SQL Plan 2 | Diff |
------------------------------------------------

Join Order Diff
-----------------------------------------
| Query Block | SQL Plan 1 | SQL Plan 2 |
-----------------------------------------

Join Method Diff
---------------------------------------------------------
| Query Block | Table to Join | SQL Plan 1 | SQL Plan 2 |
---------------------------------------------------------
| SEL$1       | "T2"@"SEL$1"  | HASH       | MERGE      |
---------------------------------------------------------

 Plan Id          : 325
 Plan Hash Value  : 2795996736

----------------------------------------
| Id  | Operation            | Name    |
----------------------------------------
|   0 | SELECT STATEMENT     |         |
| * 1 |   HASH JOIN          |         |
|   2 |    TABLE ACCESS FULL | TEST100 |
|   3 |    TABLE ACCESS FULL | TEST100 |
----------------------------------------

Predicate Information (identified by operation id):
------------------------------------------
* 1 - access("T1"."ID"="T2"."ID")

 Plan Id          : 326
 Plan Hash Value  : 216926072

-----------------------------------------
| Id  | Operation           | Name      |
-----------------------------------------
|   0 | SELECT STATEMENT    |           |
|   1 |   MERGE JOIN        |           |
|   2 |    INDEX FULL SCAN  | TEST100_I |
| * 3 |    SORT JOIN        |           |
|   4 |     INDEX FULL SCAN | TEST100_I |
-----------------------------------------

Predicate Information (identified by operation id):
------------------------------------------
* 3 - access("T1"."ID"="T2"."ID")
* 3 - filter("T1"."ID"="T2"."ID")

-----------------------------------------------------------------
| Diff | Transformation | SQL Plan 1 | SQL Plan 2 | Query block |
-----------------------------------------------------------------
| *    | . PARSER       | Yes        | Yes        | . SEL$1     |
-----------------------------------------------------------------

четверг, 13 сентября 2012 г.

win: Oracle Service not starting

C:\WINDOWS\system32>sc start OracleServiceTESTDB11G_stby
[SC] StartService FAILED 1058:

The service cannot be started, either because it is disabled or because it has no enabled devices associated with it.
C:\WINDOWS\system32>sc qc OracleServiceTESTDB11G_stby
[SC] QueryServiceConfig SUCCESS
...
        START_TYPE         : 4   DISABLED
...
C:\WINDOWS\system32>sc config OracleServiceTESTDB11G_stby start= demand
[SC] ChangeServiceConfig SUCCESS

C:\WINDOWS\system32>sc qc OracleServiceTESTDB11G_stby
[SC] QueryServiceConfig SUCCESS
...
        START_TYPE         : 3   DEMAND_START
...
C:\WINDOWS\system32>sc start OracleServiceTESTDB11G_stby

SERVICE_NAME: OracleServiceTESTDB11G_stby
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 2  START_PENDING
                                (NOT_STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x7d0
        PID                : 4204
        FLAGS              :

C:\WINDOWS\system32>sc query OracleServiceTESTDB11G_stby

SERVICE_NAME: OracleServiceTESTDB11G_stby
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 4  RUNNING
                                (STOPPABLE, PAUSABLE, ACCEPTS_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0

среда, 12 сентября 2012 г.

Win7 stuck on welcome screen

1) Reboot, press F8, choose safe mode
2) If started -> cmd, msconfig, Check Selective startup, uncheck Load startup items, go to tab Services - > check Hide all Microsoft services, Disable All
3) Reboot normally, set needed services again with msconfig

Update BLOB

set define off DECLARE    vb1 CLOB := 'long text';    vb2 CLOB :=                 'long text';    vb3 CLOB :=              ...