---
title: "oracle数据库十六进制转十进制函数"
author: "qflamj"
date: "2010-07-23T14:11:39Z"
tags: ["C", "C#", "C++", "Oracle", "SQL"]
categories: ["数据库"]
slug: "oracle"
draft: false
lastmod: "2010-07-23T14:49:55Z"
id: 719698
url: "https://qflamj.iteye.com/blog/719698"
---

```sql

create or replace   
FUNCTION "HXTOTEN" (str_a IN VARCHAR2) RETURN NUMBER     
IS   
str_b NUMBER(10);   
str_c VARCHAR2(100);   
  
BEGIN   
    str_c:=REPLACE(str_a,'0x','');   
    str_b:=0;   
    WHILE LENGTH(str_c) IS NOT NULL LOOP   
        str_b:=str_b*16+CASE SUBSTR(str_c,0,1)   
        when   'A'   then   10       
  
            when   'B'   then   11     
  
            when   'C'   then   12     
  
            when   'D'   then   13     
  
            when   'E'   then   14     
  
            when   'F'   then   15     
  
            ELSE     CAST(SUBSTR(str_c,0,1) AS INT)   
        END;   
        str_c:=SUBSTR(str_c,-(LENGTH(str_c)-1),LENGTH(str_c)-1);   
    END LOOP;   
      RETURN str_b;   
END HXTOTEN; 

```