日期:2014-05-17  浏览次数:20894 次

oracle 中表名的连接
有个问题。ORACLE中,有一个表imei_imeicount_201101。我想将其拆分为“imei_imeicount_”和“201101”两个字符串组成一张表。怎么弄呀?

------解决方案--------------------
SQL code

declare
    str_tabprefix         varchar2(30);
    str_tabsuffix         varchar2(30);
    str_tabname           varchar2(30);
    int_exists            number;
begin
    str_tabprefix := 'imei_imeicount_';
    str_tabsuffix := to_char(sysdate, 'yyyymm');
    str_tabname := str_tabprefix || str_tabsuffix;
    
    select count(*) into int_exists from tabs where table_name = upper(str_tabname);
    if (int_exists = 0) then
        execute immediate 'create table ' || str_tabname || '(text  varchar2(200))';
    end if;
end;