请教-->存储过程中取变量值的问题,高手请进!

[复制链接]
查看11 | 回复6 | 2014-2-19 11:55:14 | 显示全部楼层 |阅读模式
从游标中获取表名称和字段名后, 再次将其赋给步骤B中查询的字段值.经debug发现,而其赋值结果却为:如:v_Dbowner=ZHANSAN, 则其结果为:index_owner=ZHANSAN, 由于其字段为字符型,故按此值查询为空,除非值为:index_owner='ZHANSAN' ,将其使用单引号括起来,但我在赋值语句中如何加入两边的单引号?曾尝试过多种方法,均无效.
index_owner='v_Dbowner'[ 无效]
index_owner='||v_Dbowner||'[ 无效]
index_owner="'v_Dbowner'"[ 无效]
..............
晕了,怎么在变量上加入引号呢?请教高手呀!:(...


具体代码如下:
create or replace procedure CreateIdx(ownname in varchar2) is
/******************************
* ownname: 待建立索引的用户名
*******************************/
v_Dbowner varchar2(50) := UPPER(TRIM(ownname));
v_Fields varchar2(100);
v_Tabname varchar2(255);
sql_Str varchar2(200);
v_idxnum number(10) :=0;
v_IsIndex varchar2(20) :=null;
e_error EXCEPTION;
--步骤A: 从表中获取待建立索引的表名称和字段名称
CURSOR c_Tabname is
select t1.tablename,t.enname
from gasys.ga_data_field_alias t,gasys.ga_data_basic t1
where t.usedinquery=1 and (t.layerid=t1.layer_id and t1.isquerylayer='Y' and t1.owner=v_Dbowner);
--Create Index
begin
OPEN c_Tabname;
LOOP
FETCH c_Tabname INTO v_Tabname,v_Fields;
If v_Tabname is not null then
--步骤B: 从系统表中查询这些表是否已经存在索引,

select index_name into v_IsIndex from all_ind_columns where index_owner=v_Dbowner and Table_name=v_Tabname and column_name =v_fields;
--如果存在索引,则删除
drop index .....
......
回复

使用道具 举报

千问 | 2014-2-19 11:55:14 | 显示全部楼层
一个单引号->''''
'zhangsan'->'''zhangsan'''
it's an apple->'it''s an apple'
回复

使用道具 举报

千问 | 2014-2-19 11:55:14 | 显示全部楼层
index_owner='||v_Dbowner||' [ 无效]
->index_owner=''''||v_Dbowner||''''
回复

使用道具 举报

千问 | 2014-2-19 11:55:14 | 显示全部楼层
还是不行. Debug发现一到 select index_name into v_IsIndex from all_ind_columns where index_owner=v_Dbowner and Table_name=v_Tabname and column_name =v_fields;
这行就跳到exception这里了.检查也没有发现有什么问题呀?!!

....
回复

使用道具 举报

千问 | 2014-2-19 11:55:14 | 显示全部楼层
1、把If v_Tabname is not null then
改成 if c_Tabname%found
2、千万不要加什么引号
回复

使用道具 举报

千问 | 2014-2-19 11:55:14 | 显示全部楼层
少写了一个then,应该是if c_Tabname%found then
回复

使用道具 举报

千问 | 2014-2-19 11:55:14 | 显示全部楼层
chr(39)||' '||chr(39)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行