我在尝试使用define命令时收到错误,否则代码工作正常请告诉我如何使用define命令使用此代码。定义b_table ='&请输入表名';
declare
v_count number;
cursor c2 is select Column_name
from all_tab_columns
where table_name= '&b_table';
begin
for r1 in c2 loop
dbms_output.put_line(r1.column_name);
select count(r1.column_name) into v_count
from HR.'&b_table';
if v_count =0 then
dbms_output.put_line(v_count);
end if;
end loop;
end;
old 5: where table_name= '&b_table';
new 5: where table_name= ' enter the table name';
old 11: from HR.'&b_table';
new 11: from HR.' enter the table name';
from HR.' enter the table name';
*
ERROR at line 11:
ORA-06550: line 11, column 9:
PL/SQL: ORA-00903: invalid table name
ORA-06550: line 10, column 1:
PL/SQL: SQL Statement ignored
答案 0 :(得分:1)
试试这个
SET serveroutput ON;
DECLARE
v_count NUMBER;
v_table_name VARCHAR2(200);
CURSOR c2(v_table VARCHAR2)
IS
SELECT Column_name FROM all_tab_columns WHERE table_name= v_table;
BEGIN
v_table_name := :table_name;
FOR r1 IN c2(v_table_name)
LOOP
dbms_output.put_line(r1.column_name);
EXECUTE immediate('SELECT COUNT('||r1.column_name||') FROM HR'||'.'||v_table_name) INTO v_count;
IF v_count =0 THEN
dbms_output.put_line(v_count);
END IF;
END LOOP;
END;