我有以下代码:(伪代码)
Select id, name, code, address from users
我json对数据库中的数据进行编码,如下所示:
{"id":"228","name":"Jimmy","code":"12345","address":"abc street"}, {"id":"229","name":"John","code":"22345","address":"10 1st street"}
但我实际上需要数据看起来像这样:
{"id":"228","name":"Jimmy","code":"12345","address":"abc street", "DT_RowId": "row_228"}, {"id":"229","name":"John","code":"22345","address":"10 1st street","DT_RowId": "row_229"}
其中DT_RowId是具有记录ID的字段,前缀为文本" row _"。 有没有办法强制sql语句将其作为结果集的一部分包含在内? 这可能不是最好的方式......但问题突然出现在我脑海中,所以现在我很好奇。
答案 0 :(得分:1)
当然,只需使用串联运算符||
和字符串文字:
Select
id,
'row_' || id as DT_RowId,
name,
code,
address
from users