批量生成sql查询语句

匿名 (未验证) 提交于 2019-12-02 23:47:01

Teradata中用单引号表示“值”,双引号表示“字段名”,若要插入带有单引号的记录,需要将单引号改为两个单引号

因此Teradata中批量生成查询语句可这样写。

表A:

ID CLASS SEX AGE
1 1 0 12
2 1 0 12
3 2 1 13

select distinct 'select ''class1'',id,sex,age from a where class = '''||class||''';'

结果:

select class1,id,sex,age from a where class = '1';

select class1,id,sex,age from a where class = '2';

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!