473,409 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

Selecting a column twice

Imagine you've got the following situation (Oracle 9i):
Table A
-------------------
Name
Customer
Log_Date
Log_Type

(Changing the format of the table is not an option as the database is
already in production, and owned by someone else)
When the Name field is changed, you insert a new row, putting the
current date in Log_Date and you set Log_Type to 1 to indicate the name
was changed.

When the Customer field is changed, you insert a new row, putting the
current date in the Log_Date and you set Log_Type to 2 to indicate the
customer was changed.

So, table data looks like:

Name Customer Log_Date Log_Type
------------------------------------------------------
Joe Acme 1-1-2003 1
Sue Acme 1-14-2003 1
Dave Telex 1-1-2003 2
Bob Sprint 10-1-2004 2
Joe Acme 1-1-2004 1

Now, you want to produce a dataset that shows the last updated date for
both customer and name
Name Updated (LOG_DATE) Customer Updated (LOG_DATE)
---------------------------------------------------------------------
Joe 1-1-2004 Acme 1-1-2003
Bob 12-1-2003 Sprint 10-1-2004

I certainly can't see any way to do that in a single query. Not only
does the Log_Date field appear twice, but you need to find the last
date with Log_Type = 1 and then the last date with Log_Type = 2.

I think this can be done either with a stored procedure, or perhaps a
table function. This code will be called from an external program.

My questions:

1) Can someone give advice on writing such a procedure or table
function?

2) Returning values via variables is straightforward, but how does one
return a dataset to the calling external program?

3) Assume for example that a procedure has been called by Perl. Does
DBMS_OUTPUT.PUT_LINE return anything to the calling program, or is it
just for producing console output in SQL*Plus?

Please let me know if I've not been clear.

Thanks,
Wade
Jul 19 '05 #1
0 2366

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Agoston Bejo | last post by:
Take a look at the following example: table T(i INTEGER, j INTEGER) I want to get the value of i where j is minimal and some conditions apply. (1) SELECT i FROM T WHERE AND j
3
by: Eric | last post by:
Hi : From a crystal report i get a list of employee firstnames as a string into my store procedure. Why is it comming this way ? hmmmmmm it's a question for me too. ex: "e1,e2,e3" here are my...
3
by: klawiter | last post by:
Greetings, I have a table with two columns. On my form, I have a combo field that displays the contents of the first column. Upon selecting an item in this combo field, I would like to then...
0
by: Steven W | last post by:
I'm trying to setup a datagrid in a custom control where I can select the row with the Select column hidden and have it call the "SelectIndexChanged" event. In the "SelectIndexChanged" I just want...
1
by: Bob Loveshade | last post by:
I am looking for an example that shows how to select and highlight multiple rows in a DataGrid. My DataGrid is part of a Web User Control which is contained in an ASPX page. I haven't been...
4
by: gane | last post by:
Hi, I am creating datagrid bound column dynamically and need to check if a datagrid column already exists?Is there a way to check this? thanks gane
9
by: niz182 | last post by:
Hey all...first time to the site so excuse me for bein some what of a noob to how to properly ask questions. Im looking to create a table which selects a cloumn from another table twice. so i...
0
by: Wade Williams | last post by:
Imagine you've got the following situation (Oracle 9i): Table A ------------------- Name Customer Log_Date Log_Type
1
watertraveller
by: watertraveller | last post by:
Hi all. My ultimate goal is to return two columns, where no single value appears anywhere twice. This means that not only do I want to check that nothing from column A appears in column B and...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.