473,757 Members | 10,708 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to call an oracle function

how can i call an oracle function to get data without using a select
statement or stored procedures?

given a project_no, i need to call the function:
ops$sqltime.pa_ new_job_no_fn
which will return the next job_no

thanks in advance.
Nov 17 '05
12 9545
i made the following changes to varchar but still get the same exception.

oracle function (ops$sqltime.pa _new_job_no_fn) definition:
(p_project_no IN varchar2) return varchar2 is
-- *************** *************** *************** *************** ***************
-- DESCRIPTION: This procedure is called by the rollout process. Given a
project no,
-- it will determine a unique job_no for that project.

-- Version Date Who Description of Change
-- ------- -------- --- --------------------------------
-- 5.1.3 11/08/04 DL-JJT Changed f(x) to return '101' instead
-- of '1' if l_return is null
-- 51.1.02 08/24/98 GSB :6702: Check pa_job for duplicates
-- before returning the job_no.
-- 8.01.XX 07/10/98 GSB :3121: Initial Creation

l_count number;
l_last_job_no number := 0;
l_this_job_no number;
l_return pa_job.job_no%t ype;

cursor c1 is
select job_no
from pa_job
where project_no = p_project_no
order by job_no desc;

r1 c1%rowtype;

--Main
BEGIN
open c1;
loop
fetch c1 into r1;
exit when c1%notfound or l_return is not null;

--This will test if the job_no returned is numeric. If it isn't
--skip on to the next one.
begin
l_this_job_no := NULL;
l_this_job_no := TO_NUMBER(r1.jo b_no);
exception
when others then
null;
end;

if l_this_job_no is not null
and l_this_job_no != 9999 then
--We have a job that is entirely numeric. So let's add 1 to it, and
--test for the existence of the new job no. We do this by comparing
--to the last job_no we looked at. If it passes that
if l_this_job_no + 1 != l_last_job_no
and l_this_job_no != l_last_job_no
then
--Now check the database:
select count(*)
into l_count
from pa_job
where project_no = p_project_no
and job_no = to_char(l_this_ job_no + 1);
if l_count = 0
then
l_return := TO_CHAR(l_this_ job_no + 1);
else
l_last_job_no := l_this_job_no;
end if;
else
l_last_job_no := l_this_job_no;
end if;
end if;
end loop;

close c1;

--If l_return is null, we know this project has no numeric jobs, so we are
--safe returning a 1.
l_return := NVL(l_return,'1 01');
RETURN(l_return );
END
------------------------------------------------------------------------------------------
my code:

OracleCommand cmd = new OracleCommand() ;
cmd.Connection = oraConn;
cmd.CommandText = "ops$sqltime.pa _new_job_no_fn" ;
cmd.CommandType = CommandType.Sto redProcedure;

OracleParameter par1 = new OracleParameter ("RETURN_VALUE" ,
OracleType.VarC har);
par1.Direction = ParameterDirect ion.ReturnValue ;
par1.Size = 4000;
cmd.Parameters. Add(par1);
par1 = new OracleParameter ("PROJECT_NO ", OracleType.VarC har);
par1.Value = projectNo;
par1.Direction = ParameterDirect ion.Input;
par1.Size = 4000;
cmd.Parameters. Add(par1);
int affectedRows = (int) cmd.ExecuteScal ar();
ljn = (int) cmd.Parameters["RETURN_VAL UE"].Value;
"Bjorn Abelli" wrote:

"Newbie" wrote...
the real name of the input parameter is project_no which
is a string.


So why don't you name the parameter as such (though with capital letters)?

As you're sure it's a String, I suppose the variable "projectNo" in your
program is also a String.

That would mean that "PROJECT_NO " is a CHAR or VARCHAR2 field, most likely
with a specified length, but I doubt that it has a length of 4000...
the return value should be the job_no.


Of what type? If "PROJECT_NO " is a CHAR/VARCHAR2, my first guess would be
that the return type also is of type CHAR/VARCHAR, i.e. a String!
i believe there is only 1 input and 1 return parameter.

i made some changes and now i'm getting a different exception:

ORA-06550: line 1, column 14: PLS-00306: wrong number or
types of arguments in call to 'PA_NEW_JOB_NO_ FN' ORA-06550:
line 1, column 7: PL/SQL: Statement ignored


So the call went through, but the number or types of parameters are wrong.

Do you have a better description of the stored function with the number and
types of arguments and the type of the return value?
OracleCommand cmd = new OracleCommand() ;
cmd.Connection = oraConn;
cmd.CommandText = "ops$sqltime.pa _new_job_no_fn" ;
cmd.CommandType = CommandType.Sto redProcedure;

// I would still insist on using named parameters. Otherwise
// you'll probably not be able to fetch the return value...

// Though possibly with the type and size more accurate,
// so check with your DBA what the types really are...

OracleParameter par1 =
new OracleParameter ("RETURN_VALUE" , OracleType.Char , 20);
par1.Direction = ParameterDirect ion.ReturnValue ;
cmd.Parameters. Add(par1);

// ...both for the return value, as well as for the input
// argument...

par1 = new OracleParameter ("PROJECT_NO ", OracleType.Char , 20);
par1.Value = projectNo;
par1.Direction = ParameterDirect ion.Input;
cmd.Parameters. Add(par1);

int affectedRows = (int) cmd.ExecuteNonQ uery();

// Possibly this hence would be a String as well?

string ljn = cmd.Parameters["RETURN_VAL UE"].Value.ToString ();
// Bjorn A

Nov 17 '05 #11

"Newbie" wrote...
i made the following changes to varchar but still
get the same exception.
I noticed a small difference between what you have said, and the definition
of the function.
(p_project_no IN varchar2) return varchar2 is


....which in consequence should make the following change in your code for
the input parameter (Oracle can be picky about the parameter names...)

par1 = new OracleParameter ("P_PROJECT_NO" , OracleType.VarC har);

Hopefully your variable "projectNo" really is a string.

Note that the function also is defined to *return* a string, not a number,
so you should also make that change in your code:

string ljn = cmd.Parameters["RETURN_VAL UE"].Value.ToString ();

If it still doesn't work, I'd try the following.

- Reduce the parameters' sizes to something less
than 4000 (e.g. 200)

If it still won't work, I'd try Oracle's own Provider instead of
Microsoft's...

// Bjorn A
Nov 17 '05 #12
problem finally fixed. i changed
par1 = new OracleParameter ("PROJECT_NO ", OracleType.VarC har);
to
par1 = new OracleParameter ("P_PROJECT_NO" , OracleType.VarC har);
and now it's working. thanks a lot, Bjorn.
"Bjorn Abelli" wrote:

"Newbie" wrote...
i made the following changes to varchar but still
get the same exception.


I noticed a small difference between what you have said, and the definition
of the function.
(p_project_no IN varchar2) return varchar2 is


....which in consequence should make the following change in your code for
the input parameter (Oracle can be picky about the parameter names...)

par1 = new OracleParameter ("P_PROJECT_NO" , OracleType.VarC har);

Hopefully your variable "projectNo" really is a string.

Note that the function also is defined to *return* a string, not a number,
so you should also make that change in your code:

string ljn = cmd.Parameters["RETURN_VAL UE"].Value.ToString ();

If it still doesn't work, I'd try the following.

- Reduce the parameters' sizes to something less
than 4000 (e.g. 200)

If it still won't work, I'd try Oracle's own Provider instead of
Microsoft's...

// Bjorn A

Nov 17 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5228
by: Jan Bols | last post by:
I've been trying to install Oracle 8.1.7 on a fresh Mandrake 9.1 O.S for days, but I'm still not able to get it running. I've tried several install instructions that I found on the internet but no luck yet. Here is a short description of what I did so far: 1. I installed the jdk118_v3-glibc-2.1.3.tar in the /usr/local/ dir and made a symbolic link from /usr/local/java to this 2. I installed all the necessary groups and users (oracle,...
4
2031
by: Gnanaprakash Rathinam | last post by:
Hi Expert, Is there a way to obtain assembly name in an unmanaged call? During Interop call between managed to unmanaged, I would like to know in unmanaged code about the caller of assembly file name? Thanks, GP.
9
17031
by: mcbill20 | last post by:
Hello all. I just installed Oracle 10g developer tools on a machine running XP Pro and Office XP. Before this I had just the Oracle 9 client installed. I the previous configuration, I was able to access any of the Oracle tables on another machine but now I am having problems. Unfortunately, I don't remember the correct syntax for the ODBC connect string and I am hoping that is my whole problem. I am trying to connect to an Oracle 9...
2
1623
by: Newbie | last post by:
how can i call an oracle function? given a project_no, i need to call the function: ops$sqltime.pa_new_job_no_fn which will return the next job_no thanks in advance.
2
6677
by: Gary | last post by:
Hi Al I have the following parameters in an oracle function PACKAGE BODY ALLO A ------------------------------------------------------------------------------- FUNCTION ITEM (O_error_message OUT VARCHAR2 O_item IN OUT item.item%TYPE RETURN BOOLEAN IS......
4
29338
by: jens Jensen | last post by:
Hello, Assum i have an oracle function called ofunction. Can someone tell me how i can call this function assuming it take the parameter in_param of type clob. Any help will be highly appreciated C# .ADO.NET 2.0
2
14773
by: John | last post by:
My application needs to call Oracle function using oracle client 9.2. The oracle function returns boolean value from its returned parameter. The name space that I used is system.data.oracleclient. found out there is no boolean type in Oracle parameter in OracleType. How can I get the returned value from function call in my code? Thanks in advance
3
13857
by: Steve Kershaw | last post by:
I'm not even sure this can be done. I have a requirement to call an Oracle function (that returns a value) from C# code. The Oracle function is as follows: FUNCTION get_rec_final_qtr_count ( "P_YEAR" IN NUMBER, "P_QUARTER" IN NUMBER ) RETURN Int
0
3811
by: pbaillard | last post by:
Here a sample to call a stored procedure with an Oracle Database. odc.Connection = m_cDb ' use an open connection to your database odc.CommandType = CommandType.StoredProcedure odc.CommandText = "pkg_func.GetReqStatus" ' just set the name of the function, don't used syntax like {? = call pkg_func.GetReqStatus(?,?,?)} ' the return parameter odp = New OleDbParameter("result", OleDbType.VarChar)
0
9906
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...
0
9737
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
8737
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
7286
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
6562
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();...
0
5172
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3829
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
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.