Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2014
    Posts
    2

    Unanswered: iteration on unknown column name in PL/SQL style

    Hello all,
    I started SQL very recently. Today, I saw PL/SQL topic which is vital to use it to have loops on codes.

    I wrote the following code as you see where I can see the name of the tables
    This code runs ok :

    Code:
    SET	linesize 32000
    SET	pagesize 2400
    set serveroutput on size 30000;
    declare 
    CURSOR cur1 IS
    	select * from user_tables;
    begin
    	For myItem IN  cur1 LOOP
    			dbms_output.put_line(myItem.Table_Name);
    	END Loop;
    end;
    /
    How can I do iterations on all the columns of myItem cursor if I do not know the name of the columns in advanced?


    Thank you in advanced,
    Sam!
    Last edited by sam80; 01-16-14 at 11:33.

  2. #2
    Join Date
    Jan 2014
    Posts
    2

    iteration on unknown column name in PL/SQL style

    Hello all,
    I am new in SQL. Today I wanted to do some iteration on my db and I found that I need to use PL/SQP.

    The code that you see here works fine.
    Code:
    SET	linesize 32000
    SET	pagesize 2400
    set serveroutput on size 30000;
    declare 
    CURSOR cur1 IS
    	select * from user_tables;
    begin
    	For myItem IN  cur1 LOOP
    			dbms_output.put_line(myItem.table_name);
    	END Loop;
    end;
    /
    But what happens if I want to do iteration on myItem when I do not know the column's name?
    Should I have somehow a nested cursor?


    Thank you in advanced,
    Sam

  3. #3
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    query ALL_TAB_COLUMNS
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  4. #4
    Join Date
    Mar 2007
    Posts
    623
    Hi,

    you cannot in static SQL. You can abuse dynamic SQL and put column names from Oracle meta data into it.

    However, then there is still one question: if you even do not know columns which name(s), which kind of action are you planning to do with them?

    If you want to just put the table content into DBMS_SQL buffer (note that you do not need PL/SQL, simple SQL SELECT statement for displaying this result set), then you may be interested in this link: http://asktom.oracle.com/pls/apex/f?...:1035431863958

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •