Oracle 如何使用动态sql分配变量

Oracle 如何使用动态sql分配变量,oracle,variables,dynamic-sql,Oracle,Variables,Dynamic Sql,我需要使用动态sql分配两个变量stmp_x和tmp_y,因为我需要在运行时选择正确的表。sql语句如下所示: updateSql:= 'select p.gis_x,p.gis_y into tmp_x,tmp_y from publish_' ||splitCollection(indexs).city_no ||'.t_customer p where p.customer_id=:1 and p.gis_x is not null

我需要使用动态sql分配两个变量stmp_x和tmp_y,因为我需要在运行时选择正确的表。sql语句如下所示:

 updateSql:= 'select p.gis_x,p.gis_y into tmp_x,tmp_y from  publish_'
             ||splitCollection(indexs).city_no ||'.t_customer p 
             where p.customer_id=:1 and p.gis_x is not null and p.gis_y is not null';

 execute immediate updateSql using splitCollection(indexs).CUSTOMER_ID;

编译还可以,但是出现了关于缺少关键字的运行时错误,我如何修复它?

因此,下面是注释:

这:

需要成为:

 updateSql:= 'select p.gis_x,p.gis_y from  publish_'
             ||splitCollection(indexs).city_no ||'.t_customer p 
             where p.customer_id=:1 and p.gis_x is not null and p.gis_y is not null';

 execute immediate updateSql using splitCollection(indexs).CUSTOMER_ID RETURNING into tmp_x,tmp_y;
区别在于into子句,当与execute immediate一起使用时,into子句应该放在实际语句中,而不是Select语句的一部分


干杯

我的车坏了,请告诉我如何使它工作。你看到这个请求的问题了吗?和你问问题的方式类似吗?它怎么不起作用?发生了什么-是否出现编译错误?运行时错误?它运行但没有输出,还是输出错误?@mathguy很抱歉我的英语不好,编译还可以,运行时错误是缺少中文关键字,我不知道我对itOK的翻译是否正确,因此代码中生成的SQL SELECT语句似乎是无效的SQL查询。不要立即执行,而是使用DBMS_OUTPUT.PUT_LINEupdateSql将语句导出为文本,并检查它和/或尝试运行它。你也会犯同样的错误吗?在这里发布确切的字符串updateSql以获得更多帮助。我认为您只是缺少returning into子句。将其从select语句中删除到tmp_x,tmp_y中,并按如下方式添加:使用splitcollectionindex.CUSTOMER_ID在tmp_x,tmp_y;中执行即时更新SQL@g00dy谢谢它解决了我的问题
 updateSql:= 'select p.gis_x,p.gis_y from  publish_'
             ||splitCollection(indexs).city_no ||'.t_customer p 
             where p.customer_id=:1 and p.gis_x is not null and p.gis_y is not null';

 execute immediate updateSql using splitCollection(indexs).CUSTOMER_ID RETURNING into tmp_x,tmp_y;