Desi bhai (BanglaDESI Brother). I looked back over my shoulders hearing that in bengali. It was a bangla speaking, mid 40 guy with a shabby looks.
I was in Changi Airport to receive my lecturer.
"Do you have some loose coins, I need to call my agent here"
I did not have loose coins, so I let him use my cell. He took out some half torned paper where he has the number and started calling. I went a bit further to allow privacy.
"Ki boltase bujhtasi na. Apni dahen akbar(Dont know what is he saying.You please try once)" - he said with desparation.Somebody rightly said that in anger, love or emotion people starts talking their own language or in proper tone. I could clearly felt that this guy is from Shillete of Bangladesh (A state of Bangladesh)
I tried to call the number and heard that somebody is talking in chineese on other side.Clearly some wrong number.
-"You might have noted some wrong number".I told the guy.
-"Aita kothai hobe, ektu bolte paren ( Can you tell, where will be the place)"?. He again took out some oily paper with an address nearby to Kranji. Might be some dormitory.
I felt annoyed.What a pain? Anybody can recognise me as a Bengali from my looks..!! I cursed my looks.
I can see that my lecturer is also coming. I directed him towards the taxi que and asked him to show the paper to the driver.
Me and my lecturer was about board the cab.Suddenly the fellow come from backside."Brother, you gave me your cell to use".He is holding a 10 SGD note in his hand.
-"No, no its okay. And after all the calls do not cost 10 $ at all.Keep it"
Now my lecturer suddenly became enthuastic hearing somebody from his place and talking in his mother-tounge....!! I hold my head. I know when two first comers meet in a foreign place what happens.
Well,their long discussions ended after a gracious lunch offered my lecturer. I knew that the bengali guy has got a lucrative offer to work as a plumber with basic salary as 700 SGD with extra overtime...!! He is very excited that he can do so much overtime and send quite a lot of money back to his home where he left his wife and two kids.
I almost forgot that incident until I felt the need to adjust the height of my ceiling fan. I called the electrician.I became amazed seeing my friend once again.
-"Bhaijan chinte paren? Kemon asen?( Brother, can you remember me? How are you?"
-"yes, of course. What a surprise!! You as a electrician!! As I remember you came as a plumber,right?"
-"Yes, nowdays not so much work of plumber.I saved some money and that finished in that bad time. And I changed agent once again and this time made my job as a electrician. In this atleast I will have some work from time to time."
"Why dont you go back?" - I asked when I knew that whenever he changes a agent he need to pay around 2000 $. "After all in this way you can not save money. And Singapore job market is not good. And dont mind, dont you think that you can not earn 700 $ in your country?"
Many foreign workers come here with the dream that they can earn a lot. And for that they sell their lands, mortgage their house to collect money for the agent. And they understand the reality just after reaching here. They wish so much to go back but they can not accept the fact that they will go back with empty hand whereas they have their house morgaged, their land also gone.They continue more time in dormitory which is over-packed by some more dreamers.They got work sometime and sometime just do any odd works like packing-unpacking goods in supermarket. People hate them, nobody wants to sit beside them in MRT or buses. Ladies avoid them as they used to glare them.
The other weekend I was helping my Malay friend to shift his house and oh my....The same bengali guy is here with a gang. He saw me and friends.
-"Apanar malay dost o ase naki?(you have malay friends too?)"- He asked jokingly while moving the refrigerator inside the kitchen.I knew from him that now he is doing this 'movers-job' as a part-time hiring the truck from his boss.
-"Do you have driving licence to drive?"- I asked.
-" Apni ki bhaben je apnar sudhu malay dost ase?( Don you think you only have malay friends"). He replied with loud bang on his chinese friend back - "Lim is our driver". Poor Lim did not understand why he got such a bang. BUt I understood that my friend is quite popular among his friends.
He will never take the mover's charge when he knew that the guy is my friend. "You gave me a lot of extra when I went to repair your ceiling fan. And yours friend is my friend too"- He insistingly said. I signalled my friend that no benifit of forcing to give them money. So we offered then a good dinner donwstairs.
It is really strange that a person can laugh so heartily without any tension when he is earning from hand-to-mouth. It is stranger to show such a gratefulness to some stranger who is incidentally his friend's friend. And who is his friend?- Who helped him by lettling him call two time to some local number!!
I did not see that guy after that.
Neither I saw him in the crouds in front of Mustafa(24 hours popular store in Singapore) who are buying some mobile burgain and getting one free goodie bag nor in the small mini-vans carrying the exacly same tired looking workers who are dozzing in slumber to their dormitory.
Nowdays if I saw that some "Desi Bhai" sitting alone in a jampacked bus,I accompany him. After all I can not change my looks and in emotion I also speak up in bengali. Let others think whatever they want.
HASIM`S_ABODE
How I learned things...How I made chaos..How I became e-motional..How they did that...? The blocked frames are in my blog.Its my net abode...HASIM`S ABODE
Wednesday, October 27, 2010
Monday, October 25, 2010
Another recession.....!!!
Nowadays there is a hue and cry on recession.
In my dictionary it is a new word. I never heard about it couple of months before. And then suddenly I became so aware about it and its scary wrinkled face. Now I think I can claim expertise on this as I know why US goes into recession, why there is only 5% property booked in Burj-Al-Khalifa, why Germans are shouting when their government bails out the sinking Greece,why the European banks are kneeling,will it be Icelands turn now etc etc. I can also put worthy comment on property Bubble burst and believe me its scary; not at all like childhood colorful soap bubble burst. I know that we can pump water into a tub I never heard that money can also be pumped into economy and that also pump,pump and pump to a leaky bucket. Cool new learning for me indeed.
I silently praise the warriors who pacifies me saying "Dont worry...Things will be okay...I have seen how many IT guys loose jobs on DOT.COM burst". Man, seems this burst is more scarier than the tyre bursts in US Highway 50 or the hill-way towards Ladakh with no spare tyre..!! I like those warriors face expression when they take so pleasure to relate various stories related to the DOT.COM burst time. Sometimes I think IT guys love to get worried and tensed. But thinking and real life scenario might be different, so I follow the experts advice - "Sit tight wherever you are...keep ticking 12 hours without and chaos in office and if needed buy some Fevicol to apply on your office chair". As I told, I admire my warriors and thus I follow their golden suggestions. After all I am new in recession.
But I think, some other form of recessions starts longgg....long before the 'US/Dubai property market' or 'European banks' or 'Greece economy' fails.That is recession in humanity.
In public transport while getting in we elbow some spectacled aged guy to grab a seat meant for elders or more needy person and pretend to sleep. We rush while driving cutting in and out of lane. That's different matter that whom I overtook sometimes stops next to my lane at a RED light. We shamelessly show some other persons work as mine in office to please my blind boss and take a nap after lunch when working-from-home keeping the messenger status as 'VERY BUSY'. We don't care the stupid pedestrians at ZEBRA crossing and why should we when we are riding in BMW and he is crossing the road with a shabby bag full of vegetables. We don't bother if you catch us kissing at the back alley and why should we when you might also did the same when you were young. We are quick to press the lift button if we see others are coming, after all it is kinda subtle pride we feel that we will reach my floor faster than you. We don't care any more to know why my next-door neighbours son crying or why the ambulance came late night to our small society. In fact there if no point of knowing when we barely know any of my neighbours. What we know nowadays is only the "I and we" and yes of course the "You" provided that "You" is either my girlfriend or my BOSS.
Clearly the other form of recession started long before but till now I didn't find any warriors whom I can praise or any government who can pump,pump and pump humanity.
I am still searching and I doubt I will find ever as I know the numbers of the warriors are very less and the hole in the leaky bucket is pretty big.
In my dictionary it is a new word. I never heard about it couple of months before. And then suddenly I became so aware about it and its scary wrinkled face. Now I think I can claim expertise on this as I know why US goes into recession, why there is only 5% property booked in Burj-Al-Khalifa, why Germans are shouting when their government bails out the sinking Greece,why the European banks are kneeling,will it be Icelands turn now etc etc. I can also put worthy comment on property Bubble burst and believe me its scary; not at all like childhood colorful soap bubble burst. I know that we can pump water into a tub I never heard that money can also be pumped into economy and that also pump,pump and pump to a leaky bucket. Cool new learning for me indeed.
I silently praise the warriors who pacifies me saying "Dont worry...Things will be okay...I have seen how many IT guys loose jobs on DOT.COM burst". Man, seems this burst is more scarier than the tyre bursts in US Highway 50 or the hill-way towards Ladakh with no spare tyre..!! I like those warriors face expression when they take so pleasure to relate various stories related to the DOT.COM burst time. Sometimes I think IT guys love to get worried and tensed. But thinking and real life scenario might be different, so I follow the experts advice - "Sit tight wherever you are...keep ticking 12 hours without and chaos in office and if needed buy some Fevicol to apply on your office chair". As I told, I admire my warriors and thus I follow their golden suggestions. After all I am new in recession.
But I think, some other form of recessions starts longgg....long before the 'US/Dubai property market' or 'European banks' or 'Greece economy' fails.That is recession in humanity.
In public transport while getting in we elbow some spectacled aged guy to grab a seat meant for elders or more needy person and pretend to sleep. We rush while driving cutting in and out of lane. That's different matter that whom I overtook sometimes stops next to my lane at a RED light. We shamelessly show some other persons work as mine in office to please my blind boss and take a nap after lunch when working-from-home keeping the messenger status as 'VERY BUSY'. We don't care the stupid pedestrians at ZEBRA crossing and why should we when we are riding in BMW and he is crossing the road with a shabby bag full of vegetables. We don't bother if you catch us kissing at the back alley and why should we when you might also did the same when you were young. We are quick to press the lift button if we see others are coming, after all it is kinda subtle pride we feel that we will reach my floor faster than you. We don't care any more to know why my next-door neighbours son crying or why the ambulance came late night to our small society. In fact there if no point of knowing when we barely know any of my neighbours. What we know nowadays is only the "I and we" and yes of course the "You" provided that "You" is either my girlfriend or my BOSS.
Clearly the other form of recession started long before but till now I didn't find any warriors whom I can praise or any government who can pump,pump and pump humanity.
I am still searching and I doubt I will find ever as I know the numbers of the warriors are very less and the hole in the leaky bucket is pretty big.
Sunday, October 24, 2010
Notes on Uniqueness....!!
Whether it is a people or a race or a country, we should never forget our uniqueness, cultures and roots.
You may feel that she looks stunning in the high colar black jacket but you never realized that others like your simplicity; your's simple looks.You starts mimicking the american tone while speaking and while humming a Lady Gaga song you pick wrong notes but you never realized when you chants the ghazal, you mesmerise the passers-by. You thought to get success in business by copying some well known and popular product to realize later that your business is far behind to the business you copied.And the reason is that he has started long before you started and he knew that someday somebody wil copy him and then how can he come out with better product. Everybody in this world is unique. You better goom and nurture those unique qualities for a better acceptance
In South east asia and middle east there is a surge of Bollywood movies. The same bollywood movies which used to be called as dumb dancing-around-the-tree movies by the west. There is an increase influx of western actors in bollywood movies too.The reason is bollywood has a huge market outside India. It is good to see that Bollywood retains its flavor blodly stating that "love it or hate it, this is it"; and yes its presence is increasing in multifold than earlier. In many countries you can easily hear a popular bollywood song and in big cities you can find a "Bollywood Dance" class.Earlier time kathakali is coined as a ghost-dance for its unique appearance of the dancers and rapid eye movement and now it is a world known dance.Similarly when somebody talks about Bihu you propmtly asks him back -are you from Assam? With nominal dance steps and stereotype tune bhangra is another name for Punjab.Abroad while in Chinese new year, the cebration is incomplete without dragon dance; Deepavali is incomplete without lamps and colurs;halloween is incomplete without weird,fearful attrires.I believe there is not a single big city in this world where you will not be able to find an Indian Restaurant. And they are successfull too just by showcasing their countries delicacies.At the same time I wonder how many Indians became successfull opening up an western food giant!! It is all about the roots or the cultures of the country or states when it it comes about identity. You forget it, others forget you.
I am not so blunt to say that mimicing is wrong. Following others might be good sometimes but never always. If you can adopt good things from others keeping your own stucture intact, it is good. Any revolutionary product, the nobel prize always followed by a great idea or unique idea which is original.
After all - “Today you are You, that is truer than true. There is no one alive who is Youer than You.”
You may feel that she looks stunning in the high colar black jacket but you never realized that others like your simplicity; your's simple looks.You starts mimicking the american tone while speaking and while humming a Lady Gaga song you pick wrong notes but you never realized when you chants the ghazal, you mesmerise the passers-by. You thought to get success in business by copying some well known and popular product to realize later that your business is far behind to the business you copied.And the reason is that he has started long before you started and he knew that someday somebody wil copy him and then how can he come out with better product. Everybody in this world is unique. You better goom and nurture those unique qualities for a better acceptance
In South east asia and middle east there is a surge of Bollywood movies. The same bollywood movies which used to be called as dumb dancing-around-the-tree movies by the west. There is an increase influx of western actors in bollywood movies too.The reason is bollywood has a huge market outside India. It is good to see that Bollywood retains its flavor blodly stating that "love it or hate it, this is it"; and yes its presence is increasing in multifold than earlier. In many countries you can easily hear a popular bollywood song and in big cities you can find a "Bollywood Dance" class.Earlier time kathakali is coined as a ghost-dance for its unique appearance of the dancers and rapid eye movement and now it is a world known dance.Similarly when somebody talks about Bihu you propmtly asks him back -are you from Assam? With nominal dance steps and stereotype tune bhangra is another name for Punjab.Abroad while in Chinese new year, the cebration is incomplete without dragon dance; Deepavali is incomplete without lamps and colurs;halloween is incomplete without weird,fearful attrires.I believe there is not a single big city in this world where you will not be able to find an Indian Restaurant. And they are successfull too just by showcasing their countries delicacies.At the same time I wonder how many Indians became successfull opening up an western food giant!! It is all about the roots or the cultures of the country or states when it it comes about identity. You forget it, others forget you.
I am not so blunt to say that mimicing is wrong. Following others might be good sometimes but never always. If you can adopt good things from others keeping your own stucture intact, it is good. Any revolutionary product, the nobel prize always followed by a great idea or unique idea which is original.
After all - “Today you are You, that is truer than true. There is no one alive who is Youer than You.”
Thursday, August 19, 2010
HowToOracle:- Everything about exceptions
Every thing about Oracle Exception Handling
================================================
Facts:-
1. There are 2 kinds of exceptions:-
System defined / pre-defined exceptions
Programmer-Defined Exceptions
2. System defined exceptions are exceptions that have been given names by PL/SQL. They are named in the STANDARD package in PL/SQL and do not need to be defined by the programmer.
Oracle has a standard set of exceptions already named as follows:
Oracle Exception Name
Oracle Error
Explanation
DUP_VAL_ON_INDEX
ORA-00001
You tried to execute an INSERT or UPDATE statement that has created a duplicate value in a field restricted by a unique index.
TIMEOUT_ON_RESOURCE
ORA-00051
You were waiting for a resource and you timed out.
TRANSACTION_BACKED_OUT
ORA-00061
The remote portion of a transaction has rolled back.
INVALID_CURSOR
ORA-01001
You tried to reference a cursor that does not yet exist. This may have happened because you've executed a FETCH cursor or CLOSE cursor before OPENing the cursor.
NOT_LOGGED_ON
ORA-01012
You tried to execute a call to Oracle before logging in.
LOGIN_DENIED
ORA-01017
You tried to log into Oracle with an invalid username/password combination.
NO_DATA_FOUND
ORA-01403
You tried one of the following:
You executed a SELECT INTO statement and no rows were returned.
You referenced an uninitialized row in a table.
You read past the end of file with the UTL_FILE package.
TOO_MANY_ROWS
ORA-01422
You tried to execute a SELECT INTO statement and more than one row was returned.
ZERO_DIVIDE
ORA-01476
You tried to divide a number by zero.
INVALID_NUMBER
ORA-01722
You tried to execute an SQL statement that tried to convert a string to a number, but it was unsuccessful.
STORAGE_ERROR
ORA-06500
You ran out of memory or memory was corrupted.
PROGRAM_ERROR
ORA-06501
This is a generic "Contact Oracle support" message because an internal problem was encountered.
VALUE_ERROR
ORA-06502
You tried to perform an operation and there was a error on a conversion, truncation, or invalid constraining of numeric or character data.
CURSOR_ALREADY_OPEN
ORA-06511
You tried to open a cursor that is already open.
Sample Procedure describing handling NO_DATA_FOUND error:-
---------------------------------------------------------------
CREATE OR REPLACE PROCEDURE proc_named_exception
AS
v_ename emp.ename%TYPE;
BEGIN
SELECT ename INTO v_ename FROM emp WHERE ename = 'SMITH';
Dbms_Output.put_line('Employe name is = '||v_ename); -- Valid record willbe shown in output
/* the following will throw NO_DATA_FOUND exception */
SELECT ename INTO v_ename FROM emp WHERE ename = 'TITIKAKA';
Dbms_Output.put_line('Employe name is = '||v_ename); -- NO_DATA_FOUND, so control will go to exception block
-- Nothing will be shown in output
SELECT ename INTO v_ename FROM emp WHERE ename = 'KING';
Dbms_Output.put_line('Employe name is = '||v_ename);
EXCEPTION
WHEN No_Data_Found THEN
Dbms_Output.put_line('no data found');
END;
Facts 3:- By default, you put an exception handler at the end of a subprogram to handle exceptions that are raised anywhere inside the subprogram. To continue executing from the spot where an exception happens, enclose the code that might raise an exception inside another BEGIN-END block with its own exception handler. For example, you might put separate BEGIN-END blocks around groups of SQL statements that might raise NO_DATA_FOUND, or around arithmetic operations that might raise DIVIDE_BY_ZERO. By putting a BEGIN-END block with an exception handler inside a loop, you can continue executing the loop even if
some loop iterations raise exceptions.See sample 2 below.
Sample 2 Procedure describing handling NO_DATA_FOUND and DUP_VAL_ON_INDEX error:-
-------------------------------------------------------------------------------
CREATE OR REPLACE PROCEDURE proc_named_exception1
AS
v_ename emp.ename%TYPE;
BEGIN
BEGIN -- This block is to handle NDF
SELECT ename INTO v_ename FROM emp WHERE ename = 'SMITH';
Dbms_Output.put_line('Employe name is = '||v_ename); -- Valid record willbe shown in output
/* the following will throw NO_DATA_FOUND exception */
SELECT ename INTO v_ename FROM emp WHERE ename = 'TITIKAKA';
Dbms_Output.put_line('Employe name is = '||v_ename); -- NO_DATA_FOUND, so control will go to exception block
-- Nothing will be shown in output
SELECT ename INTO v_ename FROM emp WHERE ename = 'KING';
Dbms_Output.put_line('Employe name is = '||v_ename);
EXCEPTION
WHEN No_Data_Found THEN
Dbms_Output.put_line('NO_DATA_FOUND');
END;
BEGIN -- This block is to handle DVOI
INSERT INTO emp VALUES(7369,'Hasim','Admin',9898,SYSDATE,7000,NULL,10);
COMMIT;
EXCEPTION
WHEN DUP_VAL_ON_INDEX THEN
Dbms_Output.put_line('DUP_VAL_ON_INDEX');
END;
END;
Fact 4:- You can handle more than one exception in a single handler as follows:-
EXCEPTION
When NO_DATA_FOUND or TOO_MANY_ROWS then
Statements;
END;
Fact 5:- A User-defined exception has to be defined by the programmer. User-defined exceptions are declared in the declaration section with their type as
exception.They must be raised explicitly using RAISE statement, unlike pre-defined exceptions that are raised implicitly. RAISE statement can also be used to
raise internal exceptions.
Declaring Exception:
--------------------
DECLARE
myexception EXCEPTION;
BEGIN
Raising Exception:
------------------
BEGIN
RAISE myexception;
Handling Exception:
----------------------
BEGIN
EXCEPTION
WHEN myexception THEN
Statements;
END;
Sample 3 Procedure addemp in the package is having an user defined exception
-------------------------------------------------------------------------------
PROMPT CREATE OR REPLACE PACKAGE hasim_pack2
CREATE OR REPLACE PACKAGE hasim_pack2 AS
PROCEDURE addemp;
PROCEDURE delemp;
END hasim_pack2;
/
PROMPT CREATE OR REPLACE PACKAGE BODY hasim_pack2
CREATE OR REPLACE PACKAGE BODY hasim_pack2 AS
PROCEDURE addemp IS
is_exists EXCEPTION;
cnt NUMBER :=0;
BEGIN
SELECT Count(1) INTO cnt FROM emp WHERE empno IN (9898,9897);
IF cnt > 0 THEN
RAISE is_exists;
else
INSERT ALL
INTO emp VALUES(9898,'Timothy','CEO',7839,SYSDATE,7000,NULL,10)
INTO emp VALUES(9897,'Hasim','Admin',9898,SYSDATE,7000,NULL,10)
SELECT * FROM dual;
COMMIT;
END IF;
EXCEPTION
WHEN is_exists THEN
Raise_Application_Error(-20001,'You must delete Timothy/hasim first');
WHEN OTHERS then
Raise_Application_Error(-20002,'Some error happened while inserting records');
END addemp;
PROCEDURE delemp IS
begin
DELETE FROM emp WHERE empno IN (9898,9897);
COMMIT;
END delemp;
END hasim_pack2;
/
Fact 6:-
An Exception cannot be declared twice in the same block.
Exceptions declared in a block are considered as local to that block and global to its sub-blocks.An enclosing block cannot access Exceptions declared in its sub-block. Where as it possible for a sub-block to refer its enclosing Exceptions.
Sample 4 Exceptions raised in sub-block is handled by main block
-----------------------------------------------------------------
CREATE OR REPLACE PROCEDURE proc_named_exception3
AS
v_ename emp.ename%TYPE;
res NUMBER;
BEGIN
BEGIN -- This block is to handle TMR
SELECT ename INTO v_ename FROM emp WHERE job = 'PRESIDENT';
Dbms_Output.put_line('President Employe name is = '||v_ename); -- Valid record willbe shown in output
SELECT (10/2) INTO res FROM dual;
Dbms_Output.put_line('10/2 = '||res); -- Valid record willbe shown in output
SELECT (10/0) INTO res FROM dual;
Dbms_Output.put_line('10/0 = '||res); -- Zero_Divide,no record willbe shown in output,exception catcher is in main block
EXCEPTION
WHEN TOO_MANY_ROWS THEN
Dbms_Output.put_line('TOO_MANY_ROWS');
END;
BEGIN -- This block is to handle DVOI
INSERT INTO emp VALUES(7369,'Hasim','Admin',9898,SYSDATE,7000,NULL,10);
COMMIT;
EXCEPTION
WHEN DUP_VAL_ON_INDEX THEN
Dbms_Output.put_line('DUP_VAL_ON_INDEX');
END;
EXCEPTION
WHEN Zero_Divide THEN
Dbms_Output.put_line('Zero_Divide');
END;
Fact 7:- RAISE_APPLICATION_ERROR
To display your own error messages one can use the built-in RAISE_APPLICATION_ERROR. They display the error message in the same way as Oracle errors. You should use a negative number between –20000 to –20999 for the error_number and the error message should not exceed 512 characters. Check sample 3.
Fact 8:- The WHEN OTHERS clause is used to trap all remaining exceptions that have not been handled by the System defined Exceptions and Programmer-Defined Exceptions.
Sample 5 Usage of when others in the previous addemp procedure
----------------------------------------------------------------
create or replace PROCEDURE addemp1 IS
is_exists EXCEPTION;
cnt NUMBER :=0;
BEGIN
SELECT Count(1) INTO cnt FROM emp WHERE empno IN (9898,9897);
IF cnt > 0 THEN
RAISE is_exists;
else
INSERT ALL
INTO emp VALUES(9898,'Timothy','CEO',7839,SYSDATE,7000,NULL,10)
INTO emp VALUES(9897,'Hasim','Admin',9898,SYSDATE,7000,NULL,10)
SELECT * FROM dual;
COMMIT;
END IF;
SELECT (10/0) INTO cnt FROM dual;
EXCEPTION
WHEN is_exists THEN
Raise_Application_Error(-20001,'You must delete Timothy/hasim first');
WHEN OTHERS then
Raise_Application_Error(-20002,'Some error happened while inserting records');
END addemp1;
SQL> exec addemp1;
BEGIN addemp1; END;
*
ERROR at line 1:
ORA-20001: You must delete Timothy/hasim first
ORA-06512: at "SCOTT.ADDEMP1", line 17
ORA-06512: at line 1
SQL> exec hasim_pack2.delemp;
PL/SQL procedure successfully completed.
SQL> exec addemp1;
BEGIN addemp1; END;
*
ERROR at line 1:
ORA-20002: Some error happened while inserting records
ORA-06512: at "SCOTT.ADDEMP1", line 20
ORA-06512: at line 1
SQL>
Fact 9:- The SQLCODE function returns the error number associated with the most recently raised error exception. This function should only be used within the Exception Handling section of your code.
Sample 5 Usage of when others in the previous addemp procedure
----------------------------------------------------------------
create or replace PROCEDURE addemp2 IS
is_exists EXCEPTION;
cnt NUMBER :=0;
BEGIN
SELECT Count(1) INTO cnt FROM emp WHERE empno IN (9898,9897);
IF cnt > 0 THEN
RAISE is_exists;
else
INSERT ALL
INTO emp VALUES(9898,'Timothy','CEO',7839,SYSDATE,7000,NULL,10)
INTO emp VALUES(9897,'Hasim','Admin',9898,SYSDATE,7000,NULL,10)
SELECT * FROM dual;
COMMIT;
END IF;
SELECT (10/0) INTO cnt FROM dual;
EXCEPTION
WHEN is_exists THEN
Raise_Application_Error(-20001,'You must delete Timothy/hasim first');
WHEN OTHERS then
Raise_Application_Error(-20002,'Some error happened while inserting records'||SQLCODE||' -ERROR- '||SQLERRM);
END addemp2;
Samplerun:-
SQL> exec hasim_pack2.delemp;
PL/SQL procedure successfully completed.
SQL> exec addemp2;
BEGIN addemp2; END;
*
ERROR at line 1:
ORA-20002: Some error happened while inserting records-1476 -ERROR- ORA-01476:
divisor is equal to zero
ORA-06512: at "SCOTT.ADDEMP2", line 20
ORA-06512: at line 1
================================================
Facts:-
1. There are 2 kinds of exceptions:-
System defined / pre-defined exceptions
Programmer-Defined Exceptions
2. System defined exceptions are exceptions that have been given names by PL/SQL. They are named in the STANDARD package in PL/SQL and do not need to be defined by the programmer.
Oracle has a standard set of exceptions already named as follows:
Oracle Exception Name
Oracle Error
Explanation
DUP_VAL_ON_INDEX
ORA-00001
You tried to execute an INSERT or UPDATE statement that has created a duplicate value in a field restricted by a unique index.
TIMEOUT_ON_RESOURCE
ORA-00051
You were waiting for a resource and you timed out.
TRANSACTION_BACKED_OUT
ORA-00061
The remote portion of a transaction has rolled back.
INVALID_CURSOR
ORA-01001
You tried to reference a cursor that does not yet exist. This may have happened because you've executed a FETCH cursor or CLOSE cursor before OPENing the cursor.
NOT_LOGGED_ON
ORA-01012
You tried to execute a call to Oracle before logging in.
LOGIN_DENIED
ORA-01017
You tried to log into Oracle with an invalid username/password combination.
NO_DATA_FOUND
ORA-01403
You tried one of the following:
You executed a SELECT INTO statement and no rows were returned.
You referenced an uninitialized row in a table.
You read past the end of file with the UTL_FILE package.
TOO_MANY_ROWS
ORA-01422
You tried to execute a SELECT INTO statement and more than one row was returned.
ZERO_DIVIDE
ORA-01476
You tried to divide a number by zero.
INVALID_NUMBER
ORA-01722
You tried to execute an SQL statement that tried to convert a string to a number, but it was unsuccessful.
STORAGE_ERROR
ORA-06500
You ran out of memory or memory was corrupted.
PROGRAM_ERROR
ORA-06501
This is a generic "Contact Oracle support" message because an internal problem was encountered.
VALUE_ERROR
ORA-06502
You tried to perform an operation and there was a error on a conversion, truncation, or invalid constraining of numeric or character data.
CURSOR_ALREADY_OPEN
ORA-06511
You tried to open a cursor that is already open.
Sample Procedure describing handling NO_DATA_FOUND error:-
---------------------------------------------------------------
CREATE OR REPLACE PROCEDURE proc_named_exception
AS
v_ename emp.ename%TYPE;
BEGIN
SELECT ename INTO v_ename FROM emp WHERE ename = 'SMITH';
Dbms_Output.put_line('Employe name is = '||v_ename); -- Valid record willbe shown in output
/* the following will throw NO_DATA_FOUND exception */
SELECT ename INTO v_ename FROM emp WHERE ename = 'TITIKAKA';
Dbms_Output.put_line('Employe name is = '||v_ename); -- NO_DATA_FOUND, so control will go to exception block
-- Nothing will be shown in output
SELECT ename INTO v_ename FROM emp WHERE ename = 'KING';
Dbms_Output.put_line('Employe name is = '||v_ename);
EXCEPTION
WHEN No_Data_Found THEN
Dbms_Output.put_line('no data found');
END;
Facts 3:- By default, you put an exception handler at the end of a subprogram to handle exceptions that are raised anywhere inside the subprogram. To continue executing from the spot where an exception happens, enclose the code that might raise an exception inside another BEGIN-END block with its own exception handler. For example, you might put separate BEGIN-END blocks around groups of SQL statements that might raise NO_DATA_FOUND, or around arithmetic operations that might raise DIVIDE_BY_ZERO. By putting a BEGIN-END block with an exception handler inside a loop, you can continue executing the loop even if
some loop iterations raise exceptions.See sample 2 below.
Sample 2 Procedure describing handling NO_DATA_FOUND and DUP_VAL_ON_INDEX error:-
-------------------------------------------------------------------------------
CREATE OR REPLACE PROCEDURE proc_named_exception1
AS
v_ename emp.ename%TYPE;
BEGIN
BEGIN -- This block is to handle NDF
SELECT ename INTO v_ename FROM emp WHERE ename = 'SMITH';
Dbms_Output.put_line('Employe name is = '||v_ename); -- Valid record willbe shown in output
/* the following will throw NO_DATA_FOUND exception */
SELECT ename INTO v_ename FROM emp WHERE ename = 'TITIKAKA';
Dbms_Output.put_line('Employe name is = '||v_ename); -- NO_DATA_FOUND, so control will go to exception block
-- Nothing will be shown in output
SELECT ename INTO v_ename FROM emp WHERE ename = 'KING';
Dbms_Output.put_line('Employe name is = '||v_ename);
EXCEPTION
WHEN No_Data_Found THEN
Dbms_Output.put_line('NO_DATA_FOUND');
END;
BEGIN -- This block is to handle DVOI
INSERT INTO emp VALUES(7369,'Hasim','Admin',9898,SYSDATE,7000,NULL,10);
COMMIT;
EXCEPTION
WHEN DUP_VAL_ON_INDEX THEN
Dbms_Output.put_line('DUP_VAL_ON_INDEX');
END;
END;
Fact 4:- You can handle more than one exception in a single handler as follows:-
EXCEPTION
When NO_DATA_FOUND or TOO_MANY_ROWS then
Statements;
END;
Fact 5:- A User-defined exception has to be defined by the programmer. User-defined exceptions are declared in the declaration section with their type as
exception.They must be raised explicitly using RAISE statement, unlike pre-defined exceptions that are raised implicitly. RAISE statement can also be used to
raise internal exceptions.
Declaring Exception:
--------------------
DECLARE
myexception EXCEPTION;
BEGIN
Raising Exception:
------------------
BEGIN
RAISE myexception;
Handling Exception:
----------------------
BEGIN
EXCEPTION
WHEN myexception THEN
Statements;
END;
Sample 3 Procedure addemp in the package is having an user defined exception
-------------------------------------------------------------------------------
PROMPT CREATE OR REPLACE PACKAGE hasim_pack2
CREATE OR REPLACE PACKAGE hasim_pack2 AS
PROCEDURE addemp;
PROCEDURE delemp;
END hasim_pack2;
/
PROMPT CREATE OR REPLACE PACKAGE BODY hasim_pack2
CREATE OR REPLACE PACKAGE BODY hasim_pack2 AS
PROCEDURE addemp IS
is_exists EXCEPTION;
cnt NUMBER :=0;
BEGIN
SELECT Count(1) INTO cnt FROM emp WHERE empno IN (9898,9897);
IF cnt > 0 THEN
RAISE is_exists;
else
INSERT ALL
INTO emp VALUES(9898,'Timothy','CEO',7839,SYSDATE,7000,NULL,10)
INTO emp VALUES(9897,'Hasim','Admin',9898,SYSDATE,7000,NULL,10)
SELECT * FROM dual;
COMMIT;
END IF;
EXCEPTION
WHEN is_exists THEN
Raise_Application_Error(-20001,'You must delete Timothy/hasim first');
WHEN OTHERS then
Raise_Application_Error(-20002,'Some error happened while inserting records');
END addemp;
PROCEDURE delemp IS
begin
DELETE FROM emp WHERE empno IN (9898,9897);
COMMIT;
END delemp;
END hasim_pack2;
/
Fact 6:-
An Exception cannot be declared twice in the same block.
Exceptions declared in a block are considered as local to that block and global to its sub-blocks.An enclosing block cannot access Exceptions declared in its sub-block. Where as it possible for a sub-block to refer its enclosing Exceptions.
Sample 4 Exceptions raised in sub-block is handled by main block
-----------------------------------------------------------------
CREATE OR REPLACE PROCEDURE proc_named_exception3
AS
v_ename emp.ename%TYPE;
res NUMBER;
BEGIN
BEGIN -- This block is to handle TMR
SELECT ename INTO v_ename FROM emp WHERE job = 'PRESIDENT';
Dbms_Output.put_line('President Employe name is = '||v_ename); -- Valid record willbe shown in output
SELECT (10/2) INTO res FROM dual;
Dbms_Output.put_line('10/2 = '||res); -- Valid record willbe shown in output
SELECT (10/0) INTO res FROM dual;
Dbms_Output.put_line('10/0 = '||res); -- Zero_Divide,no record willbe shown in output,exception catcher is in main block
EXCEPTION
WHEN TOO_MANY_ROWS THEN
Dbms_Output.put_line('TOO_MANY_ROWS');
END;
BEGIN -- This block is to handle DVOI
INSERT INTO emp VALUES(7369,'Hasim','Admin',9898,SYSDATE,7000,NULL,10);
COMMIT;
EXCEPTION
WHEN DUP_VAL_ON_INDEX THEN
Dbms_Output.put_line('DUP_VAL_ON_INDEX');
END;
EXCEPTION
WHEN Zero_Divide THEN
Dbms_Output.put_line('Zero_Divide');
END;
Fact 7:- RAISE_APPLICATION_ERROR
To display your own error messages one can use the built-in RAISE_APPLICATION_ERROR. They display the error message in the same way as Oracle errors. You should use a negative number between –20000 to –20999 for the error_number and the error message should not exceed 512 characters. Check sample 3.
Fact 8:- The WHEN OTHERS clause is used to trap all remaining exceptions that have not been handled by the System defined Exceptions and Programmer-Defined Exceptions.
Sample 5 Usage of when others in the previous addemp procedure
----------------------------------------------------------------
create or replace PROCEDURE addemp1 IS
is_exists EXCEPTION;
cnt NUMBER :=0;
BEGIN
SELECT Count(1) INTO cnt FROM emp WHERE empno IN (9898,9897);
IF cnt > 0 THEN
RAISE is_exists;
else
INSERT ALL
INTO emp VALUES(9898,'Timothy','CEO',7839,SYSDATE,7000,NULL,10)
INTO emp VALUES(9897,'Hasim','Admin',9898,SYSDATE,7000,NULL,10)
SELECT * FROM dual;
COMMIT;
END IF;
SELECT (10/0) INTO cnt FROM dual;
EXCEPTION
WHEN is_exists THEN
Raise_Application_Error(-20001,'You must delete Timothy/hasim first');
WHEN OTHERS then
Raise_Application_Error(-20002,'Some error happened while inserting records');
END addemp1;
SQL> exec addemp1;
BEGIN addemp1; END;
*
ERROR at line 1:
ORA-20001: You must delete Timothy/hasim first
ORA-06512: at "SCOTT.ADDEMP1", line 17
ORA-06512: at line 1
SQL> exec hasim_pack2.delemp;
PL/SQL procedure successfully completed.
SQL> exec addemp1;
BEGIN addemp1; END;
*
ERROR at line 1:
ORA-20002: Some error happened while inserting records
ORA-06512: at "SCOTT.ADDEMP1", line 20
ORA-06512: at line 1
SQL>
Fact 9:- The SQLCODE function returns the error number associated with the most recently raised error exception. This function should only be used within the Exception Handling section of your code.
Sample 5 Usage of when others in the previous addemp procedure
----------------------------------------------------------------
create or replace PROCEDURE addemp2 IS
is_exists EXCEPTION;
cnt NUMBER :=0;
BEGIN
SELECT Count(1) INTO cnt FROM emp WHERE empno IN (9898,9897);
IF cnt > 0 THEN
RAISE is_exists;
else
INSERT ALL
INTO emp VALUES(9898,'Timothy','CEO',7839,SYSDATE,7000,NULL,10)
INTO emp VALUES(9897,'Hasim','Admin',9898,SYSDATE,7000,NULL,10)
SELECT * FROM dual;
COMMIT;
END IF;
SELECT (10/0) INTO cnt FROM dual;
EXCEPTION
WHEN is_exists THEN
Raise_Application_Error(-20001,'You must delete Timothy/hasim first');
WHEN OTHERS then
Raise_Application_Error(-20002,'Some error happened while inserting records'||SQLCODE||' -ERROR- '||SQLERRM);
END addemp2;
Samplerun:-
SQL> exec hasim_pack2.delemp;
PL/SQL procedure successfully completed.
SQL> exec addemp2;
BEGIN addemp2; END;
*
ERROR at line 1:
ORA-20002: Some error happened while inserting records-1476 -ERROR- ORA-01476:
divisor is equal to zero
ORA-06512: at "SCOTT.ADDEMP2", line 20
ORA-06512: at line 1
Wednesday, August 18, 2010
HowToTeraData: Beginners guide to teradata.
1. Getting the software and installing it:-
Get the demo version from http://www.teradata.com/dwdemo
2. Logon using BTEQ
From command mode run bteq or bteqwin( for windows version).
default userid is/dbc
default password is dbc
C:\Documents and Settings\Hasim>bteq
Teradata BTEQ 13.00.00.03 for WIN32.
Copyright 1984-2009, Teradata Corporation. ALL RIGHTS RESERVED.
Enter your logon or BTEQ command:
.logon
.logon
UserId: dbc
Password:
*** Logon successfully completed.
*** Teradata Database Release is 13.00.00.12
*** Teradata Database Version is 13.00.00.12
*** Transaction Semantics are BTET.
*** Character Set Name is 'ASCII'.
*** Total elapsed time was 2 seconds.
BTEQ -- Enter your DBC/SQL request or BTEQ command:
If facing the following error then Check HowToTeraData: CLI error: MTDP: EM_NOHOST(224): name not in HOSTS file or names database
3. Create user/database
---- Need to see -----
create user hasim_tdt from dbc as
permanent = 1000000
,password = hasim_tdt
,spool = 2000000
,fallback protection
,dual after journal
,default journal table = hasim_tdt.journals
,account = '$dbc';
4. what are the tables in DBC?
--- NTS ----
5. How to interrupt execution in bteqwin/bteq if something wrong happens?
--- NTS ---
Get the demo version from http://www.teradata.com/dwdemo
2. Logon using BTEQ
From command mode run bteq or bteqwin( for windows version).
default userid is
default password is dbc
C:\Documents and Settings\Hasim>bteq
Teradata BTEQ 13.00.00.03 for WIN32.
Copyright 1984-2009, Teradata Corporation. ALL RIGHTS RESERVED.
Enter your logon or BTEQ command:
.logon
.logon
UserId: dbc
Password:
*** Logon successfully completed.
*** Teradata Database Release is 13.00.00.12
*** Teradata Database Version is 13.00.00.12
*** Transaction Semantics are BTET.
*** Character Set Name is 'ASCII'.
*** Total elapsed time was 2 seconds.
BTEQ -- Enter your DBC/SQL request or BTEQ command:
If facing the following error then Check HowToTeraData: CLI error: MTDP: EM_NOHOST(224): name not in HOSTS file or names database
3. Create user/database
---- Need to see -----
create user hasim_tdt from dbc as
permanent = 1000000
,password = hasim_tdt
,spool = 2000000
,fallback protection
,dual after journal
,default journal table = hasim_tdt.journals
,account = '$dbc';
4. what are the tables in DBC?
--- NTS ----
5. How to interrupt execution in bteqwin/bteq if something wrong happens?
--- NTS ---
HowToTeraData: CLI error: MTDP: EM_NOHOST(224): name not in HOSTS file or names database.
CLI error: MTDP: EM_NOHOST(224): name not in HOSTS file or names database.
Solution:-
Edit the file C:/WINDOWS/SYSTEM32/DRIVERS/ETC/HOSTS
Edit the following line as:-
127.0.0.1 localhost dbccop1
Close Bteq/Bteqwin and retry.
** How will you know it should be dbccop1 ?
In the tdpid,after cop it should be 1 as you are using on a local machine and there is only one RDBMS and before cop it should be dbc as you can verify your i_dbcpath variable value from C:\Program Files\Teradata\Client\13.0\CLIv2\clispb.dat.
Solution:-
Edit the file C:/WINDOWS/SYSTEM32/DRIVERS/ETC/HOSTS
Edit the following line as:-
127.0.0.1 localhost dbccop1
Close Bteq/Bteqwin and retry.
** How will you know it should be dbccop1 ?
In the tdpid,after cop it should be 1 as you are using on a local machine and there is only one RDBMS and before cop it should be dbc as you can verify your i_dbcpath variable value from C:\Program Files\Teradata\Client\13.0\CLIv2\clispb.dat.
Subscribe to:
Posts (Atom)