读书人

PL SQL中怎么使用变量作为修改语句中的

发布时间: 2012-01-01 23:10:55 作者: rapoo

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 || ' ' ' '

读书人网 >oracle

热点推荐