select ''''||'aa'||'''' from dual
'a'
单引号用2个单引号代替
select pid, colnum, 'a' || colnum || ''''=
(select t1.value from table1 t1
where substr(''''||to_char(pid)||'''',1,length(''''||to_char(pid)||'''')-2))
'a'
单引号用2个单引号代替
select pid, colnum, 'a' || colnum || ''''=
(select t1.value from table1 t1
where substr(''''||to_char(pid)||'''',1,length(''''||to_char(pid)||'''')-2))
(select t1.value from table1 t1
where substr('''||to_char(pid)||''',1,length('''||to_char(pid)||''')-2))
= upper(t1.id) ),' as v_str …………这个应该对:
分析过程:
你想要以下结果(???我代表要用变量替代的)
a???=( (select t1.value from table1 t1
where substr('???',1,length('???')-2))
= upper(t1.id) ),).......
然后,你先这样
'
a???=( (select t1.value from table1 t1
where substr('???',1,length('???')-2))
= upper(t1.id) ),).......
'
然后,这样,把里面的引号变为俩单引号;
'
a???=( (select t1.value from table1 t1
where substr(''???'',1,length(''???'')-2))
= upper(t1.id) ),).......
'
最后,把变动的替换
'
a'||columnname||'=( (select t1.value from table1 t1
where substr('''||columnname||''',1,length('''||columnname||''')-2))
= upper(t1.id) ),).......
'ok ?
但是我在|| || 之间是 aa,不是'aa',系统不认为我取得的是个字符串,而认为是变量
你的方法我测试了一下:结果是我想要的,谢谢!你说的 where substr('''||columnname||''',1,length('''||columnname||''')-2))
= upper(t1.id) ),).......columnname 要换成我前面代码里的pid,但是方法正确我最终测试输出结果——a1=(select t1.value from cd.energydaysum t1 where
'SL02',1,length('SL02')-2)) = upper(t1.id) and 0 = t1.TYPE and 200506070000 = time )