Oracle functions, stored procedures, sequences

Source: Internet
Author: User

A. function

1. c2b function: Clob to BLOB

Create or Replace functionC2B (binchClobdefaultEmpty_clob ())returnblob isres blob; Blen Number:=Dbms_lob.getlength (b); DestOffset1 Number:= 1; SrcOffset1 Number:= 1; AMOUNTCinteger:=dbms_lob.lobmaxsize; Blobcsid Number:=Dbms_lob.default_csid; Langctxinteger:=Dbms_lob.default_lang_ctx; Warninginteger;begin    ifBlen> 0  ThenDbms_lob.createtemporary (res, true); Dbms_lob.Open(res, dbms_lob.lob_readwrite);    Dbms_lob.converttoblob (res, B, AMOUNTC, DestOffset1, SrcOffset1, Blobcsid, Langctx, warning); Else        SelectEmpty_blob () intoRes fromdual; End if; returnRes;EndC2B;
View Code


2. Hextodec function: Hexadecimal string to numeric type string

Create or Replace functionHextodec (Ichexinch   varchar2)return   varchar2    isIdecimalinteger; Cnewhexvarchar2(1); Ihexleninteger; Resultinteger;beginResult:=0; Ihexlen:=length (Ichex);  forIinch  1.. Ihexlen Loop Cnewhex:=SUBSTR (Ichex,ihexlen-I+   1,1); SelectDecode (Cnewhex,'A',Ten,'B', One,'C', A,'D', -,'E', -,'F', the, To_number (Cnewhex)) intoIdecimal fromdual; Result:=Result+Idecimal*   Power( -, (i-1)); EndLoop; return(To_char (Result));EndHextodec;
View Code


3. Dectohex function: Numeric string-to-hexadecimal string

Create or Replace functionDecToHex (Idecimalinch   varchar2)return   varchar2    isNdecimalinteger; Quotientinteger; Residueinteger; Resultvarchar2( -);beginNdecimal:=To_number (Idecimal); Loop quotient:=    Floor(Ndecimal/ -); Residue:=Ndecimal MoD -; SelectDecode (Residue,Ten,'A', One,'B', A,'C', -,'D', -,'E', the,'F', To_char (residue))||result intoResult fromdual; Exit    whenQuotient=   0; Ndecimal:=quotient; EndLoop; return(result);EndDecToHex;
View Code

Two. Sequence

1. Create a sequence

Create0 99999999 with 1 by 1 NoCache;
View Code

  

2. Seqreset stored procedure: Reset sequence

Create or Replace procedureSeqreset (vseqnamevarchar2) isN Number(Ten); TSQLvarchar2( -);begin    ExecuteImmediate'Select'||Vseqname||'. Nextval from dual'  intoN; N:=-N; TSQL:='Alter sequence'||Vseqname||'Increment by'||N; Executeimmediate TSQL; ExecuteImmediate'Select'||Vseqname||'. Nextval from dual'  intoN; TSQL:='Alter sequence'||Vseqname||'Increment by 1'; Executeimmediate TSQL;EndSeqreset;
View Code

Oracle functions, stored procedures, sequences

Related Article

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.