zoukankan      html  css  js  c++  java
  • HexToChar

    USE AdventureWorks2008R2;
    GO
    IF EXISTS(SELECT name FROM sys.objects
              WHERE name = N'dbo.sp_HexToChar')
        DROP PROCEDURE HexToChar;
    GO
    CREATE PROCEDURE dbo.sp_HexToChar
        @BinValue varbinary(255),
        @HexCharValue nvarchar(255) OUTPUT
    AS
        DECLARE @CharValue nvarchar(255);
        DECLARE @Position int;
        DECLARE @Length int;
        DECLARE @HexString nchar(16);
        SELECT @CharValue = N'0x';
        SELECT @Position = 1;
        SELECT @Length = DATALENGTH(@BinValue);
        SELECT @HexString = N'0123456789ABCDEF';
        WHILE (@Position <= @Length)
        BEGIN
            DECLARE @TempInt int;
            DECLARE @FirstInt int;
            DECLARE @SecondInt int;
            SELECT @TempInt = CONVERT(int, SUBSTRING(@BinValue,@Position,1));
            SELECT @FirstInt = FLOOR(@TempInt/16);
            SELECT @SecondInt = @TempInt - (@FirstInt*16);
            SELECT @CharValue = @CharValue +
                SUBSTRING(@HexString, @FirstInt+1, 1) +
                SUBSTRING(@HexString, @SecondInt+1, 1);
            SELECT @Position = @Position + 1;
        END
        SELECT @HexCharValue = @CharValue;
    GO
    DECLARE @BinVariable varbinary(35);
    DECLARE @CharValue nvarchar(35);
    
    SET @BinVariable = 123456;
    
    EXECUTE dbo.sp_HexToChar
        @binvalue = @BinVariable,
        @HexCharValue = @CharValue OUTPUT;
    
    SELECT @BinVariable AS BinaryValue,
        @CharValue AS CharacterRep;
    GO
  • 相关阅读:
    redis 学习笔记三
    hadoop 家族图
    hbase 笔记
    spark history server
    利用Intellij IDEA构建spark开发环境
    自己安装的工具版本
    hive读书笔记
    数据仓库元数据
    Spark RDD
    pg mysql 比较
  • 原文地址:https://www.cnblogs.com/Amaranthus/p/2049683.html
Copyright © 2011-2022 走看看