一句简单SQL的写法

ebb 2006-08-15 03:02:00
输入参数是arg_type
希望从A表中customer_type字段中查出所有以arg_type开头的记录
如果不带参数的话就是
select * from a where customer_type like 'xxx%'
但是如果带参数的话应该怎么写?
谢谢
...全文
120 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
叶落无心 2006-08-16
  • 打赏
  • 举报
回复
type t_refCur is ref cursor
procedure( p_arg varchar2 )
is
l_cur t_refCur
begin
open l_cur for
'select * from a where customer_type like :arg' using p_arg||'%';
end ;
feng2 2006-08-16
  • 打赏
  • 举报
回复
SQL> select * from a;

ITEM_NO ITEM_SUB_NO ITEM_NAME
---------- ----------- --------------------
111 1 55
111 2 54
111 6 54
333 8 45
222 4 29
444 5 44

6 rows selected

SQL> select * from a where item_no like '&_t%';-- 输入 3

ITEM_NO ITEM_SUB_NO ITEM_NAME
---------- ----------- --------------------
333 8 45

SQL> select * from a where item_no like '&_t%';-- 输入2

ITEM_NO ITEM_SUB_NO ITEM_NAME
---------- ----------- --------------------
222 4 29

SQL>
snowy_howe 2006-08-16
  • 打赏
  • 举报
回复
需要做连接字符串,用execute来执行
gw_delphi 2006-08-15
  • 打赏
  • 举报
回复
不太明白你的意思.参数直接是变量也可以啊
select * from a where instr(customer_type,'arg_type') > 0
liuyangly 2006-08-15
  • 打赏
  • 举报
回复
如果是在JAVA里面是这样写的:
select * from a where customer_type like ?

String parameter = "xxx" + "%";
把字符串转进去就行了.

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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