code: func builtinHex(args []types.Datum, ctx context.Context) (d types.Datum, err error) {
  	switch args[0].Kind() {
  	case types.KindNull:
  		return d, nil
  	case types.KindString:
  		x, err := args[0].ToString()
  		if err != nil {
  			return d, errors.Trace(err)
  		}
  		d.SetString(strings.ToUpper(hex.EncodeToString(hack.Slice(x))))
  		return d, nil
  	case types.KindInt64, types.KindUint64, types.KindMysqlHex, types.KindFloat32, types.KindFloat64, types.KindMysqlDecimal:
  		x, _ := args[0].Cast(ctx.GetSessionVars().StmtCtx, types.NewFieldType(mysql.TypeLonglong))
  		h := fmt.Sprintf("%x", uint64(x.GetInt64()))
  		d.SetString(strings.ToUpper(h))
  		return d, nil
  	default:
  		return d, errors.Errorf("Hex invalid args, need int or string but get %T", args[0].GetValue())
  	}
  }
docs: // See http://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_hex