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;
  • 相关阅读:
    D. Renting Bikes 二分
    Maximum Absurdity DP + 数学
    模拟 H
    Secrets 数论
    A. Knight Tournament SET的应用
    B. Xenia and Hamming Codeforces 256B GCD,LCM处理字符串
    Alternate Task UVA11728 暴力枚举
    GCD Extreme (II) 欧拉函数的应用
    Bit Magic HDU 4421 2-Sat
    Encoding http://acm.hdu.edu.cn/showproblem.php?pid=1020
  • 原文地址:https://www.cnblogs.com/davidgu/p/1752601.html
Copyright © 2011-2022 走看看