在 Sybase ASE 中更新插入(更新或插入)?
我正在编写一个应用程序,将数据从 Oracle 移动到 Sybase,并且需要执行更新/插入操作。在 Oracle 中,我会使用 MERGE INTO,但它似乎在 Sybase 中不可用(无论如何,在 ASE 中也不可用)。我知道这可以通过多个语句来完成,但出于几个原因,我真的试图将其放入单个语句中。
有什么建议吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
也许它可以起作用。在 ASA9 中测试。
Maybe it could work. Tested in ASA9.
也许您可以尝试使用 INSERT INTO 和/或 UPDATE FROM 以及一些子查询来伪造它,但它不会像 Oracle 那样方便。
您想将其写入代码或数据仓库吗?因为如果您想隐藏查询的复杂性,您还可以将所有 SQL 封装到存储过程中。
May be you could try to fake it with INSERT INTO and/or UPDATE FROM with some sub-queries but it will not be as convenient as Oracle does.
You wanna do this into code or data warehouse ? because you could also encapsulate all the SQL into a stored procedure if you want to hide the complexity of the queries.
ASE 15.7 具有此功能。
在此处查找文档:
http://infocenter. sybase.com/help/topic/com.sybase.infocenter.dc36272.1570/html/commands/commands84.htm
ASE 15.7 has this feature.
Find the docs here:
http://infocenter.sybase.com/help/topic/com.sybase.infocenter.dc36272.1570/html/commands/commands84.htm
Sybase 和 DB2 非常符合 IEC/ISO/ANSI SQL 标准。 MS 稍微差一些。
Oracle 根本不符合标准(尽管注释上是这么说的)。更重要的是,由于它的局限性,他们用来克服它们的方法是引入 SQL 扩展(其他 DBMS 不需要这些扩展,因为其他 DBMS 没有这些限制)。确保客户不会迁移的好方法。
因此,对您来说最好的建议是学习 SQL 标准方法来完成您在 Oracle 方面所做的任何事情。其次(不是首先)了解 Sybase 或 DB2(或其他)扩展。
SQL中不存在“MERGE”和“UPSERT”,它们仅存在于Oracle中。最重要的是,您必须在两个单独的操作中进行更新和插入。
在SQL中,UPDATE和INSERT适用于单个表;您可能有相当复杂的 FROM 子句。
对于“MERGE”,这只是一个:
更新只是补充:
在 UPDATE 中,很容易合并 WHERE 条件并消除子查询(我向您展示它以供解释)。
据我了解,Oracle 在执行子查询(标准 SQL)方面非常糟糕。这就是为什么他们有所有这些非标准的“MERGE”等,其目的是避免标准子查询语法,而其他 DBMS 都可以轻松执行。
Sybase and DB2 are very IEC/ISO/ANSI SQL Standrd-compliant. MS a little less so.
Oracle is not very Standard-compliant at all (despite what the glossies say). More important, due to it limitations, the method they use to overcome them is to introduce Extensions to SQL (which are not required for the others DBMS, which do not have the limitations). Nice way of making sure that customers do not migrate away.
So the best advice for you is to learn the SQL Standard way of doing whatever you were doing on the Oracle side. And second (not first) learn about Sybases or DB2s (or whatever) Extensions.
"MERGE" and "UPSERT" do not exist in SQL, they exist in Oracle only. The bottom line is, you have to UPDATE and INSERT in two separate operations.
In SQL, UPDATE and INSERT apply to a single table; you may have quite complex FROM clauses.
For "MERGE", that is simply an:
Update is simply the complement:
In the UPDATE it is easy to merge the WHERE conditions and eliminate the Subquery (I am showing it to you for explanation).
As I understand it, Oracle is abyssmal at executing Subqueries (Standard SQL). Which is why they have all these non-Standard "MERGE", etc., the purpose of which is to avoid the Standard Subquery syntax, which every other DBMS performs with ease.
不幸的是,如果不使用 MERGE,就不可能在一条语句中插入和更新表。顺便说一句,根据这篇文章,从 SQL:2008 开始,SQL 中确实存在,并且几乎所有主要数据库都支持,除了 Sybase ASE 和 PostgreSQL。
unfortunately, it is impossible to insert and update a table in one statement without using MERGE. which btw does exist in SQL as of SQL:2008, according to this article anyway, and supported by almost all major databases, except Sybase ASE and PostgreSQL.
合并存在于 SAP ASE 15.7 及以上版本中,如上所述 此处 和 此处
替换/更新存在于SAP ASE 16.0 及更高版本。
您需要更新才能访问它们。
Merge exists in SAP ASE 15.7 upwards, as mentioned here and here
Replace / Upsert exists in SAP ASE 16.0 and up.
You'll need to update to access them.