SQL Query Row Limits and Offsets Oracle Database 12C release 1 (12.1)

New keywords OFFSET and FETCH provides ANSI SQL standard to limit the number of rows returned and to specify a starting row for the return set.

Description of row_limiting_clause.gif follows

Note

  • ROW and ROWS has got the same meaning and can be used interchangeably
  • FIRST and NEXT has got the same meaning and can be used interchangeably
[ OFFSET offset ROWS]
FETCH  NEXT [  row_count | percent PERCENT  ] ROWS  [ ONLY | WITH TIES ]

Continue reading

Implicit Result Sets Oracle Database 12C release 1 (12.1)

It’s new option to return many ref cursors in PL/SQL implicit.

When code is migrated to Oracle Database from other vendors’ environments (Microsoft etc.), the capability will remove the need to rewrite code that takes advantage of implicit result set communication.

This feature is delivered by DBMS_SQL.RETURN_RESULT procedure which is responsible for creation of implicit result sets. Following procedure hasn’t got any explicit declaration of out variables. I love it :).

create or replace procedure return_many_cursors
authid current_user
is
  v_c1 sys_refcursor;
  v_c2 sys_refcursor;
  v_c3 sys_refcursor;
begin
  open v_c1 for 'select object_name from user_objects';

  dbms_sql.return_result(v_c1);

  open v_c2 for 'select instance_name from v$instance';

  dbms_sql.return_result(v_c2);

  open v_c3 for 'select name from v$database';

  dbms_sql.return_result(v_c3);
end;
/

Continue reading

Install Oracle 12C Release 1 (12.1) on Windows 7, 8

This article presents how to quickly install Oracle Database 12C Release 1 (12.1.0.1) on Windows.

In case you want to install Oracle RAC 12C on Windows 2008 check following article:

Install Oracle RAC 12C 12.1.0.1 on Windows 2008 using Oracle Virtual Box

Software used:

  • Oracle Database 12C Release 1(12.1.0.1) – 64 bit for Windows
  • Windows 8 Pro edition 64 bit

Binaries Database 12C Release 1(12.1.0.1)

winx64_12c_database_1of2.zip - database software
winx64_12c_database_2of2.zip - database software

Hardware and software requirements:

  • at least 2GB ram as minimumat least 10G space
  • Windows Server 2008 x64 and up – Standard, Enterprise, Datacenter, Web, and Foundation editions.
  • Windows Server 2012 x64 – Standard, Datacenter, Essentials, and Foundation editions
  • Windows 7 x64 – Professional, Enterprise, and Ultimate editions
  • Windows 8 x64 – Pro and Enterprise editions

I installed database software on Windows 8 Pro edition. Grid 12C is not supported for Windows 8 Pro.

Continue reading

Install Oracle Enterprise Manager 12C release 3(12.1.0.3) on OEL 5/6

This article presents installation of new Oracle Enterprise Manager 12C version 12.1.0.3 on OEL5, OEL6.

Read following article to find out how to install OEL5,6 and database 11G Linux. They are required for this installation:

This installation was done on OEL6(extra library must be installed) but it’s no different on OEL5

Oracle Database 12C Relase1(12.1.0.1) is not yet supported for Cloud repository.

Software used:

  • Oracle Virtual Box – 64 bit
  • Oracle Enterprise Linux 6 – 64 bit
  • Oracle Database 11G Release 2(11.2.0.3) – 64 bit for Linux
  • Oracle Oracle Enterprise Manager 12C release 3(12.1.0.3) – 64 bit for Linux

Binaries Oracle Enterprise Manager 12C (12.1.0.3)

em12103_linux64_disk1.zip - enterprise software
em12103_linux64_disk2.zip - enterprise software
em12103_linux64_disk3.zip - enterprise software

You need at least 5GB of memory for this installation so check your VirtualBox settings before proceeding.

Continue reading

DBMS_UTILITY.EXPAND_SQL_TEXT Procedure Oracle Database 12C release 1 (12.1)

If you need to analyze query which is based on complex view it can take a lot of time to do it.

New procedure EXPAND_SQL_TEXT of package DBMS_UTILITY helps to recursively replace any view references in the input SQL query with the corresponding view subquery.

Test data

create table test_tbl
(id number,
 id1 number);

create view test_v1
as select * from test_tbl;

create view test_v2
as
select * from test_v1;

create view test_v3
as
select id+id1 ok from test_v2;

What if you need to analyze following query

select * from test_v3

With new procedure it’s piece of cake

set serveroutput on
declare
  v_in_view  clob := 'select * from TEST_V3';
  v_out_view clob;
begin
  dbms_utility.expand_sql_text(v_in_view, v_out_view);
  dbms_output.put_line(v_out_view);
end;
/

anonymous block completed
SELECT "A1"."OK" "OK" FROM  
(SELECT "A2"."ID"+"A2"."ID1" "OK" 
FROM (SELECT "A3"."ID" "ID","A3"."ID1" "ID1" 
FROM (SELECT "A4"."ID" "ID","A4"."ID1" "ID1" 
FROM TOMASZ."TEST_TBL" "A4") "A3") "A2") "A1"

be smart do it with new feature WITH FUNCTION directly in sql

with
  function get_data(p_in_view clob)
  return clob
  is
    v_out_view clob;
  begin
    dbms_utility.expand_sql_text(p_in_view, v_out_view);

    return v_out_view;
  end;
select get_data('select * from TEST_V3') from dual
/

GET_DATA('SELECT*FROMTEST_V3')
----------------------------------------------
SELECT "A1"."OK" "OK" FROM  (SELECT "A2"."ID"+ ...

Have a fun 🙂

Tomasz

 

 

Change hostname OEL5/OEL6

In case you need to assign new name “new_host_name” for your host execute following steps

1. Modify “/etc/hosts” file to contain a fully qualified name for the server.

<IP-address>  <fully-qualified-machine-name>  <machine-name>

Enter following data to “/ect/hosts”

127.0.0.1     localhost.localdomain      localhost
192.168.0.50  new_host_name.dbaora.com   new_host_name

2. Modify “/etc/sysconfig/network” file

NETWORKING=yes
HOSTNAME=new_host_name.dbaora.com

3. Reboot your machine

Have a fun 🙂

Tomasz