在具有不同身份验证的 DB2 数据库之间复制表
你好 StackOverflow 社区,
我的问题如下: 我有一个表,例如 USER_ADDR
,在一个数据库中包含一堆列,例如 DB001
我需要将此表的内容(基于条件)复制到另一个数据库 DB002
中具有不同 userID 和 pwd 的类似表 USER_ADDR
(相同名称,是的) 。
我需要在将使用 .net 框架执行的存储过程中执行此操作。 我试过这个:
INSERT INTO "DB002".USER_ADDR (--column names--)
SELECT *
FROM "DB001".USER_ADDR
WHERE ID = "APPLICATION_NO_IN";
我得到:
0:发生错误:[IBM][DB2/NT64] SQL0204N“DB002.USER_ADDR”是未定义的名称。行号=15。 SQLSTATE=42704 : -204: IBM.Data.DB2: 42704
我做错了什么?
提前致谢 瓦西斯特
Hey StackOverflow community,
My question is as follows:
I have a table, say USER_ADDR
with a bunch of columns in one database, say DB001
I need to copy the contents of this table(based on a criteria) to a similar table USER_ADDR
(same name, yes) in another database DB002
with a different userID and pwd.
I need to do this in a stored procedure that will be executed using a .net framework.
I tried this:
INSERT INTO "DB002".USER_ADDR (--column names--)
SELECT *
FROM "DB001".USER_ADDR
WHERE ID = "APPLICATION_NO_IN";
I get:
0: Error occurred: [IBM][DB2/NT64] SQL0204N "DB002.USER_ADDR" is an undefined name. LINE NUMBER=15. SQLSTATE=42704 : -204: IBM.Data.DB2: 42704
What am I doing wrong?
Thanks in advance
Vashist
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在看到有关您的用例的附加信息后,我将删除我的其他答案。加载主要针对大量记录的批量加载。
在这种情况下,我建议您执行类似在.Net 中打开连接到数据源的connection1 的操作,选择数据并将其保存在.Net
DataTable
中。如果需要,您可以在存储过程中进行选择,该存储过程返回单行的各个列值或返回包含所有列(和行)的游标(行集)。然后在.Net中打开connection2并将数据从DataTable插入到您的目的地。同样,这可以通过存储过程来完成。i'm deleting my other answer after seeing the additional info about your use case. Load is mainly for bulk loads of large numbers of records.
in this case i'd recommend you do something like open connection1 in .Net to your data source, select the data and hold it in a .Net
DataTable
. If required, you can do that select in a stored proc that returns either individual column values for a single row or return a cursor (rowset) that contains all the columns (and rows). Then in .Net open connection2 and insert the data from the DataTable to your destination. Again, that can be done with a stored proc.另一种方法是使用连接到两个数据库的外部脚本。
仅使用一个数据库是不可能的,正如已经提到的,至少您使用信息集成(联合)或通过导出数据然后加载它。
Another approach is using an external script that connects to both databases.
From just one database is not possible, at least you use, as already mentioned, Information integration (federation) or by exporting the data and then loading it.