软件开发数据库GBase 8t

gbase8t有没有select as语句

有没有类似于“select(1,2,3) as source(id, line, row)”的语句,其中source不是表名,id、line、和row也是起的别名,为了方便后续通过source.id,source.line,source.row取值。

在merge into的时候需要用到。

参与17

4同行回答

faleorfaleor数据库管理员GBase
merge into targetusing (select 1, 25, 'XiaoLi' from systables where tabid=1) as source(id, age, name)on target.id=source.idwhen matched thenupdate set target.id=source.id, target.age=source.age, target.name=source.namewhen not matched theninsert (tar...显示全部

merge into target

using (select 1, 25, 'XiaoLi' from systables where tabid=1) as source(id, age, name)

on target.id=source.id

when matched then

update set target.id=source.id, target.age=source.age, target.name=source.name

when not matched then

insert (target.id, target.age, target.name) values(source.id, source.age, source.name);

收起
金融其它 · 2016-04-25
  • 哇,大神!果然是这样的。我还有个问题能问问吗,如果1,25,‘XiaoLi’这三个值待确定,也就是我要用prepareStatement来赋值,这三个值都暂时用问号“?”来代替,为何会报语法错误?
    2016-04-25
  • 你的一句大神极大的满足了我的虚荣心,我决定再回答你一次,按我的理解prepareStatement应该不是这样用的,用变量替换这几个常量不行吗?
    2016-04-25
  • 忙了一天,抱歉没有及时回复.prepareStatement就是用?代替sql中待定的变量,然后再通过参数赋值给每一个?赋值.
    2016-04-26
  • liaosnet  liaosnet回复 faleor
    刘大神~~prepare statement在java里常用到。理论上也应该可以,应该是动态sql的范围。
    2016-04-29
  • faleor  faleor回复 liaosnet
    按我的理解,?只能代替不影响执行计划的具体变量值,而不能代替字段名或表名,因为如果字段名都没有定义的话,是没法解析的,他那里报语法错误肯定也是因为?没有替换成他想要的值
    2016-04-29
  • liaosnet  liaosnet回复 faleor
    应该是要在动态sql中使用,而不是用 ? 代替。。
    2016-04-30
spiderliujiespiderliujie软件架构设计师GBase
表sale为目标表,new_sale为来源表,通过cust_id对比两个表的数据,当sale表有与new_sale相同的记录时,执行update更新sale表的salecount属性,当sale表中没有new_sale中相应的记录,则把该记录insert 到sale表中 MERGE INTO sale USING new_sale AS nON sale.cust_id = n.cust_idWH...显示全部
表sale为目标表,new_sale为来源表,通过cust_id对比两个表的数据,当sale表有与new_sale相同的记录时,执行update更新sale表的salecount属性,当sale表中没有new_sale中相应的记录,则把该记录insert 到sale表中



MERGE INTO sale USING new_sale AS n
ON sale.cust_id = n.cust_id
WHEN MATCHED THEN UPDATE
SET sale.salecount = sale.salecount + n.salecount
WHEN NOT MATCHED THEN INSERT (cust_id, salecount)
VALUES (n.cust_id, n.salecount);收起
互联网服务 · 2016-04-25
浏览771
nilainilainilainilainilainilai软件开发工程师你来
例如:create table target(id int, age int, name char(10));merge into targetusing (select 1, 25, 'XiaoLi') as source(id, age, name)on target.id=source.idwhen matched thenupdate set target.id=source.id, targe.age=source.age, target.name=source.namewhen n...显示全部

例如:create table target(id int, age int, name char(10));

merge into target

using (select 1, 25, 'XiaoLi') as source(id, age, name)

on target.id=source.id

when matched then

update set target.id=source.id, targe.age=source.age, target.name=source.name

when not matched then

insert (target.id, target.age, target.name) values(source.id, source.age, source.name);

问题:红色标注的语句是模仿mssql写的,但对于GBase8t应该是错的,这块应该怎么写才对?

source不是一张实际存在的表,只是任意起的一个名字,id,age和name也是起的别名,只是为了方便通过source.id,source.age,source.name来取得1,25,‘XiaoLi’这几个值。

收起
软件开发 · 2016-04-25
浏览802
spiderliujiespiderliujie软件架构设计师GBase
根据我的调查,目前应该不支持该语法显示全部
根据我的调查,目前应该不支持该语法收起
互联网服务 · 2016-04-25
浏览805
  • 那我用什么方法可以达到我的目的
    2016-04-25
  • 例如:create table target(id int, age int, name char(10)); merge into target using (select 1, 25, 'XiaoLi') as source(id, age, name) on target.id=source.id when matched then update set target.id=source.id, targe.age=source.age, target.name=source.name when not matched then insert (target.id, target.age, target.name) values(source.id, source.age, source.name); using后面的语句是模仿mssql写的,但对于GBase8t应该是错的,这块应该怎么写才对? source不是一张实际存在的表,只是任意起的一个名字,id,age和name也是起的别名,只是为了方便通过source.id,source.age,source.name来取得1,25,‘XiaoLi’这几个值。
    2016-04-25

提问者

nilainilainilai
软件开发工程师你来
擅长领域: 数据库GBase 8t国产数据库

相关问题

相关资料

相关文章

问题状态

  • 发布时间:2016-04-22
  • 关注会员:3 人
  • 问题浏览:3521
  • 最近回答:2016-04-25
  • X社区推广