Forum Stats

  • 3,782,556 Users
  • 2,254,666 Discussions
  • 7,880,122 Comments

Discussions

tag length value to hexadecimal

User_WWD0C
User_WWD0C Member Posts: 8 Green Ribbon

Tag = 01

length = 12

value = Bobs Records

hex = 010c426f6273205265636f726473

when i run

SELECT RAWTOHEX('Bobs Records') FROM dual

i get my desire result which is '426f6273205265636f726473'

and when i run

SELECT LENGTHB('Bobs Records') FROM dual;

i get the bytes which is 12

my question is how can i convert tlv to hex

010c426f6273205265636f726473

Best Answer

  • cormaco
    cormaco Member Posts: 1,771 Bronze Crown
    Accepted Answer

    Here is one way:

    with tv(tag,val) as (select '01','Bobs Records' from dual)
    select tag||to_char(lengthb(val),'fm0x')||rawtohex(val) as tlv from tv;
    
    TLV                          
    -----------------------------
    010c426F6273205265636F726473
    

    Note that the format model fm0x only works for lengths up to 256, you have use more 'x' for longer values.

Answers