My Work
Tuesday, March 3, 2009
IN versus EXIST
EXISTS is more faster than IN because EXISTS returns a Boolean value whereas IN returns a value.
Monday, March 2, 2009
DIfference between varchar and nvarchar in Oracle
varchar2(20 char) means you can store 20 characters -- whereas varchar2(20) means you can store 20 bytes. the varchar2(20 char) might take 20, 40, 60, 80 or more bytes to hold a string. The maximum length of a varchar2 is still 4000 bytes so varchar2(4000 char) is "misleading" in that the field will max out at 4000 bytes -- not 4000 characters.
Saturday, February 28, 2009
Generalizing Cursors with Parameters
I really don't want to write a separate cursor for each different category −− that is definitely not a data−driven approach to programming. Instead, I would much rather be able to change the joke cursor so that it can accept different categories and return the appropriate rows. The best (though not the only) way to do this is with a cursor parameter:
DECLARE
/*
|| Cursor with parameter list consisting of a single
|| string parameter.
*/
CURSOR joke_cur (category_in VARCHAR2)
IS
SELECT name, category, last_used_date
FROM joke
WHERE category = UPPER (category_in);
joke_rec joke_cur%ROWTYPE;
BEGIN
/* Now when I open the cursor, I also pass the argument */
OPEN joke_cur (:joke.category);
FETCH joke_cur INTO joke_rec;
DECLARE
/*
|| Cursor with parameter list consisting of a single
|| string parameter.
*/
CURSOR joke_cur (category_in VARCHAR2)
IS
SELECT name, category, last_used_date
FROM joke
WHERE category = UPPER (category_in);
joke_rec joke_cur%ROWTYPE;
BEGIN
/* Now when I open the cursor, I also pass the argument */
OPEN joke_cur (:joke.category);
FETCH joke_cur INTO joke_rec;
Column Aliases in Cursors
The SELECT statement of the cursor includes the list of columns that are returned by that cursor. Just as with any SELECT statement, this column list may contain either actual column names or column expressions, which are also referred to as calculated or virtual columns.
A column alias is an alternative name you provide to a column or column expression in a query. You may have used column aliases in SQL*Plus in order to improve the readability of ad hoc report output. In that situation, such aliases are completely optional. In an explicit cursor, on the other hand, column aliases are required for calculated columns when:
· You FETCH into a record declared with a %ROWTYPE declaration against that cursor.
· You want to reference the calculated column in your program.
DECLARE
CURSOR comp_cur IS
SELECT company_name, SUM (inv_amt) total_sales
FROM company C, invoice I
WHERE C.company_id = I.company_id
AND I.invoice_date BETWEEN '01−JAN−1994' AND '31−DEC−1994';
comp_rec comp_cur%ROWTYPE;
BEGIN
OPEN comp_cur;
FETCH comp_cur INTO comp_rec;
...
END;
A column alias is an alternative name you provide to a column or column expression in a query. You may have used column aliases in SQL*Plus in order to improve the readability of ad hoc report output. In that situation, such aliases are completely optional. In an explicit cursor, on the other hand, column aliases are required for calculated columns when:
· You FETCH into a record declared with a %ROWTYPE declaration against that cursor.
· You want to reference the calculated column in your program.
DECLARE
CURSOR comp_cur IS
SELECT company_name, SUM (inv_amt) total_sales
FROM company C, invoice I
WHERE C.company_id = I.company_id
AND I.invoice_date BETWEEN '01−JAN−1994' AND '31−DEC−1994';
comp_rec comp_cur%ROWTYPE;
BEGIN
OPEN comp_cur;
FETCH comp_cur INTO comp_rec;
...
END;
Monday, February 23, 2009
Query to Find Unindexed Foreign Key Constraints
Now that we know unindexed foreign key constraints can cause severe problems, here is a script that I use to find them for a specific user (this can easily be tailored to search all schemas):
SELECT * FROM (
SELECT c.table_name, cc.column_name, cc.position column_position
FROM user_constraints c, user_cons_columns cc
WHERE c.constraint_name = cc.constraint_name
AND c.constraint_type = 'R'
MINUS
SELECT i.table_name, ic.column_name, ic.column_position
FROM user_indexes i, user_ind_columns ic
WHERE i.index_name = ic.index_name
)
ORDER BY table_name, column_position;
SELECT * FROM (
SELECT c.table_name, cc.column_name, cc.position column_position
FROM user_constraints c, user_cons_columns cc
WHERE c.constraint_name = cc.constraint_name
AND c.constraint_type = 'R'
MINUS
SELECT i.table_name, ic.column_name, ic.column_position
FROM user_indexes i, user_ind_columns ic
WHERE i.index_name = ic.index_name
)
ORDER BY table_name, column_position;
Where to go in Kuakata
Kuakata is known as Sagar Konna in Bangladesh and the most beautiful thing is that you can see the sunset and sunrise from the same beach. Some great attractions are,
1) Beach :
Most of the hotels are just beside the beach. But you can see only sunset from this beach. Motocycle are abvaialable to hire to go any place in kuakata. they made a contract like a package tour...sami temple, gongamotir chor(from where you can see the sunrise).It will cost 200 taka.
2) GongaMotir Chor and Jhauban
3) Temple:
one of two temples is just beside the beach. Its just a walking distance. Another one is sami temple or misri para temple.
4) Fatrar ban:
Its part of sundarban. A tour agency is there to bring you in fatrarban. You can collect the tickets from the beach with 100 taka.
1) Beach :
Most of the hotels are just beside the beach. But you can see only sunset from this beach. Motocycle are abvaialable to hire to go any place in kuakata. they made a contract like a package tour...sami temple, gongamotir chor(from where you can see the sunrise).It will cost 200 taka.
2) GongaMotir Chor and Jhauban
3) Temple:
one of two temples is just beside the beach. Its just a walking distance. Another one is sami temple or misri para temple.
4) Fatrar ban:
Its part of sundarban. A tour agency is there to bring you in fatrarban. You can collect the tickets from the beach with 100 taka.
How to go Kuakata
You can go by Bus or Launch.
Bus:
Direct bus route from Dhaka to Kuakata. “Sakura” costs around 450 Taka (US $8.00). There are some other buses like Druti, Soudia etc. But You have to know the last destination clearly. Because some of the buses goes to khepupara and then you have to buy another ticket towards kollapara(kuakata) worth 30 taka per person.
Launch:
Dhaka to Barisal by large river boat locally known as “Launch”. They leave from Dhaka Sadarghat launch terminal between 6 to 9 PM. This comfortable overnight journey to Barisal will cost around 500 to 700 per person in a comfortable cabin (double is around 900 to 1400 taka).
You can also take a direct river boat from Dhaka sadarghat terminal to Patuakhali. This journey will cost you about the same as Barisal and these boats leaves little early around 4 to 7 PM. River boats are much nicer in Barisal route.
Bus:
Direct bus route from Dhaka to Kuakata. “Sakura” costs around 450 Taka (US $8.00). There are some other buses like Druti, Soudia etc. But You have to know the last destination clearly. Because some of the buses goes to khepupara and then you have to buy another ticket towards kollapara(kuakata) worth 30 taka per person.
Launch:
Dhaka to Barisal by large river boat locally known as “Launch”. They leave from Dhaka Sadarghat launch terminal between 6 to 9 PM. This comfortable overnight journey to Barisal will cost around 500 to 700 per person in a comfortable cabin (double is around 900 to 1400 taka).
You can also take a direct river boat from Dhaka sadarghat terminal to Patuakhali. This journey will cost you about the same as Barisal and these boats leaves little early around 4 to 7 PM. River boats are much nicer in Barisal route.
Subscribe to:
Posts (Atom)
search engine
Custom Search