473,805 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

autonomous trans with EXCEPTION fails - why?

1 New Member
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 4570
Dave44
153 New Member
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 Recognized Expert Top Contributor
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 Recognized Expert New Member
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
7892
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 have a stored procedure sp_log_action with a PRAGMA AUTONOMOUS TRANSACTION defined which is called after each statement in the main stored procedure(this writes the event to a table).
1
4490
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 least it's a documented bug that I can simply reference and move on. The following code and session output (I think) documents a condition where a procedure marked for an automomous commit is commiting an INSERT over a database link that is outside...
2
1311
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, but I am worried developers will forget to commit and/or close the connection. If I could auto wrap around it somehow..? public void SomeUpdate() { OracleConnection connection = null; OracleTransaction trans = null;
10
2059
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 these ideas are finally beginning to sink in. I believe I looked at the same article a while back and decided I wasn't quite ready for it. If I understood things correctly, there seems to be a slight problem with the design of his exception safe...
44
4235
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 user tasks should always be included in a try/catch block that actually handles any exceptions that occur (log the exception, display a message box, etc.). 2. Low-level operations that are used to carry out the high level tasks
13
2323
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 Application.Run(new Form1()); i have setup a global keyboard hook
4
3684
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 and then log them inside database tables. What about: 1) using memory structures to hold the info, then commit to the database just before exit (after the
5
14114
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
1685
AdusumalliGopikumar
by: AdusumalliGopikumar | last post by:
Where we can't use Autonomous transaction?
0
9718
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10363
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10368
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10107
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.