Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Output layout

Status
Not open for further replies.

neskin

Programmer
Mar 13, 2002
104
AU
Hello,
I have a table with data
date runname
01/01/05 09R
01/01/05 27L
02/01/05 09L
02/01/05 28R

My output need to be like
date runname
01/01/05 09R 27L
02/01/05 09L 28R

Thank you in advance
Nat
 
Neskin,

For output like yours, I particularly like to use a user-defined function such as this one:
Code:
create or replace function get_runnames (dt_in date) return varchar2 is
        hold_names varchar2(100);
    begin
        for x in (select runname from neskin where dt = dt_in) loop
            hold_names := hold_names||’ ‘||x.runname;
        end loop;
        return trim(hold_names);
    end;
/

Function created.

Once you have created the function, you can then access it to produce your results with this code:
Code:
col runname format a7
col dt heading "Date" format a8
select distinct to_char(dt,'mm/dd/yy') dt
      ,get_runnames(dt) runname
    from neskin
  order by dt;

Date     RUNNAME
-------- -------
01/01/05 09R 27L
02/01/05 09L 28R
By the way, "DATE" is a reserved word in Oracle, so you cannot use it as a column name as you did in your original post.

Let us know if this technique meets with your satisfaction.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I can provide you with low-cost, remote Database Administration services: see our website and contact me via www.dasages.com]
 
thank you for your quick response
About the date i know it was just as example
I am new to Oracle .
My new question is I am creating a procedure in Oracle then I am using as a datasource for crystal report .
Can you advice me please what is the best way to do it
Do I still have to create a user _define function or I can use a script in side of the procedure
thanks
Nat
 
Nat,

Sorry, the only thing I know about Kristle Reprots is how to spell it.[smile] If you don't get any takers here to answer your question, then I recommend posting your follow-on question in one of the "Business Objects: Crystal..." fora.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I can provide you with low-cost, remote Database Administration services: see our website and contact me via www.dasages.com]
 
don't worry about crystal can you tell me if it can be done in the procedure instead of user define function
 
Neskin,

The fundamental difference between a procedure and a function is that since a function is an expression, you treat it as data, whereas you cannot treat a procedure as a data expression. Therefore, you cannot refer to a procedure explicitly in a SQL SELECT statement, but you certainly can refer to both built-in and user-defined functions in a SELECT statement -- Oracle depends very heavily upon functions (e.g., SYSDATE, SUBSTR, TO_CHAR, TRIM, UPPER, LOWER, INITCAP, INSTR, MIN, MAX, SUM, COUNT, AVG, et cetera).

Did this adequately answer your question?

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I can provide you with low-cost, remote Database Administration services: see our website and contact me via www.dasages.com]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top