Oracle中存储过程不可以执行DDL语句,但是我们可以利用动态sql语句来建立表格。

如下:

 

代码
create or replace procedure spCreateTestTable
is
    v_CreateString 
varchar2(1000);
begin
    
declare
        v_count 
number;
    
begin
        v_count :
= 0;
        
        
select count(*)
        
into v_count
        
from tab
        
where tname='TEST_TABLE';
        
        
if v_count=1 then
            dbms_output.put_line(
'test table already exists');
            v_CreateString :
= 'drop table test_table';
            
execute immediate v_CreateString;
            
commit;
        
else
            dbms_output.put_line(
'test table created');
        
end if;
        
        v_CreateString :
= 'create table test_table(' ||
                                                
'aa varchar2(5), ' ||
                                                
'bb varchar2(5))';
        
execute immediate v_CreateString;
        
commit;
    exception
   
when others
   
then
        
rollback;
   
end;
end;

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-27
  • 2021-07-28
  • 2021-05-21
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-19
  • 2022-12-23
  • 2021-09-24
  • 2022-12-23
相关资源
相似解决方案