oracle 如何使用dblink删除表

hpxqektj  于 2023-06-22  发布在  Oracle
关注(0)|答案(1)|浏览(169)

如果Oracle中存在表,如何使用dbLink删除表?我在这里试图连接到远程数据库使用DBLink在oracle.我使用oracle sql开发.
DROP TABLE TableName@dbLinkName .这给我错误未知的命令.

begin declare
    v_mytableobject_id
        NUMBER(10);
SELECT
    object_id INTO v_mytableobject_id FROM    user_objects@dblink
WHERE
    object_name = 'MYTABLE';

IF v_mytableobject_id IS NOT NULL THEN
    dbms_utility.exec_ddl_statement@dblink ( 'drop table MYTABLE' );
ELSE
    dbms_utility.exec_ddl_statement@dblink ( 'CREATE TABLE MYTABLE
   (ID NUMBER(5,0) GENERATED ALWAYS AS IDENTITY MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER  NOCYCLE  NOKEEP  NOSCALE , 
    CODE NVARCHAR2(15), 
    DESCRIPTION NVARCHAR2(125)
    
   )'
    );
    dbms_utility.exec_ddl_statement@dblink ( 'CREATE UNIQUE INDEX MYTABLE_PK ON MYTABLE (ID) 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)'
    );
END IF;

end;
tzdcorbm

tzdcorbm1#

你不能就这样把table放下:

SQL> drop table test@dbl_mike;
drop table test@dbl_mike
                *
ERROR at line 1:
ORA-02021: DDL operations are not allowed on a remote database

不过,有一个解决方案:

SQL> begin
  2    dbms_utility.exec_ddl_statement@dbl_mike('drop table test');
  3  end;
  4  /

PL/SQL procedure successfully completed.

SQL>

相关问题