使用什么语法从JavaDB数据库中选择常量字段值? [英] What syntax is used to SELECT a constant field value from a JavaDB database?

查看:162
本文介绍了使用什么语法从JavaDB数据库中选择常量字段值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用UNION ALL将几个SELECT查询的结果合并为一个ResultSet.我使用常量字段值来标识产生每一行的语句.这在MySQL上很好用,但是Java DB抛出SQLSyntaxErrorException,指向第一个常量字段值后面的逗号.

I'm using UNION ALL to combine the results of several SELECT queries into one ResultSet. I use constant field values to identify which statement produced each row. This works well with MySQL, but Java DB is throwing SQLSyntaxErrorException, pointing at the comma after the first constant field value.

在JavaDB数据库查询中,使用什么语法选择常量字段值 SELECT ?

第一个SELECT包含约100列具有不同数据类型的列,随后的SELECT被填充以匹配正确的列数.在此处.当前的语句如下所示:

The first SELECT has ~100 columns with varying data types, and the following SELECTs are padded to match the correct number of columns. I've it here. The statements currently look like this:

select
    (0, ID, NAME_FIRST, NAME_LAST)
from person 
where ID=500
union all
select 
    (1, COMMTYPE_ID, NULL, NULL)
from person_commtype 
where PERSON_ID=500

哪个抛出以下异常:

java.sql.SQLSyntaxErrorException: Syntax error: Encountered "," at line 2, column 7.

我还尝试过强制转换值,并删除括号,如下所示:

I have also tried casting the value, and removing the parentheses, like so:

select
    (cast(0 as integer), ID, NAME_FIRST, NAME_LAST)
from person 
where ID=500

select
    0, ID, NAME_FIRST, NAME_LAST
from person
where ID=500

推荐答案

SELECT子句中的字段列表周围删除方括号.

Remove the brackets from around your list of fields in the SELECT clause.

select
    0, ID, NAME_FIRST, NAME_LAST
from person 
where ID=500
union all
select 
    1, COMMTYPE_ID, NULL, NULL
from person_commtype 
where PERSON_ID=500

这篇关于使用什么语法从JavaDB数据库中选择常量字段值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆