Authid current_user, authid definer

There are 2 interesting PRAGMA which can be defined for procedures/functions and packages:

AUTHID CURRENT_USER –  specify CURRENT_USER to indicate that the code executes with the privileges of CURRENT_USER. This clause also specifies that external names in queries, DML operations, and dynamic SQL statements resolve in the schema of CURRENT_USER. External names in all other statements resolve in the schema in which the code resides. All roles for CURRENT_USER are active for dynamic code (EXECUTE IMMEDIATE) and disabled for static compilation.

AUTHID DEFINER – specify DEFINER to indicate that the code executes with the privileges of the owner of the schema in which the package resides and that external names resolve in the schema where the code resides. This is the default and creates a definer’s rights package. All roles for DEFINER are disabled for dynamic code(EXECUTE IMMEDIATE) and static compilation.

In this article I want to show specific feature for AUTHID CURRENT_USER enabled roles for dynamic code.

Continue reading

Install Oracle 11G Release 2 (11.2) on Oracle Linux 6 (OEL6)

This article presents installation of Oracle 11.2.0.3 on OEL6.

Read following article to install OEL6 Linux: Install Oracle Linux 6 64 bit(for comfort set 2G memory for your virtual machine). During OEL6 installation I drop user oracle and both group dba and oinstall.

11.2.0.3 installation guide presents full separation of grid and oracle user.

Add groups

/usr/sbin/groupadd -g 501 oinstall
/usr/sbin/groupadd -g 502 dba
/usr/sbin/groupadd -g 503 oper
/usr/sbin/groupadd -g 504 asmadmin
/usr/sbin/groupadd -g 505 asmdba
/usr/sbin/groupadd -g 506 asmoper
Add users
/usr/sbin/useradd -u 501 -g oinstall -G asmadmin,asmdba,asmoper,dba grid
/usr/sbin/useradd -u 502 -g oinstall -G dba,asmdba oracle
Continue reading

Install Fedora 17

This article presents how to install Fedora 17.

I assume you have already downloaded Fedora 17 64 bit(about 3.5 G)  and you know how to use VirtualBox 64 bit(100M). Create virtual machine with default settings for Linux Fedora 64 bit. 1GB ram and 64G for disk is enough plus increase video memory to 128M and turn on accelaration 3D. Rest of options you can keep default.

Continue reading

Virtual Columns in tables 11G

This article presents new feature of 11g Virtual column.

Virtual column – a column that is not stored on disk. Value of the column is calculated by expression or function.

column_name [datatype] [GENERATED ALWAYS] AS (expression) [VIRTUAL]

GENERATED ALWAYS and VIRTUAL keywords are optional

Example:

--create deterministic function used by virtual column
CREATE OR REPLACE FUNCTION add_fnc(p_id NUMBER)
RETURN NUMBER
deterministic
IS
BEGIN
  RETURN p_id + 3;
END;
/
 
CREATE TABLE test_tbl
(
  static_col   NUMBER,
  --virtual column using simple syntax expression
  vir_col1 NUMBER AS (static_col + 1),
  --virtual column using long syntax expression
  vir_col2 NUMBER generated always AS (static_col+2)        virtual, 
  --virtual column long syntax with function
  vir_col3 NUMBER generated always AS (add_fnc(static_col)) virtual
)
--partition by virtual columns
PARTITION BY RANGE(vir_col2)
subpartition BY hash(vir_col1) subpartitions 4
(PARTITION p1 VALUES less than(maxvalue));
 
--add primary key using virtual column
ALTER TABLE test_tbl add constraint test_tbl primary key(vir_col1);

Continue reading

Install and configure Apex 4.2.X embedded PL/SQL

This article presents how to install and configure Apex for version 4.2, 4.2.1, 4.2.2, 4.2.3, 4.2.4, 4.2.5

Prepare software to installation

Download installation package from Oracle site and unzip.

Download apex_4.2.X.zip to directory /tmp and unzip it from
http://www.oracle.com/technetwork/developer-tools/apex/downloads/index.html

cd /tmp
unzip <downloaded software>

After unzip is completed a new directory will be created /tmp/apex so go to this directory and log into database as SYSDBA. Always use SYSDBA account for running all scripts.

cd /tmp/apex
sqlplus / as sysdba

Pre-installation steps

It’s recommended to do backup of the database and disable the Oracle XMLDB HTTP server by setting the HTTP port to 0.

EXEC DBMS_XDB.SETHTTPPORT(0);

Continue reading

Install Oracle 11G Release 2 (11.2) on Oracle Linux 5 (OEL5)

This article presents how to install Oracle 11.2.0.3 on OEL5.

Read following article to install OEL5 Linux: Install Oracle Linux 5 64 bit (for comfort set 2G memory for your virtual machine). During OEL5 installation I drop user oracle and both group dba and oinstall.

11.2.0.3 installation guide presents full separation of grid and oracle user.

Continue reading

Install Oracle Linux 5 (OEL5)

This article presents how to install Oracle Linux 5.

I assume you have already downloaded Oracle Linux 5 64 bit(about 3.5 G) from OTN and you know how to use VirtualBox 64 bit(100M) which is also available on OTN. Create virtual machine with default settings for Oracle Linux 64 bit. 1GB ram and 64G for disk is enough to run OEL5 64-bit. Rest of options you can keep default.

Continue reading

Create table as select and NULL columns views

Sometimes it’s usefull to define NULL columns in views. But there is problem to use such view for CREATE TABLE AS SELECT

--simple view with 3 null columns
create or replace view test_vw
as
select null a, null b, null c 
from dual;

it’s impossible to create table based on such view

desc test_vw
Name Null Type       
---- ---- ---------- 
A         VARCHAR2() 
B         VARCHAR2() 
C         VARCHAR2() 

create table test_tbl
as
select * from test_vw;

SQL Error: ORA-01723: zero-length columns are not allowed
01723. 00000 -  "zero-length columns are not allowed"

to solve this problem define column size for null columns

create or replace view test_vw
as
select 
  cast( null as varchar2(10) ) a, 
  cast( null as date ) b, 
  cast( null as number ) c
from dual;

desc test_vw

Name Null Type         
---- ---- ------------ 
A         VARCHAR2(10) 
B         DATE         
C         NUMBER     

create table test_tbl
as
select * from test_vw;

table TEST_TBL created

Hope it helps 🙂

Tomasz