How to dynamically change table names in OraclePL/SQL statements using the cursor declaration _ Oracle _

Source: Internet
Author: User
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
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

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;
Open cur for 'select employee_id from '| tb;
Fetch cur into id;
Exit when cur % notfound;

Total: = total + id;
End loop;
Close cur;

Dbms_output.put_line (total)
End ;*/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.