oracle 如何将 SYS_GUID() 转换为 varchar?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/603504/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 01:44:41  来源:igfitidea点击:

How do you convert SYS_GUID() to varchar?

oracleguid

提问by jon077

In oracle 10g, how do you convert SYS_GUID() to varchar? I am trying something like:

在oracle 10g 中,如何将SYS_GUID() 转换为varchar?我正在尝试类似的东西:

select USER_GUID from user where email = '[email protected]'

Which returns the RAW byte[]. Is it possible to use a function to convert the RAW to VARCHAR2 in the SQL statement?

它返回原始字节[]。是否可以使用函数将 SQL 语句中的 RAW 转换为 VARCHAR2?

回答by Quassnoi

Don't forget to use HEXTORAW(varchar2)when comparing this value to the RAWcolumns.

HEXTORAW(varchar2)将此值与RAW列进行比较时不要忘记使用。

There is no implicit convesion from VARCHAR2to RAW. That means that this clause:

VARCHAR2to没有隐式转换RAW。这意味着该条款:

WHERE raw_column = :varchar_value

will be impicitly converted into:

将被隐式转换为:

WHERE RAWTOHEX(raw_column) = :varchar_value

, thus making indices on raw_columnunusable.

,从而使索引raw_column无法使用。

Use:

用:

WHERE raw_column = HEXTORAW(:varchar_value)

instead.

反而。

回答by jon077

Use RAWTOHEX(USER_GUID).

使用 RAWTOHEX(USER_GUID)。

回答by geekzspot

select RAWTOHEX(USER_GUID) from user where email = '[email protected]'

回答by geekzspot

Please don't mod-1 if I'm wrong. I'm going from memory so this a disclaimer to verify.

如果我错了,请不要修改 1。我从记忆中去,所以这是一个免责声明来验证。

TO_CHAR is actually different between SQL and PL/SQL.

TO_CHAR 实际上在 SQL 和 PL/SQL 之间是不同的。

In SQL TO_CHAR does not take a raw as you have found out.

在 SQL TO_CHAR 中,您发现的不是原始数据。

In PL/SQL To_CHAR will take a raw value.

在 PL/SQL To_CHAR 中将采用原始值。

So if you're in a procedure anyways, sometimes it easier to use a variable, but if you're just using SQL, go with the other answers here.

因此,如果您无论如何都在过程中,有时使用变量会更容易,但如果您只是使用 SQL,请使用此处的其他答案。

回答by Toolkit

select CAST (USER_GUID AS VARCHAR2(100)) from user where email = '[email protected]'

select CAST (USER_GUID AS VARCHAR2(100)) from user where email = '[email protected]'