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.

Friday, October 19, 2007

掀起腥风血雨,阿联!

北京时间10月19日《密尔沃基哨兵报》消息:雄鹿常规赛的首战将会在美国当地时间10月31日于奥兰多开始,随着时间的日益临近,易建联在球队训练营当中的进步非常神速。这样雄鹿全队上下都震惊不已,也让他们看到了这名来自中国的球员在篮球上的天赋和努力。按照目前的状态来看,他很可能会在常规赛掀起一场腥风血雨。

  “我非常喜欢他现在所做的这些,”球队主帅拉里-克里斯科维亚克说,“对于他的未来,我真的感到欢欣鼓舞,在他身上所体现出来的进步是非常引人瞩目的,他学东西的时候领悟得非常快。”

  “在进攻方面,他能够做到什么我自己都无法猜测,对于大多数新秀来说,不管你是来自澳大利亚、中国还是波兰,都不可能像他那样领悟得这么快。一旦他的(战术)思维都打通了的话,他在球场上就会更加轻松。我想他现在正向着自己的鼎盛状态前进。”

  易建联在过去的两场季前赛当中都先发出场,并且在场均约23分钟的时间内有9.3分7.4篮板的表现。不过他也有着全队最高的14次失误,同时命中率仅有37.8%而已。“他在篮球场上的时候串上跑下的非常活跃,并且越来越适应这里的环境。”球队中锋安德鲁-博古特评价易建联的时候说,“他用了一个月的时间才进入到比赛的状态当中,在之前他总是被媒体追着无法脱身,因此注意力不能完全集中起来,但是现在,他完全能够打好每一场球。”

  “在这里的训练非常激烈,而正是这样,才可以让我变得更加强壮,更加优秀。”易建联说。不过即使如此,他也从来没有对这些训练抱有太多的怨言,而是用自己的努力来迎接训练的挑战。

  虽然K帅对易建联的表现非常满意,但是并没有为他制定太高太苛刻的目标,而是努力的让他在新秀赛季的时候,慢慢找到自己打球的方式,适应NBA的争夺。“我已经有一个月的时间没有称赞他是一名全明星的料子了,”K帅说,“但是他目前确实正在变得越来越好,因为他总是很努力的训练,并且能够很好的阅读比赛。”

  “这就是六号新秀的潜质所在吧,你所想要从优秀球员中找寻的潜力都有,他是一个非常全面的球员,无论是技术、身高还是竞技能力,一个孩子不可能表现得非常完美,也不可能完全适应竞争,但是就我看来,在训练当中他每时每刻都在提高,因为竞争压力的存在而让他变得越来越优秀。”(球童)

Wednesday, October 17, 2007

ORCL - Functions

Oracle/PLSQL Functions
--------------------------------------------------------------------------------
Sign Function
In Oracle/PLSQL, the sign function returns a value indicating the sign of a number.
The syntax for the sign function is:
sign( number )
number is the number to test for its sign.
If number < 0, then sign returns -1.
If number = 0, then sign returns 0.
If number > 0, then sign returns 1.
Applies To: Oracle 8i, Oracle 9i, Oracle 10g, Oracle 11g
Example:
select (( SIGN( SIGN(NVL(tP.xsequence, 0) - NVL(PR.xsequence, 0)) + 1)
* NVL(tP.xsequence, 0)) +
( SIGN( SIGN(NVL(PR.xsequence, 0) - NVL(tP.xsequence,0)) + 1)
* NVL(PR.xsequence, 0) )) + 1, tp.xsequence, pr.xsequence
from tP, PR
where tP.P_Number = pr.p_number
--------------------------------------------------------------------------------

ORCL - Dependency

We have a table, and we want to find all procedures/objects do DML on this table.

If you use any IDE such as PL/SQL Developer, you will easily find any object which has anything to do with this table by checking Referenced by.

Oracle finds the object dependents with some internal tables. You can find the dependencies via selecting user_dependencies view or executing dbms_utility.get_dependency procedure.

Querying user_dependencies view:
SQL> select * from user_dependencies where referenced_name = 'ALARM_REMINDER_LOG';

Executing dbms_utility.get_dependency:
SQL> exec dbms_utility.get_dependency( 'TABLE', 'advance', 'pledge_reminder_log');

PL/SQL procedure successfully completed

Everything is from Oracle Data Dictionary? Right! Objects may have some dependencies on theirselves. When creating a package or a trigger you may need other objects. When compiling an object or executing an alter command, you make dependent objects invalid. On calling objects firstly Oracle check object status. If object s valid tehere is no problem. But if an object is invalid, Oracle tries to compile the dependent objects. If there is no problem, statement executed and object status will become valid.

Tuesday, October 16, 2007

易建联的体测数据


雄鹿公布了易建联的体测数据:

阿联的体重为246磅 (约111.6千克);

不穿鞋身高为6尺11 (约2.11米),穿鞋身高为7尺1/4寸 (约2.14米),所以他也是雄鹿最高的球员,Andrew Bogut 的穿鞋身高是7尺;

阿联的臂展为7尺3.5寸 (约2.22米),比 Bogut 长了0.5寸 (1.27厘米);

他的体脂肪率只有3.4,是全队最好的,全队次好的是 Michael Ruffin 的3.9。

雄鹿的力量与体能教练 Tim Wilson 还没让阿联进行力量测试,不过 Wilson 已给阿联制定了举重强化训练课,阿联说他上赛季在宏远每周举重两次。

“我们给他安排了计划,只要当天没有比赛,也不是星期天,他每天都会举重。”Wilson 说。“不过呢,虽然上周六我们有场季前赛,那天他想举重练习,所以也就 (破例) 练了。”

“他看起来喜欢举重。我想他知道举重会对他有好处的。”

阿联说,“我喜欢……我需要练习举重。”他也不忘开玩笑说,“我太瘦了。”

另外,雄鹿的器材管理员 Dwayne Wilson 说阿联穿的鞋子为17码,衣服则是3XL。

来源:[Milwaukee Journal Times]

Sunday, September 30, 2007

愿那灵火复兴我

愿那灵火复兴我,我很喜欢这首歌,我也渴望那灵火大大复兴我!

今天教会去领诗,由于好几次没有来,牧师,长老和兄弟们都语重心长地批评了我。我也觉的很惭愧,信主这么多年了,可是就是不能很好地为主做工。回来和LP谈谈,要相互鼓励。

我们所有的一切都是上帝所赐,我们有何理由不竭力,尽力去侍奉主呢?!

周五的诗班要参加,10月5号晚7:30。
下一次的婚姻家庭是在10月14号主日。

特此警醒自己,活着为耶稣。阿门!

Friday, September 28, 2007

姚明 & 神奇玛塔

中国男篮75-66悉尼国王
这是一场气氛颇为火爆的比赛,即使在最后时刻双方也在锱铢必较。最终中国队成功逆转以75-66战胜悉尼国王,姚明轰下全场最高的37分12篮板,易建联贡献13分7篮板4助攻……


桑巴热舞。巴西队4-0击败美国。终场哨响,光芒万丈的玛塔(Marta)望向天空,兴高采烈的队友们则跑过来为最伟大的个人表演喝彩。中国刚刚度过他们的传统节日中秋节,在这一天,月亮最圆也最明亮。如果有人拉下开关让杭州黄龙体育场陷入一片黑暗,21岁的玛塔会依然光彩夺目。她是真正的明星。

Thursday, September 27, 2007

ORCL - Blank Line

My colleage asked me if there is a way to have empty blink line inside SQL select to seperate the totals. Actullay you can use CASE to check some column (this column maybe generated in the subquery).

I tried the following statement, and it's pretty cool, just an idea to be fancy:))

Connected to Oracle9i Release 9.2.0.6.0
Connected as advance
SQL>
select CASE
WHEN receipt_number IS NULL THEN
''
ELSE
donor_id
END id_no,
receipt_number,
CASE
WHEN receipt_number IS NULL THEN
''
ELSE
to_char(amount)
END
from (select g.donor_id,
g.receipt_number,
sum(g.some_amount) amount
from table_name g
group by rollup(g.donor_id, g.receipt_number))

Wednesday, September 26, 2007

ORCL- Table Function(2)

From Oracle online docs:

Example: Querying a Table Function

The following example shows a table function GetBooks that takes a CLOB as input and returns an instance of the collection type BookSet_t. The CLOB column stores a catalog listing of books in some format (either proprietary or following a standard such as XML). The table function returns all the catalogs and their corresponding book listings.

The collection type BookSet_t is defined as:
CREATE TYPE Book_t AS OBJECT
( name VARCHAR2(100),
author VARCHAR2(30),
abstract VARCHAR2(1000));

CREATE TYPE BookSet_t AS TABLE OF Book_t;

The CLOBs are stored in a table Catalogs:CREATE TABLE Catalogs
( name VARCHAR2(30),
cat CLOB);

Function GetBooks is defined as follows:
CREATE FUNCTION GetBooks(a CLOB) RETURN BookSet_t;

The query below returns all the catalogs and their corresponding book listings.
SELECT c.name, Book.name, Book.author, Book.abstract
FROM Catalogs c, TABLE(GetBooks(c.cat)) Book;

Example: Assigning the Result of a Table Function
The following example shows how you can assign the result of a table function to a PL/SQL collection variable. Because the table function is called from the SELECT list of the query, you do not need the TABLE keyword.create type numset_t as table of number;
/

create function f1(x number) return numset_t pipelined is
begin
for i in 1..x loop
pipe row(i);
end loop;
return;
end;
/

-- pipelined function in from clause
select * from table(f1(3));

COLUMN_VALUE
------------
1
2
3

3 rows selected.

-- pipelined function in select list

select f1(3) from dual;

F1(3)
---------------------------------
NUMSET_T(1, 2, 3)

-- Since the function returns a collection, we can assign
-- the result to a PL/SQL variable.
declare
func_result numset_t;
begin
select f1(3) into func_result from dual;
end;
/

ORCL - TABLE function(1)

I have to say that I am very happy to work on Oracle DB again. I found sometimes the stored procedure we created is not very efficient. We try to avoid to use temp tables and some queries are very long and complex.

Then I thought about the Oracle9i new table function. Again from the expert James Koopmann:

So What Are Table Functions?
Table functions are a new feature in Oracle9i that allow you to define a set of PL/SQL statements that will, when queried, behave just as a regular query to table would. The added benefit to having a table function is that you can perform transformations to the data in question before it is returned in the result set. This is of great use when performing ETL (Extraction Transformation Load) operations.

The Pieces
CREATE OBJECT
Here we create our own object type called IND_TAB_PRIVS. Then we create a table of IND_TAB_PRIVS called IND_TAB_PRIVS_TABLE. The table IND_TAB_PRIVS_TABLE is what we will use to return the rows from the table function within a simple select statement.

CREATE TYPE ind_tab_privs AS OBJECT
(ITP_USER VARCHAR2(50),
ITP_USER_ROLE VARCHAR2(50),
ITP_GRANTEE VARCHAR2(50),
ITP_PRIVILEGE VARCHAR2(50),
ITP_OWNER VARCHAR2(50),
ITP_TABLE_NAME VARCHAR2(50),
ITP_GRANTED_ROLE VARCHAR2(50));
/
CREATE TYPE ind_tab_privs_table AS TABLE OF ind_tab_privs;
/
CREATE FUNCTION
I have created a set of PL/SQL statements in here or check at the bottom. There is nothing particularly interesting here but the additional clauses and statements are explained in further detail in the article. Specifically the PIPELINED, PIPE ROW, and RETURN clause are discussed.

PIPELINED Clause
Within the CREATE FUNCTION clause, there is a new option called PIPELINED. This option tells Oracle to return the results of the function as they are processed, and not wait for a complete execution or completion of the result set. This pipelining of the result set to one row at a time has the immediate advantage of not requiring excessive memory or disk staging resources.

PIPE ROW(out_rec)
The PIPE ROW statement is the interface or mechanism to send a piped row through the PIPELINED option through to the caller of the function.

RETURN Clause
This statement is only required because we are writing a function here and it is expected to RETURN something. You do not need to supply an argument to return since you are returning results through the PIPE ROW statement. Actually, the only real purpose of the RETURN clause is to give control back to the caller and allow for a NO_DATA_FOUND exception.

The SELECT Statement
Nothing too exciting here except for the TABLE operator and function call. Our newly created function ITP_GRANTS just requires you to send the owner and table name. I have supplied SCOTT' and EMP' for demonstration purposes only. You should supply your own owner and table name for which you wish to get the table permissions.

Issue at the SQL/Plus Prompt the following:
SQL> SELECT * from TABLE(itp_grants('SCOTT','EMP'));

CREATE FUNCTION itp_grants (owner VARCHAR2, table_name VARCHAR2)
RETURN ind_tab_privs_table PIPELINED IS
TYPE ref0 IS REF CURSOR;
cur0 ref0;
TYPE ref1 IS REF CURSOR;
cur1 ref1;
v_owner VARCHAR2(50);
v_table_name VARCHAR2(50);
out_rec ind_tab_privs
:= ind_tab_privs(NULL,NULL,NULL,NULL,NULL,NULL,NULL);
BEGIN
v_owner := owner;
v_table_name := table_name;
--return simple grants on the object where the grantee is not a role
OPEN cur0 FOR
'SELECT grantee "user", NULL "user_role", grantee, '
'privilege, owner,table_name, NULL granted_role '
'FROM (SELECT grantee, privilege, owner, table_name '
'FROM dba_tab_privs '
'WHERE owner = :1 AND table_name = :2 '
'AND grantee NOT IN (SELECT role FROM dba_roles)) '
USING v_owner, v_table_name;
LOOP
FETCH cur0 INTO out_rec.itp_user, out_rec.itp_user_role,
out_rec.itp_grantee, out_rec.itp_privilege,
out_rec.itp_owner, out_rec.itp_table_name,
out_rec.itp_granted_role;
EXIT WHEN cur0%NOTFOUND;
PIPE ROW(out_rec);
END LOOP;
CLOSE cur0;
--return grants on the object where the grantee is a role
--get the roles
OPEN cur0 FOR
'SELECT grantee "role", NULL "user_role", grantee, '
'privilege, owner, table_name, NULL granted_role '
'FROM (SELECT grantee, privilege, owner, table_name '
'FROM dba_tab_privs '
'WHERE owner = :1 AND table_name = :2 '
'AND grantee IN (SELECT role FROM dba_roles)) '
USING v_owner, v_table_name;
LOOP
FETCH cur0 INTO out_rec.itp_user, out_rec.itp_user_role,
out_rec.itp_grantee, out_rec.itp_privilege,
out_rec.itp_owner, out_rec.itp_table_name,
out_rec.itp_granted_role;
IF cur0%NOTFOUND THEN
RETURN;
END IF;
-- evaluate for each role and get all users
OPEN cur1 FOR
'SELECT user_role, granted_role '
'FROM ( SELECT grantee user_role, granted_role '
'FROM dba_role_privs '
'CONNECT BY PRIOR grantee = granted_role '
'START WITH granted_role = :1 ) '
'WHERE user_role NOT IN (SELECT role FROM dba_roles) '
USING out_rec.itp_user;
LOOP
FETCH cur1 INTO out_rec.itp_user,
out_rec.itp_granted_role;
EXIT WHEN cur1%NOTFOUND;
IF out_rec.itp_user != v_owner THEN
PIPE ROW(out_rec);
END IF;
END LOOP;
END LOOP;
CLOSE cur0;
CLOSE cur1;
RETURN;
END itp_grants;
/

next blog I may study more about this feature, and see if we can use this for our daily job.

Tuesday, September 25, 2007

ORCL Interview Qs

Today we are talking about the interview questions we had during interview for Oracle jobs, I found some great questions/answers from James F. Koopmann(Database Expert) :

Here are the next 30 in this section. Depending on the mood of the interview and your ability to elaborate on the answer, try to give some insight that you know more than just the simple answer to some of these questions. Also, be sensitive to the interviewer getting tired of you talking too much. Well here they are.

21. How would you determine the time zone under which a database was operating?
select DBTIMEZONE from dual;

22. Explain the use of setting GLOBAL_NAMES equal to TRUE.
Setting GLOBAL_NAMES dictates how you might connect to a database. This variable is either TRUE or FALSE and if it is set to TRUE it enforces database links to have the same name as the remote database to which they are linking.

23. What command would you use to encrypt a PL/SQL application?
WRAP

24. Explain the difference between a FUNCTION, PROCEDURE and PACKAGE.
A function and procedure are the same in that they are intended to be a collection of PL/SQL code that carries a single task. While a procedure does not have to return any values to the calling application, a function will return a single value. A package on the other hand is a collection of functions and procedures that are grouped together based on their commonality to a business function or application.

25. Explain the use of table functions.

Table functions are designed to return a set of rows through PL/SQL logic but are intended to be used as a normal table or view in a SQL statement. They are also used to pipeline information in an ETL process.

26. Name three advisory statistics you can collect.
Buffer Cache Advice, Segment Level Statistics, & Timed Statistics

27. Where in the Oracle directory tree structure are audit traces placed?
In unix $ORACLE_HOME/rdbms/audit, in Windows the event viewer

28. Explain materialized views and how they are used.
Materialized views are objects that are reduced sets of information that have been summarized, grouped, or aggregated from base tables. They are typically used in data warehouse or decision support systems.

29. When a user process fails, what background process cleans up after it?
PMON

30. What background process refreshes materialized views?
The Job Queue Processes.

31. How would you determine what sessions are connected and what resources they are waiting for?
Use of V$SESSION and V$SESSION_WAIT

32. Describe what redo logs are.
Redo logs are logical and physical structures that are designed to hold all the changes made to a database and are intended to aid in the recovery of a database.

33. How would you force a log switch?
ALTER SYSTEM SWITCH LOGFILE;

34. Give two methods you could use to determine what DDL changes have been made.
You could use Logminer or Streams

35. What does coalescing a tablespace do?
Coalescing is only valid for dictionary-managed tablespaces and de-fragments space by combining neighboring free extents into large single extents.

36. What is the difference between a TEMPORARY tablespace and a PERMANENT tablespace?
A temporary tablespace is used for temporary objects such as sort structures while permanent tablespaces are used to store those objects meant to be used as the true objects of the database.

37. Name a tablespace automatically created when you create a database.
The SYSTEM tablespace.

38. When creating a user, what permissions must you grant to allow them to connect to the database?
Grant the CONNECT to the user.

39. How do you add a data file to a tablespace?
ALTER TABLESPACE ADD DATAFILE SIZE

40. How do you resize a data file?
ALTER DATABASE DATAFILE RESIZE ;

41. What view would you use to look at the size of a data file?
DBA_DATA_FILES

42. What view would you use to determine free space in a tablespace?
DBA_FREE_SPACE

43. How would you determine who has added a row to a table?
Turn on fine grain auditing for the table.

44. How can you rebuild an index?
ALTER INDEX REBUILD;

45. Explain what partitioning is and what its benefit is.
Partitioning is a method of taking large tables and indexes and splitting them into smaller, more manageable pieces.

46. You have just compiled a PL/SQL package but got errors, how would you view the errors?SHOW ERRORS

47. How can you gather statistics on a table?
The ANALYZE command.

48. How can you enable a trace for a session?
Use the DBMS_SESSION.SET_SQL_TRACE orUse ALTER SESSION SET SQL_TRACE = TRUE;

49. What is the difference between the SQL*Loader and IMPORT utilities?
These two Oracle utilities are used for loading data into the database. The difference is that the import utility relies on the data being produced by another Oracle utility EXPORT while the SQL*Loader utility allows data to be loaded that has been produced by other utilities from different data sources just so long as it conforms to ASCII formatted or delimited files.

50. Name two files used for network connection to a database.
TNSNAMES.ORA and SQLNET.ORA
Technical - UNIX

Every DBA should know something about the operating system that the database will be running on. The questions here are related to UNIX but you should equally be able to answer questions related to common Windows environments.

1. How do you list the files in an UNIX directory while also showing hidden files?ls -ltra

2. How do you execute a UNIX command in the background?Use the "&"

3. What UNIX command will control the default file permissions when files are created?Umask

4. Explain the read, write, and execute permissions on a UNIX directory.Read allows you to see and list the directory contents.Write allows you to create, edit and delete files and subdirectories in the directory.Execute gives you the previous read/write permissions plus allows you to change into the directory and execute programs or shells from the directory.

5. the difference between a soft link and a hard link?A symbolic (soft) linked file and the targeted file can be located on the same or different file system while for a hard link they must be located on the same file system.

6. Give the command to display space usage on the UNIX file system.df -lk

7. Explain iostat, vmstat and netstat.Iostat reports on terminal, disk and tape I/O activity.Vmstat reports on virtual memory statistics for processes, disk, tape and CPU activity.Netstat reports on the contents of network data structures.

8. How would you change all occurrences of a value using VI?Use :%s///g

9. Give two UNIX kernel parameters that effect an Oracle installSHMMAX & SHMMNI

10. Briefly, how do you install Oracle software on UNIX.Basically, set up disks, kernel parameters, and run orainst.

I hope that these interview questions were not too hard. Remember these are "core" DBA questions and not necessarily related to the Oracle options that you may encounter in some interviews. Take a close look at the requirements for any job and try to extract questions that interviewers may ask from manuals and real life experiences. For instance, if they are looking for a DBA to run their databases in RAC environments, you should try to determine what hardware and software they are using BEFORE you get to the interview. This would allow you to brush up on particular environments and not be caught off-guard. Good luck!

Way to go!!!

Monday, September 24, 2007

孔子说

子曰:吾,十有五,而志于学,三十而立,四十而不惑,五十而知天命,六十而耳顺,七十而从心所欲,不逾矩。