Oracle generates column names for the specified table and adds a select from before and after

Source: Internet
Author: User

Table column name is more time, manual write column name is more troublesome, this function can let a person secretly lazy

Create or Replace function F_getcols (p_tablename in varchar2/* gets all column names in the table before and after you add select from*/) RETURN varchar2
Is
Result VARCHAR2 (2000);
V_cnts number;
V_strtabname VARCHAR2 (200);
BEGIN
V_strtabname:=upper (P_tablename);
Select COUNT (1) into v_cnts from User_tables where table_name=v_strtabname;
If V_cnts>0 Then
result:= ' SELECT ';
For CR in (select column_name from User_tab_columns where table_name=v_strtabname order by column_id)
Loop
result:=result| | cr.column_name| | ', ';
End Loop;
Result:=substr (Result,1,length (Result)-1);
result:=result| | ' from ';
Else
result:= ' table does not exist ';
End If;
return (Result);
END F_getcols;

How to use

Select F_getcols (' table name ') from dual;

Oracle generates column names for the specified table and adds a select from before and after

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.