I have two tables: customer_data and customer_transactions. How can I get all the transactions to show under a single listing of the customer data, i.e., firstname, lastname, address followed by transaction_1, transaction_2 .....transaction_n?
There are two ways to do it. First, you can create a temporary table with all the columns you need. You must assume a maximum number of transactions per customer. For example, if 10 transactions are allowed, then the table structure will be:
FirstName, LastName, address, TRANS1,TRANS2,......TRANS10Then you write a PL/SQL block with two cursors: outer cursor for customer_data and inner cursor for customer transaction per current outer customer, and fill the temp table in the nested loop.
The second way is to do the same thing, but instead of inserting to a temp table, store it to an output line and use DBMS_OUTPUT to print the results. In this method, a maximum number of transation can vary.
For More Information
- Dozens more answers to tough Oracle questions from Eli Leiba are available here.
- The Best Oracle Web Links: tips, tutorials, scripts, and more.
- Have an Oracle or SQL tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize. Submit your tip today!
- Ask your technical Oracle and SQL questions -- or help out your peers by answering them -- in our live discussion forums.
- Ask the Experts yourself: Our SQL, database design, Oracle, SQL Server, DB2, metadata, object-oriented and data warehousing gurus are waiting to answer your toughest questions.
Dig Deeper on Oracle and SQL
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.