What syntax is used to SELECT a constant field value from a JavaDB database?

半城伤御伤魂 提交于 2019-12-02 03:29:32

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

The problem is that Apache Derby doesn't support

select null from test

Instead you have to cast the null to the right type:

select cast(null as varchar(255)) from test

So the query would look like:

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

You also have to remove the brackets around your column list, because that's not standard SQL syntax.

Adam Bakker

Try putting your numbers in single quotes.

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