Tuesday, March 19, 2013

Joomla or Wordpress

Doing some web site revamp recently, and amazed by the easiness and friendless of making website and there are so many nice templates you could choose, too many choice.

Looks Word press is very popular and I did get one for one of my clients, and will make it ready for themselves to update the content. For Joomla, was working with it before, and seems more complicated and powerful than Word press.

For my next project, I would like to choose Joomla if I could get the template I like. Now start to clean our hosting site stuff, so many blog/forum when I was testing. I would like to have one good forum package well support multiple languages such as English and Chinese.

Over all, here is a nice way to decide if you have difficult to choose which one:
(picture from http://www.sitepoint.com/ and thanks!)

Just now working on 2 templates, one is WordPress, one is Joomla, WordPress is OK to apply the dump.sql, but Joomla is a pain when dealing with different version. If I have time, I will definitely create my own template instead of buying. The version compatibility of Joomla is sure a pain.

Thursday, March 14, 2013

Confucius and Confusion

Sounds really funny, since I was very young I am a confused boy, very puzzled and bewildered, but never lost for what I want.

I am confused by the life, the meaning of life, and think the world is full of confusion. That's why I picked confusion as my nick. Then I tried to find the adjective for confusion and I don't like confusional(?), so I decided to use confusious(even though no such word), then people are thinking I was wrong and should be confucius. Well, should I change this to the famous ancient great Master Kong? Let me know your answer:)

Confucius Says (子曰)is so profound, and let's review the Top 10 quotes from Master Kong (so many and I just pick what I like:):

Just a thought: I have to say sorry to Master Kong, since in the end he was confused and failed. The Only savior is Our Lord! Don't you agree?!

1. “Never impose on others what you would not choose for yourself.”

己所不欲,勿施于人。

2. “Real knowledge is to know the extent of one’s ignorance.”

知之为知之,不知为不知,是知也。

3. “Keep what you say and carry out what you do.”
言必信,行必果。

4. “A gentleman sets strict demands on himself while a petty man set strict demands on others.”

君子求诸己,小人求诸人。

5. “The Superior Man is aware of Righteousness, the inferior man is aware of advantage.”

君子喻於义,小人喻於利。

6. “The gentleman wishes to be slow in speech but quick in action.”
君子欲讷于言而敏于行。

7. “When I walk along with two others, they may serve me as my teachers.”

三人行,必有我师焉。

8. “He who learns but does not think, is lost. He who thinks but does not learn is in great danger.”

学而不思则罔,思而不学则殆。

9. “He that would perfect his work must first sharpen his tools.”

工欲善其事,必先利其器。

10. “If you look into your own heart, and you find nothing wrong there, what is there to worry about? What is there to fear?”

君子坦荡荡,小人长戚戚。

太多啦,加一个:有朋自远方来,不亦乐乎?
Is it not delightful to have friends coming from distant quarters?

Friday, March 1, 2013

ORCL - LISTAGG

Very handy Listagg Function
 
During my daily routine, I constantly need to display multiple values for single row, I have to write a few lines of code until the LISTAGG function!
 
Description of listagg.gif follows
 
 
Examples from oracle
 
The following single-set aggregate example lists all of the employees in Department 30 in the hr.employees table, ordered by hire date and last name:
 
SELECT LISTAGG(last_name, '; ') WITHIN GROUP (ORDER BY hire_date, last_name) "Emp_list",
    MIN(hire_date) "Earliest"
    FROM employees
    WHERE department_id = 30;

Emp_list                                                     Earliest
------------------------------------------------------------ ---------
Raphaely; Khoo; Tobias; Baida; Himuro; Colmenares            07-DEC-02
 
 

Wednesday, August 29, 2012

ORCL - Restart Database and EM

Back from a week vacation and found that the database is not working as well the ORCLE EM. What a pity for me as a newbie DBA without any mentor or help inside office. The good thing is I have Intenet to look for help....

OK, after half day working around, here I record the steps after server is accidently shutdown:

1. my bad is not setup swap space persistent, so I have to swap -a to make enough space, will do the persistent setup for swap space.
swap -a /export/home/oracle/orcl_swap then swap -l to check

2. Start the listener: lsnrctl start

3. Set up the ORACLE_SID, could add the line in .profile: export ORACLE_SID=orcl

4. Set up the ORACLE_HOSTNAME and UNQNAME for ORALE EM
export ORACLE_HOSTNAME=solaris
export ORACLE+UNQNAME=orcl
OM will look inside folder solaris_orcl

5. Startup database
sqlplus / as sysdba then startup

6. Start Oracle EM
emctl start dbconsole

Thanks to the link ORACLE-BASE.com:
http://www.oracle-base.com/articles/misc/basic-enterprise-manager-troubleshooting.php

Tuesday, July 24, 2012

ORCL - Data Pump

We need move 10g production data into 11g test so we could test advance system upgrade, there are three upgrade methods offered to upgrade database from 10g to 11g.
  1. Database Upgrade Assistant (DBUA)
  2. Manual Upgrade (Oracle provided scripts)
  3. Export/Import (exp/imp, or expdp/impdp)
Using data pump looks promising, I prefer using Oracle EM, rather than manually following the steps:
1 impdp user/pass full=y directory =test_dir logfile=exp.log dumpfile=exp.dmp
2 copy dump file to new server
3 create database in new server with same tablespaces as source database -- IS IT NECESSARY?! (if different structure)
4 impdp user/pass full=y directory =test_dir logfile=exp.log dumpfile=exp.dmp

I used EM and finally got this error:
ORA-39126: Worker unexpected fatal error in KUPW$WORKER.LOOK_FOR_OBJECT 
looks some problem with temp tablespace:
assign the temp tablespace to the schema owner as Oracle is probably using whatever default TEMP tablespace is specified for the database.
SQL> alter user advance temporary tablespace TEMP;
 
At leaset I was able to login through PL/SQL developer.





helpful links:

Monday, July 23, 2012

ORCL - Installation

I decide to blog this after some frustration on installing Oracle 11g on Solaris 10. (For Solaris 11 you need some support account to get the Oracle 11g).

Intenet has a lot of information which sometimes could mislead you if you dont read carefully :(. I will recommend to read the official manual.

1st intall Oracle-Solaris 10, pretty straight forawrd, login as root.

Preinstallation Requirements:
PACKAGE: check all needed packages: pkginfo -i SUNWarc SUNWbtool SUNWhea SUNWlibC SUNWlibms SUNWsprot \ SUNWtoo SUNWi1of SUNWi1cs SUNWi15cs SUNWxwfnt get missing package from installaton DVD if missing any:
pkgadd -d /cdrom/sol*/Solaris*/Product SUNWi1cs SUNWi15cs
GROUP AND USER:
# groupadd oinstall
# groupadd dba
# useradd -d /export/home/oracle -m -s /usr/bin/bash -g oinstall -G dba oracle
# passwd -r files oracle
KERNEL PARAMETERS (IMPORTANT!)
Set Resource Control to Oralce Recommended Value
# projadd -U oracle -K "project.max-shm-memory=(priv,6g,deny)" group.dba
# projmod -sK "project.max-sem-nsems=(privileged,256,deny)" group.dba
# projmod -sK "project.max-sem-ids=(privileged,100,deny)" group.dba
# projmod -sK "project.max-shm-ids=(privileged,100,deny)" group.dba
This will make them persist, confirm by cat /etc/project
NOTE: When you use the prctl command (Resource Control) to change system parameters, you do not have to restart the system for these parameter changes to take effect. However, the changed parameters do not persist after a system restart.
Make sure oracle user is associated with the project (group.dba). This is missing in documents, and will possible produce "out of memory" error.
# id -p oracle uid=100(oracle) gid=100(oinstall) projid=3(default)
# usermod -K project=group.dba oracle
# id -p oracle uid=100(oracle) gid=100(oinstall) projid=100(group.dba)  
SWAP (IMPORTANT!)
# swap -l swapfile dev swaplo blocks free
/dev/dsk/c0t0d0s1 30,65 8 1092408 1092408
# mkfile 4096m /export/home/oracle/orcl_swap
# swap -a /export/home/oracle/orcl_swap
# swap -l swapfile dev swaplo blocks free
/dev/dsk/c0t0d0s1 30,65 8 1092408 1092408
/export/home/oracle/orcl_swap - 8 8388600 8388600
Now wh have enough swap space.
if you need persistent swap, add line inside /etc/vfstab.
INSTALL ORACLE Downlaod Oracle 11g and create necessary folders.
# mkdir -p /export/home/oracle/product/11.2.0/db_1
# mkdir /export/home/oracle/tmp
# chown -R oracle:oinstall /export/home/oracle
Configure profile for oracle user with enviroment variables:
vi/gedit /export/home/oracle/.profile
export ORACLE_BASE=/export/home/oracle
export ORACLE_HOME=$ORACLE_HOME/product/11.2.0/db_1
export PATH=$ORACLE_HOME/bin:$PATH
export TMP=/export/home/oracle/tmp
export TMPDIR=/export/home/oracle/tmp
export DISPLAY=0:0
Unzip and install
# unzip solaris.x64_11gR2_database_1of2.zip
# unzip solaris.x64_11gR2_database_2of2.zip
# cd databse
# ./runInstaller

After 5 time installation I am feeling OK with Oracle installation. Next step I woild like to copy 10g production data into 11g new server.

Tuesday, February 15, 2011

Popup Image/Text

University somehow uses the software called Sitecore for WCM(web content management), it's a dot net application using IIS. wonder why away from *nix open sources?

Anyway I have to use Sitecore to put up our Organization chart, good thing is that sitecore has the Edit Html option even though taking me some time to get famliar with the basic stuff in Sitecore.

The Chart is from Powerpoint since it was prepared for the presentation. We have adobe CS5 but looks the Powerpoint picture is the way to go. Sitecore limits the picture size to 700px, so the quality is kind of bad.

How to get better presentation of our organization chart based on the ppt converted picture:

1. Mouseover to get the original size, see effect1. This one is from Dynamicdrive.com (a super cool DHTML site)
2. Mouseover to magnify the portion, see effect2. This is also from Dynamicdrive.com, using jquery from google api libray , very cool.

The above effects have a shared weakness, can not get hotspot links, since it's a whole picture, I can only think to make link is doing hotspots.

So finally I did use CSS and javascript to have the CSS popout, as shown in effect3 , this one is ok for click the hotspots.

If ever anyone interests in the code, you can download here.

If you have any cool ways to do those thing, please drop me a link/links, appreciated.

Monday, February 7, 2011

PHP dynamic file

Was busy with html5 recently, even though the security issue and lack of broswer support. Did not wrok on php stuff for a while. I created a website long time ago, the owner doesn't want to spend money and ask some no-brain guy to maitain the site and made a big mess.

The site has a testmonial side note to display some customer's profile (a few words and pictures), they want to dynamically display different customers' profile each time (refresh, entering page, etc). So it's very easy for PHP to set up that.

step 1: creating different files names as note1, 2, 3, .....
step 2: dynamically include those files like this:
<?php include 'includes/side'.$n.'.inc'; ?>
step 3: random generating the number using rand(begin_number, end_number)

Overall just like this: <?php $n=rand(1,9); include 'includes/side'.$n.'.inc'; ?>

pretty cool? PHP is the king :)

Thursday, October 21, 2010

ORCL - How cool it is!

在oracle中把连串字符转变为table fields,原来要做loop很麻烦,现在用expression就行了。


真爽!特此记录,怕以后忘了,呵呵。

if A_PROSPECTIDS is not null

then

-- remove from prospects_main any not in list of ids:

T_UPDATESQL := 'delete from prospects_main pm where pm.id_number

not in (( select lpad(trim(regexp_substr(a_prospectids,'[^,]+{1}',1,level)), 10, 0) ids from dual

connect by level <= length(regexp_replace(a_prospectids,'[^,]*'))+1 ) ';

execute immediate T_UPDATESQL;

commit;

exception

when others then

RAISE_APPLICATION_ERROR(-20999,

priority_prospects: Error removing prospects: ' ||

sqlcode || ': ' || sqlerrm);

end;

end if;


另外在用动态的SQL (dynamic SQL)时,变量要用加串,两个双引号相当于一个单引号:

lpad(trim(regexp_substr(' ||''''|| t_formattedids ||'''' || ',' || '''' || '[^,]+{1}' || '''' || ',1,level)), 10, 0) ids from dual

connect by level <= length(regexp_replace(' ||''''|| t_formattedids ||'''' || ',' || '''' || '[^,]*' || '''' || '))+1

Thursday, August 6, 2009

TSQL - Job Failed (sp_addlinkedsrvlogin)

Hey, last time I just mentioned we are working on MS SharePoint stuff, so SQL server and T-SQL, all familar stuff...uh...

I learned database stuff through T-SQL at school, since our school has a good deal with MS, which school deesn't have? I have to admire MS's business strategy (sarcastic? I don't think so:)

So Our T-SQL team has a procedure to get data from oracle database and insert data into SQL table using OpenQuery, the procedure is working fine on local, but it failed when they put it as SQL job. The team jsut asked me to help so after quite some tries, we found the error is caused by invalid login. The log error is long and confusing, talking about expected NT user failed to login.

Then the problem is narrow down to the sp_addlinkedsrvlogin (Transact-SQL). There are 2 logins, local and remote login. The procedure uses some real account such as SA and some other accounts created for local login. The server is set up to use Windows and SQL loin option. Since I just jump in to try to help the team, I just trouble shooting from my experience without knowing all the set up in servers.

From MSDN:
[ @locallogin = ] 'locallogin'
Is a login on the local server. locallogin is sysname, with a default of NULL. NULL specifies that this entry applies to all local logins that connect to rmtsrvname. If not NULL, locallogin can be a SQL Server login or a Windows login. The Windows login must have been granted access to SQL Server either directly, or through its membership in a Windows group granted access.

after reading this, I tried to use NULL for local login, and it worked! I am not sure how to use actual local login to make it work on SQL job. I may check on this if I have time, or if the team has interest on that... And it's working, most time we are just lazy to explore more... hehe.

So I put this on net, hopefully someone has same situation and might be helpful. Long live sharing knowledge!

Wednesday, August 5, 2009

ORCL - Remove ^M in VI

Our management loves to use MS office products, Word, Excel, Sharepoint, to name a few...Our dev is Oracel/Unix, good thing we picked Oracle, since that is the main stream of univeristy? (BTW, I am working in university external relation department).

Quite often, we need get excel file to import into Oracle database and massaging data. Most colleagues use some gui developer tools such as Toad, PL/SQL Developer to do the job, which are pretty good. I like the Oracle external table (Worked a few years on SQL loader :).

To get file from local (of course Windows) to unix server, the PSCP comes handy! It's from Putty, maintained by a small team based in Cambridge, England, and easy command line. There are also some GUI tools like WinSCP, etc.

But sometimes when I convert excel into csv (comma, tab delimited), the external table will not work due to the stupid ( I should not say this :( )^M at the end of lines. UNIX treats the end of line differently than other operating systems. Sometimes when editing files in both Windows and UNIX environments, a CTRL-M character is visibly displayed at the end of each line as ^M in vi.

Good thing that Vi powerful replace command, :%s/^V^M//g, make sure ^V^M are ctrl-v and ctrl M, not copying/pasting :) . It looks not showing on VIM - GUI vi.

The :%s is a basic search and replace command in vi. It tells vi to replace the regular expression between the first and second slashes (^M) with the text between the second and third slashes (nothing in this case). The g at the end directs vi to search and replace globally (all occurrences).

Just another comment: I don't know why some IT people, especially the network/helpdesk IT guys like windows stuff so much (acutally I love that too, but just dont give up on *nix:), really user friendly? They will do anything to eacpae from any possibility of *nix stuff. Sigh... Are we thinking about converting data from Oracle to SQL server to work on Sharepoint stuff? Maybe it's good for performance.

We are IT people, we should handle everything and anything :)))

Tuesday, July 14, 2009

ORCL - sys_connect_by_path

I really want to share this cool use of sys_connect_by_path function!

To deal the unknown length of concatenating string, I need to concatenate multiple rows into 1 string without decaring at certain length such as varchar2(X).

So here is the magic, hope you like it...

select ltrim(sys_connect_by_path(names, ','),',') jonit_entities from (
select names, row_number() over (order by names) rn, count(*) over () cnt
from (select entity.pref_mail_name names
from prospect_entity P, entity
where P.Prospect_Id = &id
and P.ID_NUMBER = entity.id_number
order by P.PRIMARY_IND desc)
)
where rn = cnt
start with rn = 1
connect by prior rn = rn-1;

cheers, for detail information about sys_connect_by_path, please check here.

Thursday, June 11, 2009

Backyard and Gates

Summer is here finally, we have very poorly cared backyard, and no fence gates, which allows rabbit come in/out freely.

So I will start to put fence gates on both sides and also use some lawn edge to make backyard look a little bit nice. Also I should plant some trees in front and back yard.

What I need:

Tools: Post hole digger (buy/rent) -- How to Use A Post Hole Digger

Material: Lawn edging (trim free?), Concret block for path

Trees: What kind of? Trees at Homedepot

There is newly open Homedepot, closest to my home, so I guess I will pick most stuff over there, also there is a Walmart beside Homedepot, my wife's favourite grocery store.

Friday, May 2, 2008

Cold-Boot Attack


In cryptography, a cold boot attack is a type of side channel attack in which an attacker with physical access to a computer is able to retrieve encryption keys from a running operating system by cold booting the machine.[1] The attack relies on the data remanence property of DRAM static random access memory[2] to retrieve memory contents seconds to minutes after power has been removed. The time window for an attack can be extended to hours by cooling the memory modules. Furthermore, as the bits disappear in memory over time, they can be reconstructed, as they fade away in a predictable manner.[1]

The attack has been demonstrated to be effective against full disk encryption schemes of various vendors and operating systems, even where a Trusted Platform Module (TPM) secure cryptoprocessor is used.[1] This is because the problem is fundamentally a hardware (memory) and not a software issue. While the focus of current research is on disk encryption, any sensitive data held in memory are vulnerable to the attack.[1]

One mitigation is not to use sleep mode and to shut down a computer completely instead.[3][4] However a pre-boot PIN or password may also be required to prevent an attacker booting the normal operating system before launching the attack in the scenario where a machine is already turned off. "Notably, using BitLocker with a Trusted Platform Module (TPM) sometimes makes it less secure, allowing an attacker to gain access to the data even if the machine is stolen while it is completely powered off".[1]

Please check out the video below from U of Princeton.

Thursday, January 17, 2008

The Year of Mouse

This year is the mouse of year, and it's the first animal among 12 zodiac. The zodiac repeat every 12 years, and the whole repeat every 60 years.

I don't know who were 1st Chinese to introduce zodiac animal to Western, and I hate they use rat and boar, not using mouse and pig.

Here are the poster I made for Church Chinese New Year Celebration.

Poster:


Card:

Tuesday, November 13, 2007

PageRank and HITS

Two theses: PageRank and HITS

PageRank is the heart of Google search engine, which is originally developed by Brin and Page. PageRank is a link analysis algorithm that assigns a numerical weighting to each element of a hyperlinked set of documents, such as the World Wide Web, with the purpose of "measuring" its relative importance within the set. The algorithm may be applied to any collection of entities with reciprocal quotations and references. The numerical weight that it assigns to any given element E is also called the PageRank of E and denoted by PR(E).

Nobody does not know Google, and indeed Google became a part of the modern life. But a lot of IT people do not know HITS, a similar link analysis model / algorithm, developed by Jon Kleinburg and presented on January 1998, at least seven months earlier than Brin and Page’s presentation. From Wiki, “In fact, some credit Kleinberg's work as the inspiration for PageRank, though he's far too modest to accept that mantle.” HITS was not incorporated into a commercial search engine until 2001 when the search newcomer Teoma adopted it. Check http://www.ask.com .

Google does graciously provide public access to a very rough approximation of the PageRank score from 0-10, which can be found at http://toolbar.google.com within Google tool bar. Or you can access the scores without getting the toolbar – check http://www.seochat.com/seo-tools/future-pagerank/ .

HITS method for ranking pages uses both inlinks (inbound) and outlinks (outbound) to create two popularity scores for each page. HITS defines hubs and authorities. It’s easy to get the number of outlinks for any pages, but it’s not obvious to get the inlinks number. Try typing link:http://www.1000knots.net into Google search and notice some numbers. To find out how many links your page has in the indexes of outer search enginees, go to http://www.marketleap.com/publinkpop/ .


Picture of Jon Kleinberg

Wednesday, October 31, 2007

阿联的处女秀

07年11月31日鬼节阿联处女秀作客奥兰多,雄鹿大败而归。

阿联9分3板6犯下场,3丢1抢,场上时间25:26,值得肯定!

易建联在处子战就首发出场,他的步子迈得比当初的姚明还快些。他的首次得分也比姚明来得快,在比赛开始了近3分钟后,他先是抢断得手,上篮命中,可惜被吹走步在先。在首节还有9分07秒时,他终于在右侧跳投命中,拿下NBA正式比赛的第一分,雄鹿以6-4领先。

易建联在第三节一开始就投篮命中,将比分扳平。四本节还有9分42秒时,雄鹿由易建联投中一球。易建联在比赛还有3分23秒时又投中一球,可惜此后他马上被吹第6次犯规,处子战就提前离场。




RECAP from NBA site:

ORLANDO, Fla.(AP) Rashard Lewis scored 26 points and Hedo Turkoglu had 24 to lift the sharp-shooting Orlando Magic to a 102-83 victory over the Milwaukee Bucks in the teams' season opener Wednesday night.

Behind Turkoglu and Lewis, making his Eastern Conference debut, the Magic buried Milwaukee from behind the arc. Orlando was 12-of-22, compared with 4-of-17 for the Bucks. Lewis was 4-of-5 and Turkoglu 3-for-5.

The Magic actually shot better from 3-point range (54 percent) than from the field (44 percent).

Michael Redd scored 25 points for Milwaukee and Bobby Simmons added 16. Yi Jianlian had nine points and three rebounds in 25 minutes in his debut, sitting for several stretches in foul trouble. Andrew Bogut finished with 11 rebounds.

Yi's first NBA statistic was a turnover, but he responded the next play by blocking Turkoglu's layup. The 7-footer scored his first NBA bucket about 30 seconds later on a 22-foot jumper.

Dwight Howard had 16 points and 12 rebounds. Perhaps most importantly for Orlando, he hit eight of 10 free throws.

Friday, October 26, 2007

ORCL - Lag/Lead Over

In normalized form, the data is display as the row format, such as the following:

12:28:14 PM SQL> select id_number, degree_code from degrees where id_number = 'xxxx';

ID_NUMBER DEGREE_CODE
---------- -----------
xxxxxxxxxx PHD
xxxxxxxxxx ENG
xxxxxxxxxx MSC

But we want the result displasy as one row as different columns, basically we want the data de-normlized.

A Little SQL

If we know the identity for the degree code then we can construct a SQL statement that will handle this type of query using Rotate/Pivot Query.

First we want to get such identity, so we use the windows over function to assign the row number to identify the degree code:

12:28:50 PM SQL> select id, row_number() over (partition by id order by code) rn, code from degrees;
ID RN CODE
---------- ---------- -----------
000000xxxx 1 NUSSS
000000xxx1 1 EDBSS
000000xxx2 1 MAAAA
000000xxx2 2 PHDSS
000000xxx3 1 BCZZZ
000000xxx3 2 SCESS

The we can change the row to colum display using the code shown below:
12:35:47 PM SQL>
12:40:20 PM SQL> select id,
2 (select d1.code from
3 (select id, row_number() over (partition by id order by code) rn, code
4 from table_name) d1
5 where d1.id = A.id and rn =1) degree1,
6 (select d1.code from
7 (select id, row_number() over (partition by id order by code) rn, code
8 from table_name) d1
9 where d1.id = A.id and rn =2) degree2,
10 (select d1.code from
11 (select id, row_number() over (partition by id order by code) rn, code
12 from table_name) d1
13 where d1.id = A.id and rn =3) degree3,
14 (select d1.code from
15 (select id, row_number() over (partition by id order by code) rn, code
16 from table_name) d1
17 where d1.id = A.id and rn =4) degree4
18 from (select id from table_name group by id) A
19 /

Then we achieve what we want!

But if you use the Lag/lead over analytic function, it is even better!

SQL> select id, d1, d2, d3, d4 from
2 (select id, sequence, degree_code d1, lead(degree_code,1) over (order by sequence) d2,
3 lead(degree_code,2) over (order by sequence) d3, lead(degree_code,3) over (order by sequence) d4
4 from tale_name
5 where id= '0000000xxx')
6 where sequence = 1
7 /

ID D1 D2 D3 D4
---------- ----- ----- ----- -----
0000000xxx PHD ENG MSC

SQL> here we go! Analytic functions rock for 80% case!

Tuesday, October 23, 2007

ORCL - REF CURSOR

A REF CURSOR is basically a data type. A variable created based on such a data type is generally called a cursor variable. A cursor variable can be associated with different queries at run-time. The primary advantage of using cursor variables is their capability to pass result sets between sub programs (like stored procedures, functions, packages etc.).

Example: %ROWTYPE with REF CURSOR:

declare
type r_cursor is REF CURSOR;
c_emp r_cursor;
er emp%rowtype;
begin
open c_emp for select * from emp;
loop
fetch c_emp into er;
exit when c_emp%notfound;
dbms_output.put_line(er.ename || ' - ' || er.sal);
end loop;
close c_emp;
The bold statements basically show the use of REF CURSOR.

Example of using REF as parameter in the sub-programs of a PL/SQL block:

Sub-programs can also be called sub-routines. These are nothing but the divisions of the main program. These divisions are named and are executed when they are called by name from the main program. They will not get executed unless they are called.

declare
type r_cursor is REF CURSOR;
c_emp r_cursor;

type rec_emp is record
(
name varchar2(20),
sal number(6)
);
procedure PrintEmployeeDetails(p_emp r_cursor) is
er rec_emp;

begin
loop
fetch p_emp into er;
exit when p_emp%notfound;
dbms_output.put_line(er.name || ' - ' || er.sal);
end loop;
end;
begin
for i in (select deptno,dname from dept)
loop
open c_emp for select ename,sal from emp where deptno = i.deptno;
dbms_output.put_line(i.dname);
dbms_output.put_line('--------------');
PrintEmployeeDetails(c_emp);
close c_emp;
end loop;
end;

There are 2 basic types: Strong ref cursor and weak ref cursor
For the strong ref cursor the returning columns with datatype and length need to be known at compile time.
For the weak ref cursor the structure does not need to be known at compile time.

The strong ref_cursor and until Oracle 9i also the weak-type need to be declared in a package structure lik this:

create or replace package REFCURSOR_PKG as
TYPE WEAK8i_REF_CURSOR IS REF CURSOR;
TYPE STRONG REF_CURSOR IS REF CURSOR RETURN EMP%ROWTYPE;
end REFCURSOR_PKG;

Since Oracle 9i you can use SYS_REFCURSOR as the type for the returning REF_CURSOR.

/** From Oracle 9 */
create or replace procedure test( p_deptno IN number
, p_cursor OUT SYS_REFCURSOR)
is .........

Cheers.