--比如有如下代码:begin v_s1 := 'abc';
v_s2 := '123'; select count(1) into v_count from t1 where x in (v_s1, v_s2);
end;
--v_count的结果是0, 请教如何正确改写这段代码? --另请教v_s1, v_s2可改为 嵌套表 或 Varry类型吗?--多谢!
v_s2 := '123'; select count(1) into v_count from t1 where x in (v_s1, v_s2);
end;
--v_count的结果是0, 请教如何正确改写这段代码? --另请教v_s1, v_s2可改为 嵌套表 或 Varry类型吗?--多谢!
解决方案 »
- 我想把Oracle10g的数据库导到selserver 2000里 怎么导 能导吗
- 比较两个sql语句是否等价,检索结果是否相同
- oracle起动不了了,请大家帮看看日志是什么回事,谢了
- 高手请进:系统视图问题!急~~~急~~~急~~~急~~~急~~~
- 在线等!!在oracle中,如何进行多表更新?
- 我有一用户买的有许可的oracle9i for windows的盘,安装后发现和从网上下载的一样,但是不能注册啊,是不有试用的问题,有人说只是有服务,网
- win98启动瘫痪,ORACLE7如何备份
- 让job正常的定时运行,到底需要改那些参数阿?
- 数据库连接问题
- 只能用decode嵌套实现吗?比方说1-9为一组,10-39,40-99,100-999这样的组进行group by.谁有好办法?
- 存储过程怎么自动非法啦?
- 关于SQL合并字段的问题。。。急!!!
当改成select count(1) into v_count from t1 where x in ('abc', '123'); 就有结果了, 不信你测试一下试试.
declare
v_s1 varchar2(10);
v_s2 varchar2(10);
v_count int;
begin
v_s1 := 'abc';
v_s2 := '123';
select count(1) into v_count from t1 where x in (v_s1,v_s2);
dbms_output.put_line(v_count);
end;
/
非也.
当改成select count(1) into v_count from t1 where x in ('abc', '123'); 就有结果了, 不信你测试一下试试.
改成select count(1) into v_count from t1 where x in ('abc', '123') 就有结果了, 不信你测试一下试试
--另请教v_s1, v_s2可改为 嵌套表 或 Varry类型吗? 不可以的,里面必须是一个一个值,并且用,符号连接起来。
----------
abc已用时间: 00: 00: 00.00
09:15:39 scott@TUNGKONG> declare
09:15:50 2 v_s1 varchar2(10);
09:15:50 3 v_s2 varchar2(10);
09:15:50 4 v_count int;
09:15:50 5 begin
09:15:50 6 v_s1 := 'abc';
09:15:50 7 v_s2 := '123';
09:15:50 8 select count(1) into v_count from t1 where x in (v_s1,v_s2);
09:15:50 9 dbms_output.put_line(v_count);
09:15:50 10 end;
09:15:50 11 /
1PL/SQL 过程已成功完成。
这不有结果吗?
这是我的结果, 难道是版本或补丁问题?
SQL> select distinct c3 from t1;
C3
----------
w0
w1
w2
-------------------------
SQL> select count(1) from t1 where c3 in ('w1','w2');
COUNT(1)
----------
6SQL> declare
2 v_count integer;
3 v_s1 varchar2(20);
4 v_s2 varchar2(20);
5 begin
6 v_s1 := 'w1';
7 v_s2 := 'w2';
8 select count(1) into v_count from t1 where c3 in (v_s1, v_s2);
9 dbms_output.put_line(v_count);
10 end;
11 /
0
PL/SQL procedure successfully completed
SQL>
----------
2已用时间: 00: 00: 00.03
09:36:54 scott@TUNGKONG> declare
09:37:38 2 v_count integer;
09:37:38 3 v_s1 varchar2(20);
09:37:38 4 v_s2 varchar2(20);
09:37:38 5 begin
09:37:38 6 v_s1 := 'w1';
09:37:38 7 v_s2 := 'w2';
09:37:38 8 select count(1) into v_count from t1 where c3 in (v_s1, v_s2);
09:37:38 9 dbms_output.put_line(v_count);
09:37:38 10 end;
09:37:38 11 /
2PL/SQL 过程已成功完成。已用时间: 00: 00: 00.01
名称 是否为空? 类型
----------------------------------------------------- -------- ------------------------------------
C3 CHAR(10)09:44:32 scott@TUNGKONG> select * from t1;C3
----------
w0
w1
w2已用时间: 00: 00: 00.00
09:44:36 scott@TUNGKONG> declare
09:44:48 2 v_count integer;
09:44:48 3 v_s1 t1.c3%type;
09:44:48 4 v_s2 t1.c3%type;
09:44:48 5 begin
09:44:48 6 v_s1 := 'w1';
09:44:48 7 v_s2 := 'w2';
09:44:48 8 select count(1) into v_count from t1 where c3 in (v_s1, v_s2);
09:44:48 9 dbms_output.put_line(v_count);
09:44:48 10 end;
09:44:48 11 /
2PL/SQL 过程已成功完成。已用时间: 00: 00: 00.00
09:44:49 scott@TUNGKONG> declare
09:44:55 2 v_count integer;
09:44:55 3 v_s1 varchar2(10);
09:44:55 4 v_s2 varchar2(10);
09:44:55 5 begin
09:44:55 6 v_s1 := 'w1';
09:44:55 7 v_s2 := 'w2';
09:44:55 8 select count(1) into v_count from t1 where c3 in (v_s1, v_s2);
09:44:55 9 dbms_output.put_line(v_count);
09:44:55 10 end;
09:44:55 11 /
0PL/SQL 过程已成功完成。已用时间: 00: 00: 00.00
09:46:44 2 v_count integer;
09:46:44 3 v_s1 char(10);
09:46:44 4 v_s2 char(10);
09:46:44 5 begin
09:46:44 6 v_s1 := 'w1';
09:46:44 7 v_s2 := 'w2';
09:46:44 8 select count(1) into v_count from t1 where c3 in (v_s1, v_s2);
09:46:44 9 dbms_output.put_line(v_count);
09:46:44 10 end;
09:46:44 11 /
2PL/SQL 过程已成功完成。
=====================================
主要问题在于你程序中定义的类型和表中字段类型不一致导致的.........
定义变量的时候可以使用
declare
v_s1 t1.x%type:= 'abc';
v_s2 t1.x%type:= '123';
就不会有类型上的问题