473,394 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

autonomous trans with EXCEPTION fails - why?

1
My quest is to create a function that returns a string value from a lookup table given the ID.
If no match occurs, then I want to load that value into the lookup table.
So here's my lookup table...
Expand|Select|Wrap|Line Numbers
  1.  
  2. SQL> select * from bios_lookup;
  3.  
  4.    BIOS_ID BIOS
  5. ---------- ----------------------------------------------------------------
  6.          1 Phoenix - AwardBIOS v6.00PG
  7.          2 Phoenix ROM BIOS PLUS Version 1.10 A14
  8.          3 Phoenix ROM BIOS PLUS Version 1.10 A20
  9.          4 Phoenix ROM BIOS PLUS Version 1.10 A19
  10.          5 Phoenix ROM BIOS PLUS Version 1.10 A08
  11.          6 Phoenix ROM BIOS PLUS Version 1.10 A11
  12.          7 Phoenix ROM BIOS PLUS Version 1.10 A17
  13.          8 Phoenix NoteBIOS 4.0 Release 6.0
  14.          9 Default System BIOS
  15.         10 786B2 v1.11
  16.         11 Phoenix ROM BIOS PLUS Version 1.10 A02
  17.         12 Phoenix ROM BIOS PLUS Version 1.10 A05
  18.         13 SE7520JR23 Production BIOS Version 07.20, Build 0074
  19.         14 Phoenix ROM BIOS PLUS Version 1.10 A09
  20.         15 Phoenix ROM BIOS PLUS Version 1.10 A06
  21.         16 Phoenix ROM BIOS PLUS Version 1.10 A04
  22.         17 &Phoenix NoteBIOS 4.0 Release 6.0
  23.         18 PhoenixBIOS 4.0 Release 6.0
  24.         19 )Phoenix - Award WorkstationBIOS v6.00PG
  25.         20 Phoenix ROM BIOS PLUS Version 1.10 A03
  26.         21 Phoenix FirstBIOS(tm) Notebook Pro Version 2.0 for IBM ThinkPad
  27.         22 Phoenix ROM BIOS PLUS Version 1.10 A18
  28.         23 OCPRF100- PhoenixBIOS 4.0 Release 6.0
  29.  
  30. 23 rows selected.
  31.  
  32. --And here's my function...
  33. SQL> create or replace function bios_no(bios_in in varchar2) return number is
  34.   2  pragma autonomous_transaction;
  35.   3  bnum number;
  36.   4  begin
  37.   5  select bios_id into bnum from bios_lookup where bios_in = bios;
  38.   6   EXCEPTION
  39.   7       WHEN OTHERS THEN
  40.   8       begin
  41.   9          select bios_seq.nextval into bnum from dual;
  42.  10          insert into bios_lookup (bios_id,bios) values (bnum,bios_in);
  43.  11          commit;
  44.  12       end;
  45.  13  return bnum;
  46.  14  end;
  47.  15  /
  48.  
  49. Function created.
  50.  
  51. SQL> select bios_no('test') from dual;
  52.  
  53. BIOS_NO('TEST')
  54. ---------------
  55.              43
  56.  
  57. --looks good.....             
  58. SQL> select * from bios_lookup;
  59.  
  60.    BIOS_ID BIOS
  61. ---------- ----------------------------------------------------------------
  62.          1 Phoenix - AwardBIOS v6.00PG
  63.          2 Phoenix ROM BIOS PLUS Version 1.10 A14
  64.          3 Phoenix ROM BIOS PLUS Version 1.10 A20
  65.          4 Phoenix ROM BIOS PLUS Version 1.10 A19
  66.          5 Phoenix ROM BIOS PLUS Version 1.10 A08
  67.          6 Phoenix ROM BIOS PLUS Version 1.10 A11
  68.          7 Phoenix ROM BIOS PLUS Version 1.10 A17
  69.          8 Phoenix NoteBIOS 4.0 Release 6.0
  70.          9 Default System BIOS
  71.         10 786B2 v1.11
  72.         11 Phoenix ROM BIOS PLUS Version 1.10 A02
  73.         12 Phoenix ROM BIOS PLUS Version 1.10 A05
  74.         13 SE7520JR23 Production BIOS Version 07.20, Build 0074
  75.         14 Phoenix ROM BIOS PLUS Version 1.10 A09
  76.         15 Phoenix ROM BIOS PLUS Version 1.10 A06
  77.         16 Phoenix ROM BIOS PLUS Version 1.10 A04
  78.         17 &Phoenix NoteBIOS 4.0 Release 6.0
  79.         18 PhoenixBIOS 4.0 Release 6.0
  80.         19 )Phoenix - Award WorkstationBIOS v6.00PG
  81.         20 Phoenix ROM BIOS PLUS Version 1.10 A03
  82.         21 Phoenix FirstBIOS(tm) Notebook Pro Version 2.0 for IBM ThinkPad
  83.         22 Phoenix ROM BIOS PLUS Version 1.10 A18
  84.         23 OCPRF100- PhoenixBIOS 4.0 Release 6.0
  85.         43 test
  86.  
  87. 24 rows selected.
  88.  
  89. --YES - it works, now create a view with the function embedded...
  90.  
  91. create or replace view sms_host as
  92.   SELECT csd."MachineID", csd."Name0", csd."Model0", csd."Domain0",
  93.          osd."Caption0",osd."Version0",
  94.    bios_no(pbd."SoftwareElementID00") as bios,
  95.          sia."IP_Addresses0",
  96.          sd."SystemRole0",
  97.          sdi."User_Name0"
  98.   FROM  TEMP_CSD csd, TEMP_OSD osd, TEMP_PBD pbd, TEMP_SIA sia, TEMP_SD sd, TEMP_SDI sdi   
  99.   WHERE csd."MachineID" = osd."MachineID"
  100.     AND osd."MachineID" = pbd."MachineID"  
  101.     AND pbd."MachineID" = sia."ItemKey" 
  102.     AND sia."ItemKey" = sd."MachineID"
  103.     AND sd."MachineID" = sdi."ItemKey";
  104.  
  105. SQL> select * from sms_host where rownum < 2;
  106. select * from sms_host where rownum < 2
  107.                                       *
  108. ERROR at line 1:
  109. ORA-06503: PL/SQL: Function returned without value
  110. ORA-06512: at "NETTEST.BIOS_NO", line 14
  111.  

Why doesn't this work?????

(I resolved the issue below, but still am curious why the original failed)
Expand|Select|Wrap|Line Numbers
  1.  
  2.  create or replace function bios_no(bios_in in varchar2) return number is
  3.     pragma autonomous_transaction;
  4.     bnum number;
  5.     begin
  6.     select nvl(bios_id,0) into bnum from bios_lookup where bios_in = bios;
  7.     if bnum = 0 then
  8.          begin
  9.             select bios_seq.nextval into bnum from dual;
  10.             insert into bios_lookup (bios_id,bios) values (bnum,bios_in);
  11.            commit;
  12.         end;
  13.    end if;
  14.    return bnum;
  15.    end;
  16.    /
  17.  
Mar 28 '08 #1
3 4550
Dave44
153 100+
Your function only returns a value if it gets into the exception block. when it finds the passed in value in the lookup table nothing is returned, thats why your getting the no value returned error i believe.
try testing the function with a value that exists and see what happens.
Mar 31 '08 #2
amitpatel66
2,367 Expert 2GB
Yes Dave is right. You have used RETURN statement in the EXCEPTION block. You need to use the return statement before your exception block,ie in the main begin block itself.
Mar 31 '08 #3
Saii
145 Expert 100+
In addition to above solution, I just want to point out that try using no_data_found exception instead of generic when others exception to populate a new value, unless you want to populate new row on every exception thrown by the code.
Mar 31 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Sam | last post by:
Guys, I have a question regarding oracle. I have a stored procedure executing a number of statements including delete , select and lots of inserts in one big procedure and main transaction I...
1
by: Dan Loomis | last post by:
Hi guys - I have a weird condition here I'm trying to get resolution on, and unfortunately I'm not getting anywhere with my friends at Oracle. I'm hoping it's something simple, or at the very...
2
by: Tim Smith | last post by:
I have a lot of code which follows the general pattern below. Is there an easy (or hard) way of avoiding repeating the same code over and over. I do need to manage the connection at this level,...
10
by: Steven T. Hatton | last post by:
I read Stroustrup's article of the day: http://www.research.att.com/~bs/C++.html Programming with Exceptions. InformIt.com. April 2001. http://www.research.att.com/~bs/eh_brief.pdf Some of...
44
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level...
13
by: tolisss | last post by:
Hi i have setup a global exception handler b4 Application.Run like Application.ThreadException += new ThreadExceptionEventHandler(GlobalExceptionProcessing.AppThreadException ); then after...
4
by: Daniel Daoust | last post by:
Hi, knowing that "autonomous transaction" (Oracle concept of) are not yet implemented in PostgreSQL, has anyone found a work-around. I need to preserve database states from a potential rollback...
5
by: dilippanda | last post by:
Hi Experts, I want to know what is the use of pragma autonomous transaction in PL/SQL. In which condition should we use this? Please guide me with an example. Thanks, Dilip
1
AdusumalliGopikumar
by: AdusumalliGopikumar | last post by:
Where we can't use Autonomous transaction?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.