當前位置:首頁 » 存儲配置 » oracle存儲過程動態表名

oracle存儲過程動態表名

發布時間: 2022-03-30 15:37:13

『壹』 想用oracle的存儲過程動態建表

建立序列:
create sequence t_id
increment by 1
start with 1
nomaxvalue
cache 20;
建立自動建表過程:
create or replace procere pro_createtable(tname in varchar2 default to_char(sysdate,'yyyymm'))
as
v_sql varchar2(200);
v_tname varchar2(10);
begin
if length(tname)<>6 then
raise_application_error(-20000,'輸入參數長度不夠,不能轉換為日期格式!');
end if ;
if to_number(substr(tname,5,2)) not between 1 and 12 then
raise_application_error(-20001,'輸入參數中不包含有效的月份數字,不能轉換為日期格式!');
end if ;
--v_tname:=to_char(to_date(tname,'yyyymm'),'yyyymm');
v_tname:='hd_'||tname;
v_sql:='create table '||v_tname||' ('||
'id number not null,'||
'name varchar2(20),'||
'city varchar2(20))'||
'tablespace users';
execute immediate v_sql;
end;
測試:
begin
pro_createtable;
pro_createtable('201106');
pro_createtable('201115');--報錯
end;

『貳』 oracle動態表名查詢 如何寫sql語句或者存儲過程實現: 根據某張表中的某個欄位的值決定查詢哪一張表

begin
for cur in(select id,flag fromu a)
loop
if cur.flag=0 then
select * from b;
...
else
select * from C;
...
end if;
end loop;
end;

『叄』 ORACLE 存儲過程如何實現動態建表或者是觸發器

需求沒說清楚,你說建立的新表有什麼需求?什麼叫每插入一條記錄都會自動添加匹配的其他三表的欄位值? 你在新表插數據和舊表有什麼關系?新表的欄位不是你自己定義的?去和什麼匹配

『肆』 oracle存儲過程中查詢動態表名

先建立結果表,也就是存放你最終結果的表

createtabletest
(avarchar2(100),
bvarchar2(100));

然後建立存儲過程

createprocerep_insert
as
cursorcur_tbnameis
select'insertintotestselectcol1,col2from'||table_name
fromuser_tableswheretable_namelike'AA____BB';--這個位置的表名必須大寫的A和B,col1和col2換成你實際的欄位名稱
begin
opencur_tbname;
loop
fetchcur_tbnameintov_sql;
exitwhencur_tbname%notfound;
executeimmediatev_sql;
commit;
endloop;
end;

我最終沒測試,你自己測試一下,看哪有問題吧

『伍』 oracle存儲過程中動態建表

把後面的結束符去掉,如下
execute immediate 'create table fsn0831 as select prodid from fsng.pc_prod_service where 1=2';

『陸』 oracle存儲過程動態建表

需要用到動態sql。

1、首先要給用戶賦予許可權:

grantcreateanytableto用戶名;

2、創建存儲過程:

createprocerep_create_table
(v_sqlvarchar2)--輸入建表語句
as
begin
executeimmediatev_sql;
end;

3、執行:

『柒』 Oracle存儲過程中如何把表名寫在變數裡面進行查詢該表

大概這樣
create or replace procere p_XX(tabName in varchar2) is
type t_cursor is ref cursor;
v_cursor t_cursor;
v_SQLStatement varchar2(300);

begin
v_SQLStatement = 'select xx from '||tabName ;
open v_cursor for v_SQLStatement;
loop fetch v_cursor into XXX;
exit when v_cursor%notfound;
--做你的操作
end loop; close v_cursor;
end;

『捌』 在 oracle 的存儲過程中 如何聲明一個動態表的記錄型變數

你只能在存儲過程中使用動態的匿名塊了。

比如:

createorreplaceprocerepro1(p_tnamevarchar2)is
v_dy_sql_blockvarchar2(32767);
begin
v_dy_sql_block:='declare'||
'l_row'||p_tname||'%rowtype;'||
'....';
executeimmediatev_dy_sql_block;
end;

『玖』 oracle 的存儲過程中 動態的創建一張表 然後插入一個變數到這個表中,表能動態的創建但是變數不能插入進去

1、execute immediate ' insert into addtopinfo values('||sysdate||','||v_name||')'; v_name 既然是變數 怎麼可能會用' '括弧起來;
就算是 直接執行 的話 也是 execute immediate ' insert into addtopinfo values(sysdate,v_name);
2、如果有v_name的話 ,我建議你一般用拼sql的方式來執行
例如 如下格式(這個是我自己的procere截取的,可以參考下)
v_CreateSql := ' create table ' ||vv_owner||'.'|| vv_name_temp ||
' as select * from ' || iv_name || ' where 1=0';

execute immediate v_CreateSql;

3、下次報錯,請把你的出錯情況提出來。我們怎麼知道什麼錯呢?

熱點內容
sql表添加記錄 發布:2025-02-01 11:22:08 瀏覽:864
word編輯加密 發布:2025-02-01 11:18:53 瀏覽:571
php變數文本 發布:2025-02-01 11:10:46 瀏覽:426
音悅台上傳mv 發布:2025-02-01 11:05:02 瀏覽:516
微信如何設置訪問限制 發布:2025-02-01 10:43:06 瀏覽:335
b站緩存視頻下架還有嗎 發布:2025-02-01 10:37:52 瀏覽:940
e卡通初始密碼是多少 發布:2025-02-01 10:31:55 瀏覽:127
phppost上傳文件 發布:2025-02-01 10:26:42 瀏覽:105
伺服器不能寫入ip地址 發布:2025-02-01 10:18:56 瀏覽:129
青驕如何重置賬號密碼 發布:2025-02-01 09:57:51 瀏覽:520