Adding column name in the out put - PL/SQL - CURSOR

Hi All
I am very new to pl/sql.
I am trying to accomplish the below task in ORACLE XE in windows 7 os.
Using the DEPT table and an explicit cursor write a block to find the location of all departments.
dept table
DEPTNO DNAME     LOC
10     
ACCOUNTING     NEW YORK
20     RESEARCH     DALLAS
30     SALES     CHICAGO
40     OPERATIONS     BOSTON
BELOW IS MY CODE :
            BEGIN                                                                    
FOR D_DEPT_DETAILS IN (SELECT DEPTNO , LOC FROM DEPT)
LOOP
DBMS_OUTPUT.PUT_LINE(D_DEPT_DETAILS.DEPTNO || ' ' || D_DEPT_DETAILS.LOC);
END LOOP;
END;
/                      MY OUTPUT
10 NEW YORK
20 DALLAS
30 CHICAGO
40 BOSTON
My question is very simple
how do i add a coloum name to the above output. I refered the book but I couldnt find it.
Edited by: Matt on Apr 13, 2011 12:03 PM
Edited by: Matt on Apr 13, 2011 12:13 PM
Edited by: Matt on Apr 13, 2011 12:16 PM

Do you want a column header in the output? If so you could do something like this:
BEGIN
        DBMS_OUTPUT.PUT_LINE('DEPTNO LOC');
        FOR D_DEPT_DETAILS IN (SELECT DEPTNO , LOC FROM DEPT)
        LOOP
                DBMS_OUTPUT.PUT_LINE(D_DEPT_DETAILS.DEPTNO || '      ' || D_DEPT_DETAILS.LOC);
        END LOOP;
END;
/

Similar Messages

  • How should we get the out put file-name same as in put file-name in file to

    Hi frnds,
    having hundreds of files in the sender system with different names, how should we get the out put file-name  in the receiver system same as the in put file-name in file to file scenario ?
    Thanks in advance.
    truly,
    snrvakiti.

    Hi,
    In Receiver File Adapter you can set under 'Adapter-Specific Message Properties'
    check Use Adapter-Specific Message Properties
    check Fail on Missing Adapter Message Properties
    Check File Name
    Have a look at this link,  [File_to_File|http://allsapnetweavernotes.blogspot.com/2008/09/how-can-i-access-filename-from-fileftp.html]
    Regards,
    P.Rajesh

  • Is it possible to display only dynamically selected fields in the out put?

    Is it possible to display only dynamically selected fields in the out put? i need to display set of columns in the selection criteria, but in the output i have display only input given fields. because i need to convert it into .csv file. So i have to display selected fields from internal table. In oracle they are using"execute immediate". is there any equivalent in SAP?
    thanks in advance.

    Hi Remya,
    Are you talking about dynamic programming in ABAP ?
    If yes, there are concepts like RTTS which facilitates it.
    Yes, the select query also supports dynamic selection of fields. ( Please care about ( ) in dynamic sql ).
    Do more research on Field Symbols and statements like ASSIGN COMPONENT OF.
    Regards,
    Philip.

  • How to change recordset bahaviour to accept dynamic column names in the where clause

    Hi
    im using php-mysql and i make a recordset and i want to make the column names in the where clause to be dynamic like
    "select id,name from mytable where $tablename-$myvar";
    but when i do this my i break the recordset and it disappear
    and when i use variables from advanced recordset it only dynamic for the value of the column not for the column name
    and when i write the column name to dynamic as above by hand it truns a red exclamation mark on the server behaviour panel
    so i think the only way is to change the recordset behaviour is it? if so How to make it accept dynamic column names?
    thanks in advance.

    As bregent has already explained to you, customizing the recordset code will result in Dreamweaver no longer recognizing the server behavior. This isn't a problem, but it does mean that you need to lay out your dynamic text with the Bindings panel before making any changes. Once you have changed the recordset code, the Bindings panel will no longer recognize the recordset fields.
    Using a variable to choose a column name is quite simple, but you need to take some security measures to ensure that the value passed through the query string isn't attempting SQL injection. An effective way of doing this is to create an array of acceptable column names, and check that the value matches.
    // create array of acceptable values
    $valid = array('column_name1', 'column_name2', 'column_name3');
    // if the query string contains an acceptable column name, use it
    if (isset($_GET['colname']) && in_array($_GET['colname'], $valid)) {
      $col = $GET['colname'];
    } else {
      // set a default value if the submitted one was invalid
      $col = 'column_name1'
    You can then use $col directly in the SQL query.

  • Run time Column Name in the Select Statement

    Hi there,
    I face problem while writing sql statment for report in the Oracle reports.
    The prom is I want to bound the where clause column name with the value stored in a variable e.g.
    Select * from emp
    where Column_Name = 'XYZ' ;
    where the variable Column_Name have different values at different times, e.g.
    At a time the value of Column_Name is Dept then
    Select * from emp
    where Dept = 'XYZ' ;
    At other time value of Column_Name is City then
    Select * from emp
    where City = 'XYZ' ;
    Waiting for the response .
    Regards,
    Hafeez

    Hi,
    U can use lexical parameters for the solutions.U must be aware of it, but still i describe how to work it out.
    1)In your datamodel in object navigator create a parameter under User parameter node.Name the parameter, for eg. p_clause.
    set data type of parameter to character.
    2)write a select query eg.
    select * from emp &p_clause; --(THIS IS THE PARAMETER WE CREATED ABOVE)
    3)Now run your report
    Now in your parameter form pass the value for p_clause parameter.
    eg: where name='JACK';
    or
    where city='NEWYORK';
    or where deptno=10;
    But do it in steps as above mentioned.
    Do tell me if it works or not via mail on [email protected]
    Enjoy.......
    navneet jain
    [email protected]

  • How to refer to a column name in the domain constraint

    When we specify a check constraint (for SQL Server) within a domain we need to enter some syntax expression, for example
    len(phone) > 7
    Later the modeller will put exactly this expression into SQL code. But this would be wrong as constraint should refer to a column name in the table (which would not be "phone").
    So how to make Data modeler to put a real column name within domain constraint?

    Thank you very much, it really works!
    However I would like to know where I can get documentation on such internal variables (like %COLUMN%)? I find it difficult to locate this information in the Help file attached to a modeler (it seems that it only describes UI screens).

  • Importing the out-put to the exel

    Hi all,
    iam very new to the unix and sql,
    just i want to know how to export the out-put of the query into exel using unix(spool)

    A lot of people rob banks too.
    You can spool an output to a file delimiting columns with commas if you wish. But that is outputting a file not outputting to Excel.
    Personally I'd fire anyone in a data center I caught outputting Oracle into a non-secure unauditable form and putting the organization at risk.

  • Is it possible to export the out put of Crystal report into text file?

    Hi All,
    Is it possible to export the out put of Crystal report into text file?

    Hi
    Yes, Go to File --> Export --> Export Report --> Under Format select TEXT & select the destination as "Disk file"(defaultly selected)
    Give the proper details as per your requirement for "Characters per inch" & "Number of lines per page" & click on 'OK"
    In "Choose Export file" window, select the destination folder & provide file name. click on "SAVE"
    Regards
    Ashwini

  • Adding column names to data file

    Hi,
    I have a question regarding writing to file. Currently in my program, when I start running it, a dialog box pops up and the user gets to pick/ create a file. My data is written on to a file as columns. I want to add column names to the file. Any suggestions on how to do it? Since the file is created by the user at run time and since the column names have to be added just once at the beginning, I'm not sure how to go about doing this. Any suggestions or pointers?
    Thanks,
    Sukanya

    dear sir
    i wanted to ask you help. i saw your program bt i am having a big problem
    here is my VI. i actually have to do a database where there is the name of the student,
    date of equipment of borrowal. time of the equiment when it was borrowed and its date
    but when am doing this. each time i always have to create a new file each time.
    i cant use the only onw file.
    and also my 2nd problem is that when the output is being yielded, it is repeatedly
    givine me the same output twice, thrice and a lot like in the pic below
    help please
    Attachments:
    1we.JPG ‏84 KB
    doom..JPG ‏44 KB

  • How to get the column names of the table into the Dashboard prompt

    how to get the column names of the table into the Dashboard prompt
    Thanks & Regards
    Kishore P

    Hey john,
    My requirement is as follows
    I have created a Rank for Total sales by Region wise i.e RANK(SUM(Dollars By Region)) in a pivot table.
    My pivot table looks like this
    COLUMN SELECTOR: TOTAL US , REGION , DISTRICT , MARKET
    ---------------------------------------------------- JAN 2009          FEB 2009        MAR 2009
    RANK              REGION                  DOLLARS           DOLLARS        DOLLARS DOLLARS
    1 CENTRAL 10 20 30 40
    2 SOUTHERN 10 30 30 70
    3 EASTERN 20 20 20 60
    4 WESTERN 10 20 30 40
    When i select the District in column selector
    Report has to display rank based on Total Sales by District. i.e
    ------------------------------------------------- JAN 2009         FEB 2009       MAR 2009
    RANK             DISTRICT              DOLLARS           DOLLARS        DOLLARS DOLLARS
    for this i need to change the fx of rank i.e RANK(SUM(Dollars By Region)) to RANK(SUM(Dollars By District)) and fx of Region i.e Markets.Region to Markets.District dynamically.
    so , i need to capture column name of the value selected from the column selector and dynamically i need to update the fx 0f RANK & fx of region.
    do you have any solution for this?
    http://rapidshare.com/files/402337112/Presentation1.jpg.html
    Thanks & Regards
    Edited by: Kishore P on Jun 24, 2010 7:24 PM
    Edited by: Kishore P on Jun 24, 2010 7:28 PM

  • How to display the out put of the sql query in a text file using forms

    I want to display the out put of the sql query in a text file using forms 6.0.Same could be done using spool command in sqlplus but i want it using forms....Fiaz

    Have a look at the text_io package:
    http://www.oracle.com/webapps/online-help/forms/10g/state?navSetId=_&navId=3&vtTopicFile=f1_help/oraini/c_text_io.html&vtTopicId=
    cheers

  • Adding file name in the sender Adaptor

    Hi ,
    I am facing some problem in adding file name .
    The scenario is like this :
    The file needs to be send from on system  and needs to be Archived . Once processed, the archived file should be prefixed with ARCH_ so that it is not picked up again .And the other thing given is the file name used will be of the format XXX_YYY_nnnnnnnnnn.DAT where nnnnnnnnnn is the date stamp .
    Please help it's urgent ......
    Thanks and regards
    Anita

    Hi,
    if you can have XML achvived files you can use
    standard
    processing mode: Archive
    with one swich you can set the timestamp mode
    yyyMMdd-hhMMss-SSS_.
    ref
    http://help.sap.com/saphelp_nw04/helpdata/en/e3/94007075cae04f930cc4c034e411e1/content.htm
    Regards,
    michal

  • Need helpcreating a script to read the name of a folder and adding that name into the permissions of that folder

    Need help creating a script to read the name of a folder (which is the AD Username) and adding that name into the permissions of that folder.
    I have over 100 folders which I need to add the AD user to read and write to their own folder
    Hope you guys understand what I mean

    Just to add, Mac in intergrated into AD and all I need is help in creating the script
    Thanks

  • Run Clear Case command from java and save the out put in to a file.

    Can any one help me out ...
    I want to execute Clear case command from a java and want to save the out put of this command to a file.
    I am naot able to find out how to start..
    Message was edited by:
    chandra_verma

    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • Need to filter the out put of iw38 reprort

    hello Experts,
    i have requirement like need to filter the out put of iw38 report and after that again i need to filter that output by using department and client code and oreder .ned to show out put with 3 push buttons .
    dertails:
    selection screen fields:
    region
    customer  code
    oreder
    date range
    from these 4 fields i need to pass two(order and date range)   fields to  iw38 report and then what ever output i am getting again that should filter by customer code and region which are there in my program
    , need to display the out put with 3 push buttons .
    plz suggest me  with appraoach and sample code .
    Note : i am using using submit and return export memory but its directly showing iw38 output and not coming back.

    Hi ananta,
    The function module LIST_FROM_MEMORY loads the list from the ABAP Memory to an internal table of the row type ABAPLIST.
    The function module WRITE_LIST inserts the content of an internal table of the row type ABAPLIST in the current list.
    The function module DISPLAY_LIST displays the content of an internal table of the row type ABAPLIST in a separate list screen.
    check the below program..
    REPORT  Z642_TEST2.
    DATA list_tab TYPE TABLE OF abaplist.
    SUBMIT riaufk20 EXPORTING LIST TO MEMORY
                                    AND RETURN.
    CALL FUNCTION 'LIST_FROM_MEMORY'
      TABLES
        listobject = list_tab
      EXCEPTIONS
        not_found  = 1
        OTHERS     = 2.
    IF sy-subrc = 0.
      CALL FUNCTION 'WRITE_LIST'
        TABLES
          listobject = list_tab.
    ENDIF.
    write: ' This is calling program', sy-repid.
    Edited by: Rammohan Nagam on Apr 8, 2009 4:05 PM

Maybe you are looking for

  • Error in Import Java Dump during installation on MSCS

    Dear Experts, I am facing the following the error during ECC 6 dual stack installation on MSCS. PM com.sap.inst.jload.Jload main SEVERE: couldn't connect to DB Apr 29, 2011 5:40:30 PM com.sap.inst.jload.Jload logStackTrace SEVERE: java.sql.SQLExcepti

  • Keeps asking for apple Id that is not mine

    I reset my iPad and now it keeps asking for apple ida that are not mine.  How can i get it to stop?

  • Where have lib32-libxxf86vm lib32-gcc-libs and wine gone?

    Im just installed 64bit arch, as i couldnt get gpu folding to with with ubuntu, i had arch 64bit workin a few months ago no problems, this install, i cannot install wine or the foldingathome-gpu-nvidia packages because they have missing dependencies,

  • Regarding select query Issue

    Hi ABAPERS,       I had written one written one 'select single' query to retrieve the data from PRPS table. but what the data was selecting for OBJNR (Object number)field based on PSPNR(WBS element) . That OBJNR values in the report is totally differ

  • SCOM Alerting : How to change displayed "Has value" number on email to user

    Our end users who receive these alerts want to see only a whole number value for Logical Disk  with a counter % Free Space Presently the alert fires -email is sent and the out put that is displayed for "has a value" displays 12.8447532653809 Users wa