string Hiveql - RIGHT() LEFT() 函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41435889/
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-08 16:35:49  来源:igfitidea点击:

Hiveql - RIGHT() LEFT() Function

stringhivehiveql

提问by jmich738

Is there a function in Hiveql that is equivalent to Right() or Left() fuction form TSQL? For example, RIGHT(col1,10)to get the first 10 characters from col1.

Hiveql 中是否有等效于 Right() 或 Left() 函数形式 TSQL 的函数?例如,RIGHT(col1,10)从 col1 中获取前 10 个字符。

thank you

谢谢你

回答by sandeep rawat

There is no right or left function but you can implement same with substr like

没有右或左功能,但您可以使用 substr 实现相同的功能,例如

left (column, nchar) = substr(column, 0, nchar)

right  (column, nchar) = substr (column, (-1)* nchar)

Note: Here ncharis no of character

注意:这里nchar不是字符

回答by ańō??Xmo??

This works for me for right function: substr (col, -nchar) = right(col, nchar).

这对我来说适用于正确的函数:substr (col, -nchar) = right(col, nchar)。

hive> select substr('adbcefghij',-4);
ghij
Time taken: 40.839 seconds, Fetched: 1 row(s)

Hope this helps.

希望这可以帮助。

回答by ALEKSEY NIKITOV

right(column, nchar) = substr(column, (length(column)-nchar+1), nchar)

right(column, nchar) = substr(column, (length(column)-nchar+1), nchar)