开发者

Oracle REGEXP_LIKE and the meaning of \A and \Z

I came across code similar to the following in an Oracle stored procedure:

SELECT * FROM hr.employees WHERE REGEXP_LIKE(FIRST_NAME, '\A'||:iValue||'\Z', 'c');

And I am not sure what the \A and \Z do.

From what I can glean from the Oracle documentation, I think that they simply suppress the meaning of special characters in the iValue parameter. If so, the above must be equivalent to

SELECT * FROM hr.employees WHERE FIRST_NAME=:iValue;

Can anyone confirm this? Empirically this seems to be 开发者_JAVA技巧the case.

I think that in the past they wanted case insensitive searching so the 'c' was an 'i' before. So in this case we do not need to use the REGEXP_LIKE function any more and can replace it with an equals.


  • \A matches the position at the beginning of the string.
  • \Z matches the position at the end of the string or before a newline at the end of the string.
  • \z matches the position at the end of the string.

These are independent of multiline mode, unlike ^ and $.

Example:

foo\Z would match on foo\n, but foo\z would not match on foo\n.

See Oracle reference.


if || is used for string concatenation, then it's not the same as simple string comparison as it would allow you to use regex. (Also I'm not sure how Oracle treats case sensitivity when using =, MySQL ignores case by default when comparing strings.)


\A matches the very start of input.
\Z matches the very end of input.

Check out regular-expressions.info, which is a great regex resource

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜