UKOUG Conference 2010

We developed an Oracle CEP application which processes GSM network events and produces alerts. We also used Oracle Coherence to facilitate handling huge data.
My presentation about this topic has been selected for inclusion within the this year programme to present on Tuesday 30th November:

Processing Turkcell GSM Network Data with Oracle CEP
(30/11/2010 13:45 – 14:30)

I’m a bit excited because this will be my first visit to England and my first presentation in abroad :)

Installing jQuery to Application Express ( APEX )

Sometimes, you want to add different things your page such as different buttons, images, motions. JQuery API provides these wishes by using JavaScript and CSS.

For detail information, examples and to do download this api, visit http://jquery.com.

If you want to import and use this api in your Apex Application you will have to do some steps.

1 ) Download latest version of jQuery Api from http://jquery.com or customizable version at : http://jqueryui.com/download
2 ) Install those files to $ORACLE_HOME/apex/images/jquery/ folder. ( jQuery folder must be created ).
3 ) Then, you should edit the $ORACLE_HOME/apex/images/imagelist.xml file.
This file an xml file and you should add those under the directories node.



jquery
jquery/theme
jquery/theme/images

And, you should add file paths under the files node. ( Those file names should be changed if you downloaded another version instead of 1.6 Personalized JQuery )

/jquery/jquery-1.3.1.js
/jquery/jquery-ui-personalized-1.6rc6.min.js
/jquery/jquery-ui-personalized-1.6rc6.js
/jquery/theme/ui.accordion.css
/jquery/theme/ui.all.css
/jquery/theme/ui.base.css
/jquery/theme/ui.core.css
/jquery/theme/ui.datepicker.css
/jquery/theme/ui.dialog.css
/jquery/theme/ui.progressbar.css
/jquery/theme/ui.resizable.css
/jquery/theme/ui.slider.css
/jquery/theme/ui.tabs.css
/jquery/theme/ui.theme.css
/jquery/theme/images/ui-bg_diagonals-thick_18_b81900_40x40.png
/jquery/theme/images/ui-bg_diagonals-thick_20_666666_40x40.png
/jquery/theme/images/ui-bg_flat_10_000000_40x100.png
/jquery/theme/images/ui-bg_glass_65_ffffff_1x400.png
/jquery/theme/images/ui-bg_glass_100_f6f6f6_1x400.png
/jquery/theme/images/ui-bg_glass_100_fdf5ce_1x400.png
/jquery/theme/images/ui-bg_gloss-wave_35_f6a828_500x100.png
/jquery/theme/images/ui-bg_highlight-soft_75_ffe45c_1x100.png
/jquery/theme/images/ui-bg_highlight-soft_100_eeeeee_1x100.png
/jquery/theme/images/ui-icons_228ef1_256x240.png
/jquery/theme/images/ui-icons_222222_256x240.png
/jquery/theme/images/ui-icons_ef8c08_256x240.png
/jquery/theme/images/ui-icons_ffd27a_256x240.png
/jquery/theme/images/ui-icons_ffffff_256x240.png

4 ) After that, you should run apex_epg_config.sql ( in $ORACLE_HOME/apex directory ) and enter $ORACLE_HOME whichever it is, to refresh file paths.

SQL> @apex_epg_config

PL/SQL procedure successfully completed.

PL/SQL procedure successfully completed.

Enter value for 1: D:\app\TTASUNGUR\product\11.1.0\db_1\
old 1: create directory APEX_IMAGES as ‘&1/apex/images’
new 1: create directory APEX_IMAGES as ‘D:\app\TTASUNGUR\product\11.1.0\db_1\/
apex/images’

Directory created.

PL/SQL procedure successfully completed.

Commit complete.

PL/SQL procedure successfully completed.

timing for: Load Images
Elapsed: 00:00:59.68

Session altered.

PL/SQL procedure successfully completed.

Commit complete.

Session altered.

Directory dropped.

5 ) So far, you imported and installed the jquery to your Apex environment. Now, you can use jquery in your apex pages. Let’s do an example, create a page and create a region and we will create a draggable div place.

$(document).ready(function()
{
$(“#tasinabilir”).draggable( { revert: true } );

}
);

Bura tasinabilir bir bolge

( There are many examples at http://jquery.com )
6 ) Then test your page, click div place and drag it to anywhere and release, it will return its first position.

Oracle Apex 3.1 Sunumu

18 Ekimde, OracleTURK grubuna, Oracle Akademi sponsorluğunda, Kadıköy Bireysel Eğitim Merkezinde gerçekleştirmiş olduğum, Oracle Application Express v3.1 sunumu ve workshop esnasında gösterdiğim bazı özelliklere ait kodlar için tıklayın.

For english:
I present the Oracle Application Express v3.1 to OracleTurk Group, at Kadıköy Bireysel Eğitim Merkezi, sponsored by Oracle Turkiye Akademi. To access this presentation click here.

Asynchronous Ajax in Apex

We use Ajax for rapid query processing without submitting page. In apex, you can build ajax within your pages. For this purposes, we use “Application Process” under the Shared Components.

Sometimes, Application Process can not response rapidly. For example, if you query a count from very large table, it takes for minutes or hours. If you put a text field for table name and if user can query number of records of input big table, also if you perform this operation with ajax in apex as synchronously, the BROWSER will freeze and consumes %100 cpu time. Everything will go bad.

In this situation, you have to use “Asynchronous Ajax” opposite of Synchoronous, so you can more than one job on same time. To perform this, give an eye to this example:

Firstly, you can build your ajax javascript :


function getNumberOfRecords(){
var ajaxRequest = new htmldb_Get(null,&APP_ID.,'APPLICATION_PROCESS=GetCount',0);
ajaxRequest.add('P6_TABLE_NAME',html_GetElement('P6_TABLE_NAME').value);
ajaxRequest.GetAsync(f_AsyncReturn);
ajaxRequest = null;
}

This code is used to connect your apex page with your application process. ( By the way, Application Processes are need to created as On Demand ). In normally, synchronous method, you call get() method of ajaxRequest object. Pay attention to this, in asynchronous method, you need to call GetAsync() method by passing an Object. What is the f_AsyncReturn ? :


function f_AsyncReturn(){
if(p.readyState == 1){
$x('P6_TEXTAREA').value = '';
}else if(p.readyState == 2){
}else if(p.readyState == 3){
}else if(p.readyState == 4){
$x('P6_TEXT_AREA').value = p.responseText;
// you can add other things add this area
}else{return false;}
}

If you coded ajax in other languages such as php,jsp; probably you coded as above. There are 4 states to deal with ajax. One of them (state 1) is “Loading”, one of them (state 4) is “Success”. Result of ajax is written in 4. states. Before ajax Request is completed, you can write “Loading” message in first state.

The other operations are the same with Synchronous method. You need to create an Application Process, it’s running time must be “On Demand” as well.

So, by performing this Asynchronous method, your browser will not be freezed. And, not consuming all of CPU time. But disadvantage of this ( may be not seemed apparently ), your job is take much time rather than synchronous method. But, it is worth!

Running DDL Statements on Remote Database

You cannot run any DDL statement on a remote databases via using our custom remote sqls.

CREATE TABLE EMP@DB1 …

This causes an error. Instead of this you can use the Dynamic Sql to produce ddl statement to execute it when it is called.

For example, There are two DB. A_DB and B_DB. We write this function in A_DB:


CREATE OR REPLACE PROCEDURE dyn_sql( v_Sql_in VARCHAR2 )
IS
curName INTEGER;
iRet INTEGER;
BEGIN
curName := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(curName, v_sql_in, DBMS_SQL.NATIVE);
iret := DBMS_SQL.EXECUTE(curName);
DBMS_SQL.CLOSE_CURSOR(curName);
END;

When you call this procedure as “exec dyn_sql(‘CREATE TABLE EMP (EMPNO INTEGER)’);” in B_DB database, an EMP table will be created in A_DB database.

About Returning Into Clause on Remote DB – ORA-22816

We use PL/SQL RETURNING INTO clause for returning value(s) after dml commands(INSERT,UPDATE,DELETE). Assume that you would insert row a employee table with employee_id value. Likely, you type this sql statement:


INSERT INTO TEMPLOYEES (EMP_ID,EMP_NAME) VALUES( SEQ_TEMPLOYEES.NEXTVAL,'FUAT SUNGUR');

After this statement you need this employee_id to add another table. You can use RETURNING INTO clause to get employee_id value after an insert statement as follows:


INSERT INTO TEMPLOYEES (EMP_ID,EMP_NAME) VALUES( SEQ_TEMPLOYEES.NEXTVAL,'FUAT SUNGUR') RETURNING EMP_ID INTO iEmpId;

After these, iEmpId variable has employee_id value.
There is no problem if you perform these on one database.

If you want to perform this between databases, likely you would get :

ORA-22816: unsupported feature with RETURNING clause

This error may be pothering and discouraging you to what do you want. We can use other tactic to perform our willings.

Assume that you have two databases A_DB, B_DB and in B_DB databases you want to add a row in Employee Table that table in A_DB. In this situation you take advantage of functions. Write a function that returns the sequence number of just added row.


FUNCTION INSERT_EMPLOYEE_AND_GET_SEQ(vEmpName_in IN VARCHAR2)
RETURN INTEGER
IS
iEmpId INTEGER;
BEGIN

INSERT INTO TEMPLOYEES (EMP_ID,EMP_NAME) VALUES (SEQ_TEMPLOYEES.NEXTVAL,vEmpName_in) RETURNING EMP_ID INTO iEmpId;
RETURN iEmpId;
EXCEPTION
WHEN OTHERS THEN NULL;
END;

Also you have add function parameter to whether the returning into is used or not. May be this sequence number is need only once and after you would use that sequence to insert employee. So, there are lots of need why you do it.

Google Syntax Highlighter for PL/SQL

Google Syntax Highlighter App. provides us to show code in our blogs or other html pages. This application shows code of C,Java,Jscript,C#,SQL,XML,Ruby,Phyton. But as you predicted, Oracle PL/SQL is missing. So, i decided to develop a code to highlight our Oracle/PLSQL code. Things you have to do them are as follows :

  • Download the Google Syntaxlighter to your pc: http://code.google.com/p/syntaxhighlighter/
  • Then upload the folder that is extracted from zip file, to your server.
  • For blogger, go to your template page and edit.
  • After first head tag and before the closed head tag you should write some javascript code to template page.
  • The template page should look alike this page :

    <link type=”text/css” rel=”stylesheet” href=”http://xxx.googlepages.com/SyntaxHighlighter.css”></link>

    <script language=”javascript” src=”http://xxx.googlepages.com/shCore.js”></script>

    <script language=”javascript” src=”http://xxx.googlepages.com/shPlsql.js”></script>

    ….

    ….

    ….

    // dont modify if you dont want to change template except to show coding

    ….

    <script language=”javascript”>

    window.onload = function () {

    dp.SyntaxHighlighter.ClipboardSwf = ‘http://afsungur.googlepages.com/clipboard.swf’;

    dp.SyntaxHighlighter.BloggerMode();

    dp.SyntaxHighlighter.HighlightAll(‘code’);

    }

    </script>

  • Then writing a post, you should write your pl sql code as follows:

    <pre name=”code” class=”plsql”>

    … your pl sql code …

    </pre>

Download shBrushPlSql.js

(This is compatible with reserver words and keywords of Oracle Latest Version )

After all of these step, now you can test your plsql code. Like this :)


CREATE OR REPLACE PACKAGE BODY PKG_RULE_CONTROL IS

-- CREATED BY A. FUAT SUNGUR
-- afsungur@gmail.com
--
--
-- Kural ile ilgili islemleri gerceklestiren pakettir

------------------------------------------------------------------------------------------
-- DBMS_SCHEDULER tarafindan cagrilacak pl sql blogunun dinamik olarak uretilmesini saglar
-- RUN_JOB prosedurune gonderilecek parametreler dinamik olarak ayarlanir.
FUNCTION PRODUCE_JOB_SQL
(
vExpr_1 VARCHAR2,
vExpr_2 VARCHAR2,
nCond_Id NUMBER,
iRuleId NUMBER
) RETURN VARCHAR2 IS

vJobSql VARCHAR2(2000);
iSqlCode INTEGER;
vSqlErrMsg VARCHAR2(250);

BEGIN
-- CHR(39) = ' ( tek tirnak )
IF (vExpr_2 IS NOT NULL)
THEN
vJobSql := 'BEGIN PKG_JOB_CONTROL.RUN_JOB(' || CHR(39) ||
vExpr_1 || CHR(39) || ',' || CHR(39) || VExpr_2 ||
CHR(39) || ',' || nCond_Id || ',' || iRuleId ||
'); END;';
ELSE
vJobSql := 'BEGIN PKG_JOB_CONTROL.RUN_JOB(' || CHR(39) ||
vExpr_1 || CHR(39) || ',NULL,' || nCond_Id || ',' ||
iRuleId || '); END;';
END IF;
RETURN vJobSql;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
INSERT INTO TERRORS
VALUES
(SEQ_TERRORS.NEXTVAL,
iSqlCode,
vSqlErrMsg,
CURRENT_TIMESTAMP,
'FUNCTION PKG_RULE_CONTROL.PRODUCE_JOB_SQL()');
COMMIT;
RETURN NULL;
END;
END;

Creating your own authentication method in Apex

With this operation, you can do your own login page instead of default apex login page.

Firstly, you need to create a package that deal with user login operations. PKG_APP_SECURITY package name is appropriate for this need.


CREATE OR REPLACE PACKAGE BODY PKG_APP_SECURITY
AS

PROCEDURE login

(p_uname IN VARCHAR2,
p_password IN VARCHAR2,
p_session_id IN VARCHAR2,
p_flow_page IN VARCHAR2)
IS
BEGIN
-- THIS PROVIDES AUTHENTICATION
wwv_flow_custom_auth_std.login (
p_uname => p_uname,
p_password => p_password,
p_session_id => p_session_id,
p_flow_page => p_flow_page || ':' || 1);

EXCEPTION
WHEN OTHERS
THEN RAISE;
END login;

PROCEDURE add_user (p_username IN VARCHAR2, p_password IN VARCHAR2)
AS
BEGIN
INSERT INTO P_USERS (username, PASSWORD)
VALUES (UPPER (p_username),
get_hash (TRIM (p_username), p_password));

COMMIT;
EXCEPTION
WHEN OTHERS
THEN ROLLBACK; RAISE;
END add_user;

FUNCTION get_hash (p_username IN VARCHAR2, p_password IN VARCHAR2)
RETURN VARCHAR2
AS
BEGIN
RETURN DBMS_OBFUSCATION_TOOLKIT.md5 (
input_string => UPPER (p_username) || '/' || UPPER (p_password));
END get_hash;

PROCEDURE valid_user2 (p_username IN VARCHAR2, p_password IN VARCHAR2)
AS
v_dummy VARCHAR2 (1);

BEGIN

SELECT '1' INTO v_dummy
FROM P_USERS
WHERE UPPER (username) = UPPER (p_username)
AND PASSWORD = get_hash (p_username, p_password);

EXCEPTION
WHEN NO_DATA_FOUND
THEN raise_application_error (-20000, 'Invalid username / password.');
END valid_user2;

FUNCTION valid_user (p_username IN VARCHAR2, p_password IN VARCHAR2)
RETURN BOOLEAN
AS
BEGIN
valid_user2 (UPPER (p_username), p_password);
RETURN TRUE;
EXCEPTION
WHEN OTHERS
THEN RETURN FALSE;
END valid_user;

END PKG_APP_SECURITY;

The P_USERS table has two columns, types of both columns are varchar2 and first of them is username and second of them is password.

Secondly, you should use an authentication schema. To perform this, in Shared Components, click Authentication Schemas. Then Create Button.

1-> Click “Create Schema” Button.
2-> Write your own authentication schema name, such as “MY AUTH METHOD”.
3-> Then “Create Scheme” button.
4-> After scheme is created, click your authentication schema icon in authentication schemas page.
5-> Then Login Processing tab, in “Authentication Function” textarea, type this:
“RETURN PKG_APP_SECURITY.valid_user”
6-> If this method return false in application the authentication is not successfullied.
7-> Don’t forget, you should set your own authentication schema to as current used.

Last thing we need to do, edit your login page (genrally page 101). Then, in processes tab ( in page processing tab ), click login process. And, type this to process textarea in source tab:
“pkg_app_security.login (P_UNAME => :P 101_USERNAME, P_PASSWORD => :P 101_PASSWORD, P_SESSION_ID => v(‘APP_SESSION’), P_FLOW_PAGE => :APP_ID );”.

After performed these 3 steps, you can use your own login page with your own user tables in Apex Applications.

Installing Application Express 3.1 on Oracle 10g 10.2.0.1.0

In installing apex on Oracle 10g 10.2.0.1.0, i was getting a XDB Login Problem. I setup apex and entering the url path of apex, then browser ask me repeatedly xdb username and password. I tried lots of things that could not solve this problem. Especially this problem take place in Oracle 10g 10.2.0.1.0. I searched lots of web pages, forum, blogs then i found the solution.

Firstly, download the apex_3.1.1.zip in Oracle Web page. Then extract this file to Oracle Home.
When you type “dir /b” or “ls -la” in Oracle Home, you should see same this :

G:\oracle\product\10.2.0\db_3>dir /b
1907-b75f9673d7_orcl
admin
apex
assistants
BIN
cdata
cfgtoollogs
clone
com
config
….

So, type “cd apex” to enter this folder. Then run sqlplus as sysdba.
And execute the @apexins (apexins.sql).

Then, to change the ADMIN user password type the @apxxepwd.

After these, you should configure the Embedded PL SQL Gateway ( if you wont use the oracle http server like me).

Type @apex_epg_config to configure the plsql gateway.
Then, unlock the ANONYMOUS user, type “ALTER USER ANONYMOUS ACCOUNT UNLOCK”.
After these, now we are at the last point.
To enable XML DB HTTP SERVER :
exec dbms_xdb.sethttpport(7780);
// if you enter a port of used service, you can’t run the apex.
// so do not enter the Apache Tomcat Port : 8080

If XDB username and password is questioned, you should run this command:
( I found it after lots of searching )
EXEC DBMS_EPG.authorize_dad ( dad_name => ‘APEX’, user => ‘ANONYMOUS’ );

Now, you can try to login the Apex page via typing “http://localhost:7780/apex/apex_admin”.

If it asks still XDB username and password, you should read this blog and comments carefully.

http://jeffkemponoracle.blogspot.com/2007/07/apex-30-via-embedded-plsql-gateway.html

If you encounter any problem, send an email or comments.

Materialized View

Oracle DW uygulamalarında sıkça rastlayabileceğimiz bir yapı olan Materialized Viewları, saklı tablo sonuçları olarak düşünebiliriz. Normal Viewlardan farkı, bir sql sorgusu olarak değil de sql sorgusu + data olarak saklanmasıdır. Yani MV diskte yer kaplar.

Peki neler yapılıyor MVlerle, milyonlarca kayıt bulunan tabloda belli sorguları önceden çalıştırıp bunun sonuçlarını saklama işlemini yapıyoruz.
Örneğin, bir satış tablomuz var, 5 milyar kaydımız var bu tabloda, 100 id’li müşterinin o günkü toplam harcamalarını öğrenmek istiyoruz. Bu öğrenme işi çok fazla kez tekrar ediliyor diyelim. 5 milyar kayıt içinde group by, sum() gibi sql özelliklerini kullanmak çok fazla kaynak kullanımına sebebiyet vereceğinden dolayı, bu işlemlerin önceden bir yerde tutulması bizim işimize yarayacaktır.

Yazının başında belirtildiği gibi, Data Warehouse sistemlerde özellikle kullanılan bir yapı, biraz real-time uygulamaların dışında gerçekleştirilebilir diyebiliriz. Örneğin salı günkü verilerden yola çıkarak, çarşamba günü rapor hazırlama işlemleri bu şekilde daha hızlı gerçekleştirilebilir. Salı akşamı sorgular çalıştırılır, MV’ler güncellenir, çarşamba günü sorgular çalıştırıldığında Ana tablo yerine bu MV’lerden ilgili bilgiler çekilmiş olur. Yani 5 milyar kayıt içinde arayacağımıza, çok daha az miktarda veri içinde arama yapmış olacağız. Bu da bizim kaynakları kullanma performansımızı arttıracak. Fakat bu durumda güncel verilerden yararlanmamış oluyoruz, sadece önceki güne ait verilerden yararlanmış oluyoruz. Bunu önleme yöntemleri de mevcut, MV’de.

MV’de bilinmesi gereken en önemli özelliklerden birisi de Query Rewriting özelliği. Bu özellik Session bazında ve MV oluştururken enable yapıldığı takdirde, MV ‘in sql sorgusu çalıştırıldığında ana tablo yerine MV’den veriler çekilmiş oluyor. Şöyle ki, MV yi oluştururken “SELECT * FROM SALES” olarak oluşturduğumuz zaman, Query Rewriting özelliği enable olur ise, “SELECT * FROM SALES” sorgusu çalıştırıldığında, CBO ( Cost Based Optimizer ) bu sorgunun aslında MV’den çekilmesine karar verir ve yazılan sorguyu MV’yi işaret edecek şekilde ( örn : “SELECT * FROM MV_SALES” ) değiştirirr ve sorguyu yapan farkında olmadan MV kullanılmış olur.

Eğer bu özellik enable edilmez ise, MV’den yararlanmak için sorgu yazılırken MV direk işaret edilmelidir. “SELECT * FROM MV_SALE” gibi, aksi takdirde direk ana tablodan veriler çekilir.

Follow

Get every new post delivered to your Inbox.