Saturday, May 15, 2010

Errorlogging Clause in 10.1 and above



I was working on the Errorlogging clause in the Insert statement which can be used to capture errors that may occur while inserting, and I noticed that Errorlogging clause does not automatically create an error logging table, if it is not specified. I was trying this using SQLDeveloper, so was not sure whether it was a bug in the SD or not. To test it, I ran it using SQL*Plus.

Here is the Insert statement with Error logging clause

Log Errors Syntax (Screen -01)
Since it appeared that Error log table can be optional, I decided to omit and run the Insert statement. However, Oracle returned an Error (Screen -02)

Not mentioning table is Not an option (Screen -02)
So, decided to follow the textbook approach and created the errorlog table (Screen -03)

Created Error Log Table (Screen -03)

As you can see from the screen below, the procedure got executed successfully (Screen -04)

Procedure to generate Error (Screen -04)

The data got inserted into the Err$_Employees Table (Screen -05). So, I think I might have hit into a Bug, however, I am still researching about it.
Data Inserted Into Error Log Table (Screen -05)



References:  

Click here to view Insert Statement
Click here to view DBMS_ERRLOG Statement

Click here to view well written example @orafaq.com
Bug: Could not find any bug other that this old one in Metalink # Bug 5255455

Sunday, May 9, 2010

Date display in Oracle/SQLDeveloper



    A post in OTN forum (forum question was, How can I tell SQL Developer to always display datetime values in full?) asked how SQLDeveloper will display "Hours & seconds" in a "DATE" datatype, when the data entered is Date with no time component. Will it error out or will it display '00:00:00"? To this, I was certain, SQLDeveloper would gracefully display the timestamp at midnight. However, to prove it, I have to key-in data in date column and display them.
Before we get to that, let us first understand how Oracle stores DATE datatype.
Oracle stores date in 7 bytes (Ref: Oracle Advanced Application Developer's Guide. to access click here) Quote: Oracle Database stores dates in its own internal format. Date data is stored in fixed-length fields of seven bytes each, corresponding to century, year, month, day, hour, minute, and second. End Quote
So let us get back to SQLDeveloper and analyze how it displays date datatype
I would use the seeded table EMPLOYEES which has "hire_date" column defined as DATE datatype for demonstration purposes.
Emp table Columns and Datatypes (Screen -01)

Let us take an internal dump of the date and display the data (Screen -02)

Data Display (Screen -02)
As you can see in the above screen, SQLDeveloper displays all Hire_date column data with the time component. How does it do it, when the data keyed in does not contain time component? Well, if the data does not contain time details, then Oracle stores it as 12:00:00 AM.
A brief note on the Datadump column:-
Let us take line # 6 and analyze. 120 represents Century, 109 represents Year (both are displayed as 100+Century/100+Year), then comes the month, and date. Next you would see 1,1,1 which represents the time portion (or in other words the time here is 12:00:00 AM). Time is stored as (HH+1),(MI+1),(SS+1) and displayed as 12+(HH-1) and so on. For example Line # 3 diplays 23-FEB-2010 06:34:12 AM and is stored as CC=(100+20), YY=(100+10), MM=2, DD=23, Hours=7 (6+1), Minutes=35(34+1), Seconds=13(12+1).


Why Century and Year are stored in excess 100 notation? so that we can represent BC numbers. If you look at Line # 4, you would notice that for Century and Year column the value is less that 100. That is because, the data represents BC.90-100=-10, the century inserted and the negative value will tell Oracle that it is a BC and not AD.Another point is that, we know that BC 1010 is greater than BC 1011 (line # 5). So it works  perfectly well in binary sorting too.

So, to conclude, there is absolutely no issues in displaying date by SQLDeveloper

Saturday, May 8, 2010

TNS-12541: TNS:no listener



The command lsnrctl start ORCLPLSQL resulted in "TNS-12541:TNS:no listener " error yesterday; I was puzzled (See below).

(Screen -01)



Oracle was working perfectly fine till then; moreover, I had not installed any new s/w at all.What could then be the issue?
A search on Google brought up this page: ORA-12514: TNS:listener does not currently know of service requested in connect descriptor

As listed in that web page, I tried the first one.
The Command, show parameter local listener displayed that tns port has not changed, listener.ora is pointing to the correct port.
Next, I tried tnsping avs.ramanujam.com, which resulted in the same error message.


(Screen -02)

Another thing I noticed was, both starting up the listener and tnsping was taking more time than usual. Next I ran the ifconfig command, I noticed that the ipaddress had changed. (I have to make a confession here. Even though the best practices and the recommendation is that "servers" should have static ipaddress, I had not made it static.) Bang- sound of myself hitting my head  -changed the ipaddress in the /etc/hosts and I was back into business in no matter of time.
Final screen is after successful connection is shown below

(Screen -03)

Wednesday, May 5, 2010

(Not a ) Bug in Debug Procedures in SQLDev

Today an OP in SQLDeveloper forum at OTN had complained about "disappearing" Green icon on Procedures (To read the post click here Note: Sue has pointed out that it is not a bug.I have posted an update below on how to use compiler with debug option. So if you just want to know how to turn on or off the compiler with debug option, just scroll down. If you have time to kill  :-), go ahead and read the entire post. ) . So, back to my original post.... 
I just happen to have Windows version SQLDeveloper (Build Version 2.1.1.63) and Linux Version (Build Version 2.1.1.64) installed. Just a heads up for those who are wondering about the "green" icons, when you compile a procedure, in SQLDeveloper, if the procedure compiles successfully, then it will display a Green icon on the left of the procedure name. If the procedure fails to compile a "red" stop icon is displayed - pretty cute isn't it? Only that it does not seem be consistent across versions (or is it across OS versions, I wonder)?
Since I usually used Linux, I was not sure what the OP was talking about. I created a few test procedures in 63 (windows version) first (Screen -01).
Windows Build version 63. Notice missing Proc toolbar (Screen -01)

Everything went off without any hitch, although it did not display the Procedure Complier bar, it was not a show stopper. I could compile repeatedly the procedure without any issue, and update the parameter for this procedure (Screen -02).
Modify the parameter (Screen -02)


Next, I started my linux version and recreated the same procedure. Bingo! The first time procedure got compiled and the green icon was displayed. I could see the Procedure 'Compilation' Toolbar. However, when I compiled again, (Screen -03)

Linux Build 64 (notice the Procedure Tool bar (Screen 03)

When I complied "with Debug option", I could see the green icon now (Screen -04)

Go for Green (Compiled with Debug) (Screen -04)

But, I cannot modify the parameter window (Screen -05). I hope SQLDeveloper team will take note of this and correct the bug.

Cann't change the parameter (Screen -05)

Update:
As Sue Harper had pointed out, it was a case of how I compiled. Default Compilation option for SQLDeveloper is to "Compile with Debug"
If you want to reset the default preferences to "compile and no Debug" go to Tools-->Database-->PLSQL Compiler and click on the optimization level and set it to 2. Note: This setting "tells" compiler to optimize the PLSQL Library units. (Screen -06)


After setting the preferences to zero, I reran the procedure and was able to change the input parameter ( See below) .



The log ouput window is shown below. Thanks Sue.


You might also want to read this post ( If using windows:-

How to get SQLDeveloper working on Windows 7

If you are using *nix then

How to make SQLDeveloper work on Linux

)