Access中Left()和Left $()函数之间的区别 [英] Difference between Left() and Left$() function in Access

查看:150
本文介绍了Access中Left()和Left $()函数之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试调试损坏的查询.查询使用 Left $([blahblah],4)而不是Left([blahblah],4).

I am trying to debug a broken query. The query uses Left$([blahblah],4) instead of Left([blahblah],4).

在其中的Left()和Left $()函数之间有什么区别 Microsoft Access?

What is the difference between the Left() and Left$() functions in Microsoft Access?

推荐答案

结尾的$是String数据类型的类型声明字符 VBA.

The trailing $ is a type declaration character for the String data type in VBA.

从Left $()返回的结果是一个字符串,而Left()返回一个 变体.

The result returned from Left$() is a string, whereas Left() returns a Variant.

如果有可能出现Null值,则必须使用Left(),而不是Left $(), 因为Variant可以为Null,但String不能为Null.为了证明这一点:

You must use Left(), not Left$() if there is any chance of Null values, since the Variant can be Null but the String cannot. To demonstrate that:

  1. 按Ctrl + G打开Immedate窗口.

  1. Press Ctrl+G to open the Immedate window.

输入: ?左(空,1) 答案是空.

Enter: ? Left(Null,1) The answer is Null.

现在输入: ?左$(Null,1) 这将生成错误94.由于结果应为Null,因此字符串为 不能为Null,则会收到错误消息:无效使用Null".

Now enter: ? Left$(Null,1) This generates Error 94. Since the result should be Null, and the String cannot be Null, you receive the error, "Invalid use of Null".

如果要处理字符串值,则在VBA代码中,Left $()会稍微变小 效率更高,因为它避免了与 变体.但是,如果可能有任何个可能涉及空值的情况,请使用 Left(),否则用诸如Nz()之类的东西显式处理Null.

If you are dealing with string values, in VBA code, Left$() will be slightly more efficient, as it avoids the overhead/inefficieny associated with the Variant. However, if there is any chance that Nulls may be involved, use Left(), or else explicitly handle the Null with something such as Nz().

left $()如果返回NULL,将返回一个字符串或生成错误

left$() will return a string or generate an error if passed NULL

left()如果返回NULL,将返回一个字符串或NULL

left() will return a string or NULL if passed NULL

有关Null的更多信息: http://allenbrowne.com/casu-11.html

More information on Nulls: http://allenbrowne.com/casu-11.html

这篇关于Access中Left()和Left $()函数之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆