日期:2014-05-17  浏览次数:20838 次

PL SQL中如何使用变量作为修改语句中的列名?
declare        
lv_month     :=     '07 '    
update     table     set     zzs¦¦lv_month= '111111 '    

lv_month   是变量
 
为什么执行老是错误啊,我想实现的语句是    
update     table     set     zzs07= '111111 '

------解决方案--------------------
declare
lv_month varchar2(10) := '07 ';
lv_zzs varchar2(10) := '1111 ';
begin
dbms_output.put_line( 'update table set zzs ' || lv_month || '= ' ' '||lv_zzs|| ' ' ' ' );
end;
------解决方案--------------------
||是字符串的连接符
' '中的内容表示文字
如果字符串中需要有[ ']怎么办呢?就用[ ' ']来表示
所以
update table set zzs07 = '256 '

=> > >

[update table set zzs] + [07] + [= '] + [256] + [ ']

在将[]中的 '替换成 ' ' => > >

[update table set zzs] + [07] + [= ' '] + [256] + [ ' ']

将[]替换成 ' ',将+替换成|| => > >

'update table set zzs ' || [07] || '= ' ' ' || [256] || ' ' ' '
'update table set zzs ' || lv_month || '= ' ' ' || lv_zzs || ' ' ' '