Chopsy
Chopsy

Reputation: 43

how to SAVE many values in one field/column of one row in oracle database?

I want to keep track of an individual's credit card transactions(the amount, in essence). Instead of having a new entry made in the database for each transaction, is there any way I can save all the transactions of one person on a single row? i.e. , if a person A makes purchases of Rs.1500, Rs. 2600 and Rs. 3200 at different instances, I want the table entry to look something like this:

A : 1500, 2600, 3200

Also, is there any way I can keep only certain number of entries? Meaning, for one new entry added, one oldest entry should get deleted. I'm using Oracle 10g. Please help me out. Thank you.

Upvotes: 1

Views: 1049

Answers (1)

Justin Cave
Justin Cave

Reputation: 231741

Can you? Well, you certainly could define the column as a VARCHAR2 or a CLOB and write a comma-separated list of values to that column. That would mean that you would then have to write code to parse the data every time you selected it. And write code to do things like removing or modifying one element in the list. And you'd lose the benefits of proper data typing. And of proper normalization. And you'd really, really annoy whoever has to support your code in the future. Particularly when someone inadvertently stores a transaction value of 1,000 rather than 1000 in your comma-separated string column.

So you can, yes. But I cannot envision any situation where it would really make sense to do so.

Create a table to store transactions. Create a new row for every transaction. Link each transaction to a specific person. You'll be grateful you did.

Upvotes: 4

Related Questions