首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ORA-00997:非法使用长数据类型

ORA-00997:非法使用长数据类型
EN

Stack Overflow用户
提问于 2022-08-24 07:55:43
回答 2查看 102关注 0票数 0

我知道有很多类似的问题,但我的问题有点不同。

我正在尝试执行一个存储过程,将数据从MsSQL迁移到Oracle,而在这个特定的表上,数据类型是MsSQL上的varchar(2000)和Oracle上的nvarchar2(2000)。我使用TO_LOB()修复了错误

ORA-00932:不一致的数据类型:期望CHAR变长

因为我发现很多人用它作为解决方案。但随后我遇到了这个错误,许多人建议使用TO_LOB()作为解决方案,但事实并非如此。

我不是Oracle的熟练或有经验的用户,我的知识也很少。下面是我用来创建这个过程的代码示例。

代码语言:javascript
复制
CREATE OR REPLACE PROCEDURE default_proc
IS
BEGIN
   EXECUTE IMMEDIATE 'TRUNCATE TABLE default_table';
   INSERT INTO default_table (data1, data2, data3, data4)
   SELECT data1, TO_LOB(data2) data2, data3, data4
   FROM default.table@dblink
EXCEPTION
WHEN OTHERS THEN
   DBMS_OUTPUT.PUT_LINE('ERROR IS : ' || SQLCODE || ' : ' || SQLERRM);
END default_proc;
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-08-25 05:34:26

我找到了一个解决方案,其实很简单。把它放在一个循环里!

代码语言:javascript
复制
CREATE OR REPLACE PROCEDURE default_proc
IS
BEGIN
   EXECUTE IMMEDIATE 'TRUNCATE TABLE default_table';
   FOR n IN (SELECT data1, data2, data3, data4
    FROM default.table@dblink)
    LOOP
        INSERT INTO default_table (data1, data2, data3, data4)
        VALUES (n.data1, n.data2, n.data3, n.data4);
    END LOOP;
EXCEPTION
WHEN OTHERS THEN
   DBMS_OUTPUT.PUT_LINE('ERROR IS : ' || SQLCODE || ' : ' || SQLERRM);
END default_proc;
票数 0
EN

Stack Overflow用户

发布于 2022-08-24 10:04:21

尝试使用to_clob(),它在下面的示例中工作..。

代码语言:javascript
复制
create table test (col varchar2(2000));

 insert into test
   select to_clob('I agree with that, unfortunately many sites are blocked, like message boards and forum/blog sites/etc. Im actually looking first at asktom and this forum before I proceed with google. Which actually points me to the TO_LOB function, which in our environment throws an error message shown above.Follow up question: This TO_LOB function looks simple and easy to use but as shown above in my post it throws an error message. Have I missed something or is there something in our environment that affected the behavior of this function?') from dual union all
   select to_clob('I agree with that, unfortunately many sites are blocked, like message boards and forum/blog sites/etc. Im actually looking first at asktom and this forum before I proceed with google. Which actually points me to the TO_LOB function, which in our environment throws an error message shown above.Follow up question: This TO_LOB function looks simple and easy to use but as shown above in my post it throws an error message. Have I missed something or is there something in our environment that affected the behavior of this function?')    from dual;
   
   
   select * from test;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73469424

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档