How to dynamically change table names in OraclePLSQL statements
How to dynamically change table names in Oracle PL/SQL statements
/*
The younger brother just came into contact with the ORACLE stored procedure and asked me a question. The younger brother wrote a stored procedure to receive a parameter as the table name, then, you can query the content of one field of all records in the table and import it to another table.
(
Tabname in varchar
)
Is
V_servicesname tabname. service type % type; -- this variable is used to store the obtained field content, but I do not know how to define it.
Cursor curSort1 is the select service type from tabname order by encoding; -- this statement does not prompt that the table name cannot be found
Begin
.....
End getservicesname1;
An example:
Create or replace procedure cal (tb varchar2) is
Id pls_integer;
Total pls_integer: = 0;
Type emp_cur is ref cursor;
Cur emp_cur;
Begin
Open cur for 'select employee_id from '| tb;
Loop
Fetch cur into id;
Exit when cur % notfound;
Total: = total + id;
End loop;
Close cur;
Dbms_output.put_line (total)
End ;*/