0
的程序我寫了這個代碼,它工作正常:創建光標作爲參數
declare
cursor c_emp is
select last_name, first_name from employees;
type c_list is table of employees.last_name%type index by binary_integer;
type c_list2 is table of employees.first_name%type index by binary_integer;
last_list c_list;
first_list c_list2;
counter integer := 0;
begin
for i in c_emp loop
counter := counter + 1;
last_list(counter) := i.last_name;
first_list(counter) := i.first_name;
dbms_output.put_line('Employee(' || counter || '): ' || last_list(counter) || ' ' || first_list(counter));
end loop;
end;
/
這一次,我想使程序與我可以插入表名和列入遊標參數。我試過這個:
create or replace procedure show_data(tab_name in varchar2, data_list in varchar2)
is
str varchar2(100);
str2 varchar2(100);
column_name varchar2(100);
begin
str := 'select ' || data_list || ' from ' || tab_name;
for vRec in str loop
dbms_output.put_line(str);
end loop;
end;
/
它給出了一個錯誤,其中str不是遊標。我不確定如果光標可以用這種方式完成,但是從它看起來不可能的錯誤。
我的代碼哪部分是錯的,還是因爲我沒有聲明我的遊標?但是,如果我聲明我的遊標,我不能通過使用動態SQL方式獲取參數。
嗨vmachan,非常感謝你的回覆。我更改了一些代碼,因爲缺少分號。最後我可以成功編譯它!謝謝。現在我將嘗試將數組類型放入參數中,以便可以選擇可選列。 再一次,謝謝! – nicklowkc
如果答案幫助了您並解決了您的問題,則可以將其標記爲已接受。 @nicklowkc –