zoukankan      html  css  js  c++  java
  • Oracle中利用存储过程建表

    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;
  • 相关阅读:
    select * from a,b探讨
    使用python脚本从数据库导出数据到excel
    git入门
    登录远程服务器脚本
    Ubuntu下python开发环境搭建
    asyncio并发编程
    深入理解python协程
    单例模式的几种实现方式
    MySQL统计百分比结果
    Java查询MySQL数据库指定数据库中所有表名、字段名、字段类型、字段长度、字段描述
  • 原文地址:https://www.cnblogs.com/davidgu/p/1752601.html
Copyright © 2011-2022 走看看