Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8646697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:52:52+00:00 2026-06-12T12:52:52+00:00

I have a query that a user enters an item number, and the query

  • 0

I have a query that a user enters an item number, and the query displays the item number and item description, then goes in a loop and displays information for every item number in the database. At the end of the loop, the query will show you the total amount of inventory based on the items displayed.

How would I display the Item Number and Item Description before the loop begins? Everything is working fine expect for that one part.

I want to see Item Number: 5 Item Description: Shirt. I don’t see any data for Item Number and Item Description.

PL/SQL QUERY:

SET SERVEROUTPUT ON
DECLARE
    CURSOR C1 
    IS
    SELECT items.items_numbers, items_description, items_size, items_price, items_qoh, sum(items_price*items_qoh) "Value" FROM inventories
    JOIN items ON inventories.items_number=items.items_numbers
    WHERE items.items_numbers='&enter_items_number'
    GROUP BY items.items_numbers, items_description, items_size, items_color, items_price, items_qoh
    ORDER BY items_price;

    totalvalue NUMBER(8,2); 
    test1 C1%rowtype;

    BEGIN
    OPEN C1;
    totalvalue:=0;  
    DBMS_OUTPUT.PUT_LINE('items ID: '  || test1.items_number ||  'items Description: ' ||  test1.items_description);
    close C1;
    open C1;
    LOOP

    fetch C1 into test1;
    exit when c1%notfound;

    DBMS_OUTPUT.PUT_LINE('Size: ' || test1.items_size);
    DBMS_OUTPUT.PUT_LINE('Price: ' || test1.items_price);
    DBMS_OUTPUT.PUT_LINE('QOH: ' || test1.items_qoh);
    DBMS_OUTPUT.PUT_LINE('Value: ' || test1.items_qoh*test1.items_price);
    totalvalue:=totalvalue+test1.items_qoh*test1.items_price;
    END LOOP;   

DBMS_OUTPUT.PUT_LINE('TOTAL VALUE: '  || totalvalue);

END;
/

Output:

 Item Number: Item Description:
 Size: S
 Price: 25.00
 QOH: 25
 Value: 625.0
 Size: L
 Color: Blue
 Price: 30.00
 QOH: 100
 Value: 3000.0
 TOTAL VALUE: 3625.0
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T12:52:53+00:00Added an answer on June 12, 2026 at 12:52 pm

    Just like you’re fetching data from the open cursor within the loop, you’ll have to fetch data before the loop to be able to print it. Right now you’re only opening the cursor and closing it thereafter, without fetching from it. Be aware to check whether you were able to fetch a row or not (like you did with c1%notfound).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem, i have a query that just simply displays the user
I have a query that pulls back a user's feed which is essentially all
i have a query that returns some users related to a specific user (Bob).
I have a script that I'm using that when the user enters a code
I have created a word dictionary that uses PHP and XML. The user enters
I have an application that executes the following MySQL query: SELECT 402 AS user_id,
I am using in C# MYsql .I have query that works if I run
I have a query that successfully grabs the unique products from my products table
I have a query that basically combines tables of actions and selects from them
I have have this query that i want to execute. SELECT warehouse.expiry_date, pharmacy.expiry_date, drugs.active_substance,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.