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... -
-
SQL> select * from bios_lookup;
-
-
BIOS_ID BIOS
-
---------- ----------------------------------------------------------------
-
1 Phoenix - AwardBIOS v6.00PG
-
2 Phoenix ROM BIOS PLUS Version 1.10 A14
-
3 Phoenix ROM BIOS PLUS Version 1.10 A20
-
4 Phoenix ROM BIOS PLUS Version 1.10 A19
-
5 Phoenix ROM BIOS PLUS Version 1.10 A08
-
6 Phoenix ROM BIOS PLUS Version 1.10 A11
-
7 Phoenix ROM BIOS PLUS Version 1.10 A17
-
8 Phoenix NoteBIOS 4.0 Release 6.0
-
9 Default System BIOS
-
10 786B2 v1.11
-
11 Phoenix ROM BIOS PLUS Version 1.10 A02
-
12 Phoenix ROM BIOS PLUS Version 1.10 A05
-
13 SE7520JR23 Production BIOS Version 07.20, Build 0074
-
14 Phoenix ROM BIOS PLUS Version 1.10 A09
-
15 Phoenix ROM BIOS PLUS Version 1.10 A06
-
16 Phoenix ROM BIOS PLUS Version 1.10 A04
-
17 &Phoenix NoteBIOS 4.0 Release 6.0
-
18 PhoenixBIOS 4.0 Release 6.0
-
19 )Phoenix - Award WorkstationBIOS v6.00PG
-
20 Phoenix ROM BIOS PLUS Version 1.10 A03
-
21 Phoenix FirstBIOS(tm) Notebook Pro Version 2.0 for IBM ThinkPad
-
22 Phoenix ROM BIOS PLUS Version 1.10 A18
-
23 OCPRF100- PhoenixBIOS 4.0 Release 6.0
-
-
23 rows selected.
-
-
--And here's my function...
-
SQL> create or replace function bios_no(bios_in in varchar2) return number is
-
2 pragma autonomous_transaction;
-
3 bnum number;
-
4 begin
-
5 select bios_id into bnum from bios_lookup where bios_in = bios;
-
6 EXCEPTION
-
7 WHEN OTHERS 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 return bnum;
-
14 end;
-
15 /
-
-
Function created.
-
-
SQL> select bios_no('test') from dual;
-
-
BIOS_NO('TEST')
-
---------------
-
43
-
-
--looks good.....
-
SQL> select * from bios_lookup;
-
-
BIOS_ID BIOS
-
---------- ----------------------------------------------------------------
-
1 Phoenix - AwardBIOS v6.00PG
-
2 Phoenix ROM BIOS PLUS Version 1.10 A14
-
3 Phoenix ROM BIOS PLUS Version 1.10 A20
-
4 Phoenix ROM BIOS PLUS Version 1.10 A19
-
5 Phoenix ROM BIOS PLUS Version 1.10 A08
-
6 Phoenix ROM BIOS PLUS Version 1.10 A11
-
7 Phoenix ROM BIOS PLUS Version 1.10 A17
-
8 Phoenix NoteBIOS 4.0 Release 6.0
-
9 Default System BIOS
-
10 786B2 v1.11
-
11 Phoenix ROM BIOS PLUS Version 1.10 A02
-
12 Phoenix ROM BIOS PLUS Version 1.10 A05
-
13 SE7520JR23 Production BIOS Version 07.20, Build 0074
-
14 Phoenix ROM BIOS PLUS Version 1.10 A09
-
15 Phoenix ROM BIOS PLUS Version 1.10 A06
-
16 Phoenix ROM BIOS PLUS Version 1.10 A04
-
17 &Phoenix NoteBIOS 4.0 Release 6.0
-
18 PhoenixBIOS 4.0 Release 6.0
-
19 )Phoenix - Award WorkstationBIOS v6.00PG
-
20 Phoenix ROM BIOS PLUS Version 1.10 A03
-
21 Phoenix FirstBIOS(tm) Notebook Pro Version 2.0 for IBM ThinkPad
-
22 Phoenix ROM BIOS PLUS Version 1.10 A18
-
23 OCPRF100- PhoenixBIOS 4.0 Release 6.0
-
43 test
-
-
24 rows selected.
-
-
--YES - it works, now create a view with the function embedded...
-
-
create or replace view sms_host as
-
SELECT csd."MachineID", csd."Name0", csd."Model0", csd."Domain0",
-
osd."Caption0",osd."Version0",
-
bios_no(pbd."SoftwareElementID00") as bios,
-
sia."IP_Addresses0",
-
sd."SystemRole0",
-
sdi."User_Name0"
-
FROM TEMP_CSD csd, TEMP_OSD osd, TEMP_PBD pbd, TEMP_SIA sia, TEMP_SD sd, TEMP_SDI sdi
-
WHERE csd."MachineID" = osd."MachineID"
-
AND osd."MachineID" = pbd."MachineID"
-
AND pbd."MachineID" = sia."ItemKey"
-
AND sia."ItemKey" = sd."MachineID"
-
AND sd."MachineID" = sdi."ItemKey";
-
-
SQL> select * from sms_host where rownum < 2;
-
select * from sms_host where rownum < 2
-
*
-
ERROR at line 1:
-
ORA-06503: PL/SQL: Function returned without value
-
ORA-06512: at "NETTEST.BIOS_NO", line 14
-
Why doesn't this work?????
(I resolved the issue below, but still am curious why the original failed) -
-
create or replace function bios_no(bios_in in varchar2) return number is
-
pragma autonomous_transaction;
-
bnum number;
-
begin
-
select nvl(bios_id,0) into bnum from bios_lookup where bios_in = bios;
-
if bnum = 0 then
-
begin
-
select bios_seq.nextval into bnum from dual;
-
insert into bios_lookup (bios_id,bios) values (bnum,bios_in);
-
commit;
-
end;
-
end if;
-
return bnum;
-
end;
-
/
-
3 4570
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.
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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).
|
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...
|
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;
|
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...
|
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
| |
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
|
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
|
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
| |
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...
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
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();...
|
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
| |
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...
| |