Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8335133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:34:25+00:00 2026-06-09T03:34:25+00:00

I am writing a PL SQL block that retrieves all the columns and the

  • 0

I am writing a PL SQL block that retrieves all the columns and the data types of the tables in the database. I am able to get the columns , but not the datatypes. Looking for suggestions for a good approach. Any help would be appreciated. My code is as follows

ACCEPT p_1 PROMPT 'Please enter the Table Name'

DECLARE
    v_table_name    VARCHAR2(40) :='&p_1';
    -- First cursor 
    CURSOR get_tables IS    
        SELECT DISTINCT table_name 
        FROM user_tables 
        WHERE UPPER(table_name) = UPPER(v_table_name);
    --Second cursor 
    CURSOR get_columns IS
        SELECT DISTINCT column_name
        FROM user_tab_columns
        WHERE table_name = v_table_name;
    v_column_name   VARCHAR2(100);
    -- Third Cursor
    CURSOR get_types IS
        SELECT data_type 
        FROM user_tab_columns
        WHERE table_name = v_table_name;

    v_data_type user_tab_columns.data_type%type;
BEGIN
    -- Open first cursor
    OPEN get_tables;
    FETCH get_tables INTO v_table_name;
    DBMS_OUTPUT.PUT_LINE(' ');
    DBMS_OUTPUT.PUT_LINE('Table = ' || v_table_name );
    DBMS_OUTPUT.PUT_LINE('=========================');
    CLOSE get_tables;
    -- Open second cursor
    OPEN get_columns;
    FETCH get_columns INTO v_column_name;
    WHILE get_columns%FOUND LOOP
        DBMS_OUTPUT.PUT_LINE('  ' || v_column_name);
        FETCH get_columns INTO v_column_name;
    END LOOP;
    CLOSE get_columns;
    --Open Third Cursor
    OPEN get_types;
    FETCH get_types into v_data_type;
    WHILE get_types%FOUND LOOP
        DBMS_OUTPUT.PUT_LINE(' ' || v_data_type );
        FETCH get_types into v_data_type;
    END LOOP;

    CLOSE get_types;     
END;

My error states PLS-00371: at most one declaration for ‘V_DATA_TYPE’ is permitted

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T03:34:27+00:00Added an answer on June 9, 2026 at 3:34 am

    Not a PLSQL guru but here’s my grain.

    Select data_type from user_tab_columns where TABLE_NAME = 'YourTableName'
    

    Props to Eric, check this thread and his answer.

    Remember you can use DESC command to describe an Oracle Table, View, Synonym, package or Function. It will give you name, data_type and lengh.
    And if this actually works for you, you should be able to get the data for all of your tables, although I’m not a huge fan of cursors, you should do fine.

    Try this:

    -- Open second cursor
                OPEN get_columns;
                LOOP
                FETCH get_columns INTO v_column_name, v_data_type;
                EXIT WHEN get_columns%NOTFOUND;
                DBMS_OUTPUT.PUT_LINE('  ' || v_column_name);
                END LOOP;
                CLOSE get_columns;
        END LOOP;
    

    But be careful on the datatype you’ve chosen for v_data_type variable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on scripts that apply database schema updates. I've setup all my SQL
I'm writing a SQL embedded in C program with tables below: table index:id, xx
I am writing a PL/SQL Procedure that performs a select based on input variables
I'm writing sql to search a database by a number of parameters. How would
I find myself writing SQL code (queries or stored procs) to solve problems that
I am newbie in writing SQL queries and this is for a mySQL database.
I have this idea that using SQL VIEWS to abstract simple database computations (such
I'm writing an activity in Android where the user modifies an SQL Database. The
Oracle IDE to visually = wizard (not writing sql) create views? any names? (eg
I am writing SQL Server database, where I have a relation UserTypedText(userId, date, textId,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.