想要执行以下sql语句
select * from testTabel where colName in ('a', 'b')用plsql实现的相关代码
declare
TYPE Tab_Test IS TABLE OF testTable.colName%TYPE INDEX BY BINARY_INTEGER;
tar Tab_Test;
begin
tar(1) := 'a';
tar(2) := 'b'; select * from testTabel where colName in 这里怎么写?
end注:主要是想问table类型怎么用在in的查询条件里,下面这样的方法不行。
var := '(' || tar(1) || ', ' || tar(2) || ')';
就是单引号的问题
select * from testTabel where colName in ('a', 'b')用plsql实现的相关代码
declare
TYPE Tab_Test IS TABLE OF testTable.colName%TYPE INDEX BY BINARY_INTEGER;
tar Tab_Test;
begin
tar(1) := 'a';
tar(2) := 'b'; select * from testTabel where colName in 这里怎么写?
end注:主要是想问table类型怎么用在in的查询条件里,下面这样的方法不行。
var := '(' || tar(1) || ', ' || tar(2) || ')';
就是单引号的问题
解决方案 »
- ORA-00972: 标识符过长
- 写了一个含有if else 嵌套语句的触发器,老是报错
- sqlplus
- imp命令的导入是插入还是覆盖?
- 关于自定义函数如何使用??---
- 触发器能否触发一个存储过程
- 我的80端口号被oracle http server占用,如何改为别的端口呢?
- 哪里有oracle 9i下载..?(要可正常安装的)
- 请问下面的两条语句其查询效率比较怎么样?
- 我有1个insert 语句,1个delete语句,如果实现insert语句发生异常时继续执行下面的delete语句??
- 有用OCI开发过oracle georaster的吗
- PC编译问题:ld: Unsatisfied symbol "sqlcxt" in file xxxx
连续两个单引号也不行
'(''' ||tar(1)||''','''||tar(2)||''')'
select * from testTabel
where colName in '(''' || tar(1) || ''',''' || tar(2) || ''')'
Thank you!!可是,有没有什么系统包之类的呢,或是其它的方法 ,用来简化。
比如说在select中,对于table类型,可以这样用
select colName BULK COLLECT INTO tar FROM testTabel ;
就把查寻结果全都装入tar中了
好像还有问题,东西没有查出来。
直接在plsql里使用select * from testTabel where colName in ('a', 'b'),是有查寻结果的。
按照上面方法拼接,相应部分确实变成了('a', 'b')的形式。但是什么都没有查到。
SQL> declare
2 a number := 1;
3 b number := 2;
4 c number;
5 begin
6 execute immediate 'select 1 from dual where 1 between :a and :b'
7 into c
8 using a, b;
9 end;
10 /PL/SQL procedure successfully completedSQL>
select * from testTabel where colName in ('a', 'b')
和
select * from testTabel where colName in '(''' || tar(1) || ''',''' || tar(2) || ''')'有区别吗,怎么会一个能查到,一个查不到?
var := '(''' || tar(1) || ''', '''|| tar(2) || ''')';
DBMS_OUTPUT.PUT_LINE(var);
查看是没有问题的,为('a', 'b')
TYPE Tab_Test IS TABLE OF testTable.colName%TYPE INDEX BY BINARY_INTEGER;
tar Tab_Test;
begin
tar(1) := 'a';
tar(2) := 'b';
execute immediate 'select * from testTabel where colName(:1,:2)' into xxxx using tar(1),tar(2);
end
我的colName列是varchar2,里面存的是各种字符串
而且,假设tar有100项,这样会不会不太好写
rel TYPE_CIRELATION;
tar TYPE_CIRELATION;
var varchar2(150);begin
tar(1):='c';
tar(2):='a';
var := '(''' || tar(1) || ''','''|| tar(2) || ''')';
var := 'select sourceci from testtable where targetci in' || var;
execute immediate var bulk collect into rel;
end