Tuesday 17 October 2017

How to install OraOLEDB12.dll 64 bit / OraOLEDB11.dll 32 bit ? or How to solve "OraOLEDB.Oracle Provider is not registered" error?


32 Bit
-------
1. login into cmd prompt (using Run as Administrator option) and run the below command

cd C:\ORACLE\cli11gR2_32\bin

C:\ORACLE\cli11gR2_32\bin> c:\Windows\system32\regsvr32.exe OraOLEDB11.dll

Note:
Ensure the path variable was set and referring the location "C:\ORACLE\cli11gR2_32\bin"



64 Bit
--------




 

1. Download  "ODAC112040Xcopy_64bit"
2. Unzip it
3.login into cmd prompt (using Run as Administrator option) and run the below command

cd C:\Users\Downloads\ODAC112040Xcopy_64bit

C:\Users\Downloads\ODAC112040Xcopy_64bit>dir
 Volume in drive C is System Volume
 Volume Serial Number is DC2F-3B02

 Directory of C:\Users\Downloads\ODAC112040Xcopy_64bit

04/11/2017  05:10 PM    <DIR>          .
04/11/2017  05:10 PM    <DIR>          ..
01/06/2014  03:55 PM    <DIR>          asp.net
01/06/2014  03:56 PM    <DIR>          asp.net4
10/23/2013  04:36 PM            26,323 configure.bat
10/23/2013  04:21 PM            11,538 install.bat
01/06/2014  04:00 PM    <DIR>          instantclient_11_2
01/06/2014  03:46 PM    <DIR>          network
01/06/2014  03:57 PM    <DIR>          odp.net20
01/06/2014  03:58 PM    <DIR>          odp.net4
01/06/2014  03:59 PM    <DIR>          oledb
01/06/2014  03:59 PM    <DIR>          oramts
01/06/2014  03:42 PM             8,766 readme.htm
01/03/2014  03:10 PM            14,042 unconfigure.bat
01/06/2014  04:00 PM            20,676 uninstall.bat
               5 File(s)         81,345 bytes
              10 Dir(s)  282,921,463,808 bytes free

C:\Users\Downloads\ODAC112040Xcopy_64bit>INSTALL ALL “C:\Oracle\Oracle64Driver” Oracle64Driver TRUE

4. copy the content of instantclient folder into to bin folder


Tuesday 13 June 2017

Wednesday 7 June 2017

How to stop currently running oracle scheduled jobs?

begin
   dbms_scheduler.stop_job('<JOB_NAME>',true);
end;


example

begin
   dbms_scheduler.stop_job('PRJ_EMP_UPDATE',true);
end;

once after stopping the job, we can disable it from the PL/SQL developer.

How to identify current running oracle scheduled jobs?



SELECT * FROM USER_SCHEDULER_RUNNING_JOBS;

How to identify current consumption of memory (UGA and PGA) ?

UGA - User Global Area or Session memory
PGA - Process Global Area


select name, sum(value/1024/1024) "MB" from v$statname n, v$session s, v$sesstat t  where s.sid = t.sid
and n.statistic# = t.statistic# and s.TYPE = 'USER' and s.USERNAME is not null and n.name in ('session pga memory', 'session uga memory')
group by name

Thursday 1 June 2017

reason for ORA-12008: error in materialized view refresh path ORA-01652: unable to extend temp segment by 128 in tablespace TEMP


ORA-12008: error in materialized view refresh path

ORA-01652: unable to extend temp segment by 128 in tablespace TEMP



The above error is due to lack of TEMP space ...



To identify the used and free space




SELECT   A.tablespace_name tablespace, D.mb_total,
 SUM (A.used_blocks * D.block_size) / 1024 / 1024 mb_used,
 D.mb_total - SUM (A.used_blocks * D.block_size) / 1024 / 1024 mb_free
 FROM     v$sort_segment A,
 (
 SELECT   B.name, C.block_size, SUM (C.bytes) / 1024 / 1024 mb_total
 FROM     v$tablespace B, v$tempfile C
 WHERE    B.ts#= C.ts#
 GROUP BY B.name, C.block_size
 ) D
 WHERE    A.tablespace_name = D.name
 GROUP by A.tablespace_name, D.mb_total;





To fix it need to increase the size...



.  Temporary fix

a) Resize temporary file as
SQL> ALTER DATABASE TEMPFILE ‘/u01/oradata/VIS11i/temp01.dbf’ RESIZE 3072M;

or

b) Add temp datafile to temporary tablespace as

SQL> ALTER TABLESPACE TEMP ADD TEMPFILE ‘/u01/oradata/VIS11i/temp02.dbf’
SIZE 1024M REUSE AUTOEXTEND ON NEXT 50M  MAXSIZE 1024M;

.

Root Cause Analysis

1.  Identify temp segment usages per session


— Temp segment usage per session.

SQL> SELECT   S.sid || ‘,’ || S.serial# sid_serial, S.username, S.osuser, P.spid, S.module,
P.program, SUM (T.blocks) * TBS.block_size / 1024 / 1024 mb_used, T.tablespace,
COUNT(*) statements
FROM     v$sort_usage T, v$session S, dba_tablespaces TBS, v$process P
WHERE    T.session_addr = S.saddr
AND      S.paddr = P.addr
AND      T.tablespace = TBS.tablespace_name
GROUP BY S.sid, S.serial#, S.username, S.osuser, P.spid, S.module,
P.program, TBS.block_size, T.tablespace
ORDER BY mb_used;

2. Identify temp segment usages per statement

— Temp segment usage per statement.

SQL> SELECT  S.sid || ‘,’ || S.serial# sid_serial, S.username, Q.hash_value, Q.sql_text,
T.blocks * TBS.block_size / 1024 / 1024 mb_used, T.tablespace
FROM    v$sort_usage T, v$session S, v$sqlarea Q, dba_tablespaces TBS
WHERE   T.session_addr = S.saddr
AND     T.sqladdr = Q.address
AND     T.tablespace = TBS.tablespace_name
ORDER BY mb_used;
Depending on outcome of temp segment usage per session and per statement focus on problematic session/statement.


reference : http://onlineappsdba.com/index.php/2009/07/27/ora-1652-unable-to-extend-temp-segment-by-128-in-tablespace-temp/

Monday 22 May 2017

How to grant SYSDBA privilege to an user?

grant connect ,resource,DBA to USER
How to resove PLS-00201: identifier 'JSON' must be declared error in oracle?

1. Need to install the PL/JSON package
2. GRANT EXECUTE ON JSON TO <user>;
How to parse JSON in oracle?

 In 11g, we need to install the utilities for  JSON
1.
APEX_JSON


https://docs.oracle.com/cd/E59726_01/doc.50/e39149/apex_json.htm#AEAPI29635

2.

PL/JSON

https://sourceforge.net/p/pljson/wiki/Home/


3. upgrade to 12c

After the installation we can use the JSON, JSON_LIST type we can parse the JSON files...
HOW TO GRANT THE JSON OBJECT TYPE TO USER IN ORACLE?

SQL> GRANT EXECUTE ON JSON TO MURUGA;
Grant succeeded


SQL> GRANT EXECUTE ON JSON_LIST TO MURUGA;
Grant succeeded

SQL> GRANT EXECUTE ON JSON_VALUE TO MURUGA;
Grant succeeded


SQL> GRANT EXECUTE ON JSON_VALUE_ARRAY TO MURUGA;
Grant succeeded
HOW TO LIST THE JSON OBJECT TYPES IN ORACLE?


SQL> SELECT * FROM USER_OBJECTS WHERE OBJECT_TYPE = 'TYPE' AND OBJECT_NAME LIKE '%JSON%'
  2  ;
OBJECT_NAME                                                                      SUBOBJECT_NAME                  OBJECT_ID DATA_OBJECT_ID OBJECT_TYPE         CREATED     LAST_DDL_TIME TIMESTAMP           STATUS  TEMPORARY GENERATED SECONDARY  NAMESPACE EDITION_NAME
-------------------------------------------------------------------------------- ------------------------------ ---------- -------------- ------------------- ----------- ------------- ------------------- ------- --------- --------- --------- ---------- ------------------------------
JSON                                                                                                                443607                TYPE                5/19/2017 9 5/19/2017 9:2 2017-05-19:09:23:57 VALID   N         N         N                  1
JSON_LIST                                                                                                           443606                TYPE                5/19/2017 9 5/19/2017 9:2 2017-05-19:09:23:57 VALID   N         N         N                  1
JSON_TAB                                                                                                            439925                TYPE                5/18/2017 4 5/18/2017 4:3 2017-05-18:16:33:19 VALID   N         N         N                  1
JSON_VALUE                                                                                                          443604                TYPE                5/19/2017 9 5/19/2017 9:2 2017-05-19:09:23:56 VALID   N         N         N                  1
JSON_VALUE_ARRAY                                                                                                    443605                TYPE                5/19/2017 9 5/19/2017 9:2 2017-05-19:09:23:57 VALID   N         N         N                  1

Friday 17 March 2017

How to Create oracle Nested Table?

How to Create oracle Nested Table?

Create a table with NESTED TABLE column:
CREATE OR REPLACE TYPE my_tab_t AS TABLE OF VARCHAR2(30);
/
CREATE TABLE nested_table (id NUMBER, col1 my_tab_t)
       NESTED TABLE col1 STORE AS col1_tab;
Insert data into table:
INSERT INTO nested_table VALUES (1, my_tab_t('A'));
INSERT INTO nested_table VALUES (2, my_tab_t('B', 'C'));
INSERT INTO nested_table VALUES (3, my_tab_t('D', 'E', 'F'));
COMMIT;
Select from nested table:
SQL> SELECT * FROM nested_table;
        ID COL1
---------- ------------------------
         1 MY_TAB_T('A')
         2 MY_TAB_T('B', 'C')
         3 MY_TAB_T('D', 'E', 'F')
Unnesting the subtable:
SQL> SELECT id, COLUMN_VALUE FROM nested_table t1, TABLE(t1.col1) t2;
        ID COLUMN_VALUE
---------- ------------------------
         1 A
         2 B
         2 C
         3 D
         3 E
         3 F
6 rows selected.
A more complicated multi-column nested table where customers can have multiple addresses:
CREATE TYPE address_t AS OBJECT (
   street  VARCHAR2(30),
   city    VARCHAR2(20),
   state   CHAR(2),
   zip     CHAR(5) );
/
CREATE TYPE address_tab IS TABLE OF address_t;
/
CREATE TABLE customers (
   custid  NUMBER,
   address address_tab )
NESTED TABLE address STORE AS customer_addresses;

INSERT INTO customers VALUES (1,
            address_tab(
              address_t('101 First', 'Redwood Shores', 'CA', '94065'),
              address_t('123 Maple', 'Mill Valley',    'CA', '90952')
            )                );
Unnesting the subtable:
SQL> select c.custid, u.*
  2  from customers c, table (c.address) u
  3  ;

    CUSTID STREET                         CITY                 ST ZIP
---------- ------------------------------ -------------------- -- -----
         1 101 First                      Redwood Shores       CA 94065
         1 123 Maple                      Mill Valley          CA 90952
 
 
To view the TYPE creation content
 
select text from user_source where name = 'MY_TAB_T' order by line 

select text from user_source where name = 'MY_TAB_T' order by line 


select * from  ALL_TYPES;
 
 
 
Source : http://www.orafaq.com/wiki/NESTED_TABLE 

Thursday 16 March 2017

How to identify the distinct data types used in a oracle schema?

How to identify the distinct data types used in a oracle schema?

select distinct data_type,data_length,data_precision,data_scale
from all_tab_columns;

How to identify the oracle schema names in a database / Display all oracle Schemas

How to identify the oracle schema names in a database? / Display all oracle Schemas

 select distinct
   owner
from
   dba_segments
where
   owner in
   (select username
    from dba_users
    where default_tablespace not in ('SYSTEM','SYSAUX')
   )
;

or

select distinct
   owner
from
   dba_segments
where
   owner not in (
'SYSTEM', 'XDB', 'SYS', 'TSMSYS', 'MDSYS', 'EXFSYS', 'WMSYS', 'ORDSYS', 'OUTLN', 'DBSNMP');

Source : http://www.dba-oracle.com/t_display_all_schemas.htm

Wednesday 15 March 2017

How to generate AWR & ASH from SQLPLUS or through procedure

set serveroutput on;
declare
dbid number;
instance_id number;
start_id number;
end_id number;
begin
dbms_output.enable(1000000);
select max(snap_id)-1,max(snap_id) into start_id,end_id from dba_hist_snapshot;
/* If you know the snap_id then comment the above line  and use the below code
start_id :=1233;
end_id := 1234;
*/
select dbid into dbid from v$database;
select instance_number into instance_id from v$instance;

--dbms_output.put_line('<PRE>');
for rc in ( select output from
   table(dbms_workload_repository.awr_report_text(dbid,instance_id,start_id,end_id))
           ) loop
  -- dbms_output.put_line('<BR>');
   dbms_output.put_line(rc.output);
end loop;
--dbms_output.put_line('</PRE>');
end;

FOR AWR html output

declare
dbid number;
instance_id number;
start_id number;
end_id number;
begin
dbms_output.enable(1000000);
select max(snap_id)-1,max(snap_id) into start_id,end_id from dba_hist_snapshot;
/* If you know the snap_id then comment the above line  and use the below code
start_id :=1233;
end_id := 1234;
*/
select dbid into dbid from v$database;
select instance_number into instance_id from v$instance;

--dbms_output.put_line('<PRE>');
for rc in ( select output from
   table(dbms_workload_repository.awr_report_html(dbid,instance_id,start_id,end_id))
           ) loop
  -- dbms_output.put_line('<BR>');
   dbms_output.put_line(rc.output);
end loop;
--dbms_output.put_line('</PRE>');
end;

/*privileges needed


grant select any dictionary to username;
grant SELECT ON SYS.V_$DATABASE  to username;
grant SELECT ON SYS.V_$INSTANCE to username;
grant EXECUTE ON SYS.DBMS_WORKLOAD_REPOSITORY  to username;
grant SELECT ON SYS.DBA_HIST_DATABASE_INSTANCE to username;
grant SELECT ON SYS.DBA_HIST_SNAPSHOT to username;
grant ADVISOR to username;

*/

ASH Report for the past 30 minutes

declare
dbid number;
instance_id number;
begin
select dbid into dbid from v$database;
select instance_number into instance_id from v$instance;
dbms_output.enable(500000);
dbms_output.put_line('<PRE>');
for rc in ( select output from
   table(dbms_workload_repository.ash_report_text( dbid,instance_id,SYSDATE-31/1440, SYSDATE-1/1440))) loop
   dbms_output.put_line(rc.output);
end loop;
dbms_output.put_line('</PRE>') ;
end;

for ASH HTML output

declare
dbid number;
instance_id number;
begin
select dbid into dbid from v$database;
select instance_number into instance_id from v$instance;
dbms_output.enable(500000);
dbms_output.put_line('<PRE>');
for rc in ( select output from
   table(dbms_workload_repository.ash_report_html( dbid,instance_id,SYSDATE-31/1440, SYSDATE-1/1440))) loop
   dbms_output.put_line(rc.output);
end loop;
dbms_output.put_line('</PRE>') ;
end;