How to dynamically change table names in Oracle PL/SQL statements

Source: Internet
Author: User

/*
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 ;*/

Related Article

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: info-contact@alibabacloud.com 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.