Posted By: Petrus Spesial Copy of Procedures and functions. - 09/30/11 08:04 AM

In the SQL window there is a spesical copy function where the sql state can be turned into a C#, VB variable. This is a nice function that I use a lot.

It would be great if this also was available on the procedure and function level to generate code that can be pasted into the client.

Can you provide an example?
Posted By: Petrus Re: Spesial Copy of Procedures and functions. - 09/30/11 11:42 AM
Oracle function:
FUNCTION Is_Numeric(Parameter_ IN VARCHAR2) RETURN NUMBER IS

char_ VARCHAR2(1);
char_counter_ INTEGER;
is_numeric_ NUMBER;

BEGIN

is_numeric_ := 1;
char_counter_ := 0;
WHILE (char_counter_ <= LENGTH(Parameter_)) LOOP
char_counter_ := char_counter_ + 1;
char_ := SUBSTR(Parameter_,
char_counter_,
1);
IF (INSTR('0123456789',
char_,
1) = 0) THEN
is_numeric_ := 0;
EXIT;
END IF;
END LOOP;

RETURN(is_numeric_);
END Is_Numeric;

VB.NET code to run this function:

Imports System.Data.OracleClient
Imports System

Module ModuleTest

Const _oracleuser As String = "oracle user>"
Const _connectstring As String = "Oracle connect string"
Public Class TEST_API

' FUNCTION Is_Numeric(Parameter_ IN VARCHAR2) RETURN NUMBER IS
Public Function IsNumeric(ByVal Parameter_ As String) As Decimal
Dim _return_value As Decimal
Dim _commandtext As String = _oracleuser + ".TEST_API.Is_Numeric"
Using connection As New OracleConnection(_connectstring)
Dim Cmd As New OracleCommand(_commandtext, connection)
Try
Cmd.CommandType = CommandType.StoredProcedure
Cmd.Parameters.Add("Parameter_", OracleType.VarChar).Direction = ParameterDirection.Input
Cmd.Parameters.Add("Return_Value_", OracleType.Number).Direction = ParameterDirection.ReturnValue
Cmd.Parameters("Parameter_").Value = Parameter_
connection.Open()
Cmd.ExecuteNonQuery()
_return_value = Cmd.Parameters("Return_Value_").Value
Catch ex As Exception
MessageBox.Show("Oracle error message: " + ex.Message)
Return (-1)
Finally
connection.Close()
End Try
End Using
Return (_return_value)

End Function
End Class

End Module
© Allround Automations forums