473,729 Members | 2,331 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 #1
12 9539
is it a proc or a function?
The Oracle proc should call the function.

I'm not sure if you can call an actual function straight from code without
calling it from a proc (stored procedure) and then exposing it that way to
out side code.

"Newbie" <Ne****@discuss ions.microsoft. com> wrote in message
news:7C******** *************** ***********@mic rosoft.com...
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 #2

"Newbie" wrote...
how can i call an oracle function to get data without using a select
statement or stored procedures?
That statement was confusing, as a stored function as "a kind of" stored
procedure, from ADO.NET's point of view...
given a project_no, i need to call the function:
ops$sqltime.pa_ new_job_no_fn
which will return the next job_no

In short, I'd guess something like this should work...

private int NextJobNo(int project_no)
{
OracleCommand cmd = new OracleCommand() ;
cmd.Connection = cn; // You have the connection somewhere, don't
you..."
cmd.CommandText = "ops$sqltime.pa _new_job_no_fn" ;
cmd.CommandType = CommandType.Sto redProcedure;

OracleParameter par1 =
new OracleParameter ("RETURN_VALUE" , OracleDbType.In t32);
par1.Direction = ParameterDirect ion.ReturnValue ;
cmd.Parameters. Add(par1);

par1 = new OracleParameter ("PROJECT_NO ", OracleDbType.In t32);
par1.Value = project_no;
par1.Direction = ParameterDirect ion.Input;
cmd.Parameters. Add(par1);

int affectedRows = (int) cmd.ExecuteNonQ uery();
int job_no = (int) cmd.Parameters["RETURN_VAL UE"].Value;
return job_no;
}
// Bjorn A
Nov 17 '05 #3
i'm not sure but i think it's a function. if i have to use a proc (stored
procedure), then how do i implement everything?

"microsoft.news .com" wrote:
is it a proc or a function?
The Oracle proc should call the function.

I'm not sure if you can call an actual function straight from code without
calling it from a proc (stored procedure) and then exposing it that way to
out side code.

"Newbie" <Ne****@discuss ions.microsoft. com> wrote in message
news:7C******** *************** ***********@mic rosoft.com...
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 #4
i'm getting the exception:

Parameter 'p1': No size set for variable length data type: String.

my code follows:

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 ();
//i couldnt find the namespace required forOracleDbType .Int32
par1.Direction = ParameterDirect ion.ReturnValue ;
cmd.Parameters. Add(par1);
par1 = new OracleParameter ();
par1.Value = projectNo;
par1.Direction = ParameterDirect ion.Input;
cmd.Parameters. Add(par1);
int affectedRows = (int) cmd.ExecuteNonQ uery();
ljn = (int) cmd.Parameters["RETURN_VAL UE"].Value;

"Bjorn Abelli" wrote:

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


That statement was confusing, as a stored function as "a kind of" stored
procedure, from ADO.NET's point of view...
given a project_no, i need to call the function:
ops$sqltime.pa_ new_job_no_fn
which will return the next job_no

In short, I'd guess something like this should work...

private int NextJobNo(int project_no)
{
OracleCommand cmd = new OracleCommand() ;
cmd.Connection = cn; // You have the connection somewhere, don't
you..."
cmd.CommandText = "ops$sqltime.pa _new_job_no_fn" ;
cmd.CommandType = CommandType.Sto redProcedure;

OracleParameter par1 =
new OracleParameter ("RETURN_VALUE" , OracleDbType.In t32);
par1.Direction = ParameterDirect ion.ReturnValue ;
cmd.Parameters. Add(par1);

par1 = new OracleParameter ("PROJECT_NO ", OracleDbType.In t32);
par1.Value = project_no;
par1.Direction = ParameterDirect ion.Input;
cmd.Parameters. Add(par1);

int affectedRows = (int) cmd.ExecuteNonQ uery();
int job_no = (int) cmd.Parameters["RETURN_VAL UE"].Value;
return job_no;
}
// Bjorn A

Nov 17 '05 #5
"Newbie" wrote...

//i couldnt find the namespace required for OracleDbType.In t32

That depends on which provider you're using!

If you don't use Oracle's provider (where the types are defined in
Oracle.DataAcce ss.Client.Oracl eDbType), you should be able to use
System.Data.Ora cleClient.Oracl eType instead (in Microsoft's provider for
Oracle).

I haven't run any stored functions with it myself (I've only used Oracle's
own provider), so I'm not sure about the behaviour from Microsoft's
provider...

But my guess is that you simply can change OracleDbType to OracleType in
your code... :-)

i'm getting the exception:

Parameter 'p1': No size set for variable length data type: String.


Well, you don't set any types or names for any parameters at all, so I
believe it defaults to String, which *must* be defined with a length (just
as CHAR and VARCHAR2 in Oracle must have lengths)...

With the small changes I mentioned above, you'll probably at least come one
step further...

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.Int3 2);
par1.Direction = ParameterDirect ion.ReturnValue ;
cmd.Parameters. Add(par1);

// It's best to check what the input parameter *really* is
// named in the stored function, and to use that name...

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

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

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

// Bjorn A
Nov 17 '05 #6
already tried changing OracleDbType.In t32 to OracleType.Int3 2 but still
getting the same exception

"Bjorn Abelli" wrote:
"Newbie" wrote...

//i couldnt find the namespace required for OracleDbType.In t32

That depends on which provider you're using!

If you don't use Oracle's provider (where the types are defined in
Oracle.DataAcce ss.Client.Oracl eDbType), you should be able to use
System.Data.Ora cleClient.Oracl eType instead (in Microsoft's provider for
Oracle).

I haven't run any stored functions with it myself (I've only used Oracle's
own provider), so I'm not sure about the behaviour from Microsoft's
provider...

But my guess is that you simply can change OracleDbType to OracleType in
your code... :-)

i'm getting the exception:

Parameter 'p1': No size set for variable length data type: String.


Well, you don't set any types or names for any parameters at all, so I
believe it defaults to String, which *must* be defined with a length (just
as CHAR and VARCHAR2 in Oracle must have lengths)...

With the small changes I mentioned above, you'll probably at least come one
step further...

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.Int3 2);
par1.Direction = ParameterDirect ion.ReturnValue ;
cmd.Parameters. Add(par1);

// It's best to check what the input parameter *really* is
// named in the stored function, and to use that name...

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

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

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

// Bjorn A

Nov 17 '05 #7

"Newbie" wrote...
already tried changing OracleDbType.In t32 to OracleType.Int3 2
but still getting the same exception


Did you name the parameters?

What is the *real* name of the input parameter?

Did you use that name?

Are there *more* parameters in the stored function than the input parameter
and the return value?

Did you get the "no length on String" error, even when you used
OracleType.Int3 2?

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.Int3 2);
par1.Direction = ParameterDirect ion.ReturnValue ;
cmd.Parameters. Add(par1);

// It's best to check what the input parameter *really* is
// named in the stored function, and to use that name...

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

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

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


// Bjorn A

Nov 17 '05 #8
the real name of the input parameter is project_no which is a string. the
return value should be the job_no. 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

my code follows:

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 ();
par1.Direction = ParameterDirect ion.ReturnValue ;
par1.Size = 4000;
cmd.Parameters. Add(par1);
par1 = new OracleParameter ();
par1.Value = projectNo;
par1.Direction = ParameterDirect ion.Input;
par1.Size = 4000;
cmd.Parameters. Add(par1);
int affectedRows = (int) cmd.ExecuteNonQ uery();
int ljn = (int) cmd.Parameters["RETURN_VAL UE"].Value;
"Bjorn Abelli" wrote:

"Newbie" wrote...
already tried changing OracleDbType.In t32 to OracleType.Int3 2
but still getting the same exception


Did you name the parameters?

What is the *real* name of the input parameter?

Did you use that name?

Are there *more* parameters in the stored function than the input parameter
and the return value?

Did you get the "no length on String" error, even when you used
OracleType.Int3 2?

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.Int3 2);
par1.Direction = ParameterDirect ion.ReturnValue ;
cmd.Parameters. Add(par1);

// It's best to check what the input parameter *really* is
// named in the stored function, and to use that name...

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

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

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


// Bjorn A

Nov 17 '05 #9

"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 #10

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

Similar topics

3
5227
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
17027
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
1620
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
6676
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
29335
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
14770
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
13846
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
3810
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
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9200
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
9142
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...
1
6722
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
4525
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
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
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
2
2680
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2163
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.