DB2中使用like的问题请教

hengdda 2006-11-24 10:08:17
请教个问题
在sqlserver和oracle中 比如有2个表
create table t1
(
aa varchar(20)
)
create table t2
(
bb varchar(20)
)
如果
insert into t1 values ('cc')
insert into t2 values ('ccd')

接着再查询2表中是否有相似的数据 可以在oralce或者sqlserver中这样写
select * from t1,t2 where t1.aa like t2.bb
也可以在t2.bb上加||'%' 或者 +'%'

但是根据我现在在db2 v8 上的实验
select * from t1,t2 where t1.aa like t2.bb
这么写是不行的

似乎db2只能 aa like 'c%' 这样写 like后面的比较对象只能是个变量或者函数之类的 而不能是另外一个表的列

请教以下路过的高手 如何在联表查询的时候对列使用like ?
==================================================
另外问一下 如何在调试的时候打印变量?

sqlserver可以通过print(@var)
oracle 可以 dbms_output.put_line(var)

那么db2是什么? 谢谢
...全文
787 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
bluesky1001 2006-11-29
  • 打赏
  • 举报
回复
db2中谓词LIKE后边的表达式不支持字段。只支持一下类型:
A constant
A special register
A host variable
A scalar function whose operands are any of the above
An expression concatenating any of the above

(附DB2文档:
使用格式: match-expression LIKE pattern-expression
match-expression
An expression that specifies the string that is to be examined to see if it conforms to a certain pattern of characters.
The expression can be specified by:

A constant
A special register
A host variable (including a locator variable or a file reference variable)
A scalar function
A large object locator
A column name
An expression concatenating any of the above

pattern-expression
An expression that specifies the string that is to be matched.
The expression can be specified by:

A constant
A special register
A host variable
A scalar function whose operands are any of the above
An expression concatenating any of the above
with the following restrictions:

No element in the expression can be of type LONG VARCHAR, CLOB, LONG VARGRAPHIC, or DBCLOB. In addition it cannot be a BLOB file reference variable.
The actual length of pattern-expression cannot be more than 32 672 bytes.
hengdda 2006-11-29
  • 打赏
  • 举报
回复
电话给idm的工程师 人家也说不支持。但是可以凑合用以下方法对付。
如果 被匹配的东西都是这个形式 'xxxxx%' 而不是 '%xxxxxxxx%'
那么
aa like bb 可以写为
substr(aa,1,length(bb)) = bb 对付一下
虽然感觉效率低下。
但是连ibm的人都这么说 也只好凑合一下了 谢谢以上各位了。
hengdda 2006-11-27
  • 打赏
  • 举报
回复
顶一下 求路过的大侠支个招 只要能解决问题 其他方法也可以
难道db2这么多人用 没有人遇到过类似的问题吗?都怎么解决了呢?
catchmeifyoucan 2006-11-25
  • 打赏
  • 举报
回复
顶一下

5,889

社区成员

发帖
与我相关
我的任务
社区描述
IBM DB2 是美国IBM公司开发的一套关系型数据库管理系统,它主要的运行环境为UNIX(包括IBM自家的AIX)、Linux、IBM i(旧称OS/400)、z/OS,以及Windows服务器版本
社区管理员
  • DB2
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧