C # using Oracle Stored Procedure notes

Source: Internet
Author: User
1. Call includes Out/in outStored Procedure of type parameters
Stored Procedure:
Create or replace procedure "SITE_EDITSITEDATAEXIST"
(Id _ number,
Name _ varchar2,
HttpRoot _ varchar2,
Flag out integer) // out only provides the output function. in out is the input/output type.
As
TempNum integer;
Begin
If tempNum> 0 then
End if;

If tempNum> 0 then
End if;
Commit;
End;
/

Call method:

// If it is an in out type, the response must be: // Ming InputOutput
{
New OracleParameter ("subjectId", OracleType. VarChar, 60)
};

OracleHelper. ExecuteReader (OracleHelper. CONN_STRING_BASE, CommandType. StoredProcedure,

"Site_EditSiteDataExist", param );

// The ExecuteReader method must be used when return values exist.

Return int. Parse (val. ToString ());

 
2. Stored Procedure return record set

The stored procedure must be written in the package and then called.

Package Syntax:

Create or replace package pkg_cms

AS

TYPE myrctype is ref cursor;

PROCEDURE site_GetSiteData (Id _ number, p_rc OUT myrctype );

END pkg_cms;

/

Create or replace package body pkg_cms

AS
PROCEDURE site_GetSiteData (Id _ number, p_rc OUT myrctype)

IS

BEGIN

OPEN p_rc

Select Id, Name, Url, Folder_Name, Desccms, Char_Name,

DB_Address, DB_User, DB_Password, DB_Name, DB_ConnString, HttpRoot

From WebSite_Info

END site_GetSiteData;

END pkg_cms;

/

Call:

{

New OracleParameter (PARM_ID _, OracleType. Number, 8 ),

New OracleParameter ("p_rc", OracleType. cursor, 2000, ParameterDirection. output, true, 0, 0, "", DataRowVersion. default, Convert. DBNull) // The cursor type declared in the package body.

};

Return OracleHelper. ExecuteReader (OracleHelper. CONN_STRING_BASE, CommandType. StoredProcedure, "pkg_cms.site_GetSiteData", param );

// Write the package name before calling

3.OracleOther methods in the Stored Procedure

String operation
INSTR (STR, Maker) // obtain the character position in the string

SUBStr (str, beginnum, len) // obtain the substring

To_char () // convert a number to a string

| // Equals to +

LENGTH (Oldword) // obtain the string LENGTH

Time

To_date ('datestr', 'yyyy-Mi-dd') // convert string to date type "'yyyy-MM-DD '"

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.