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 8186941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:23:41+00:00 2026-06-07T02:23:41+00:00

I’m using Oracle apex and am trying to practice with automatic emails. Ideally, this

  • 0

I’m using Oracle apex and am trying to practice with automatic emails. Ideally, this is how the scenario would go: A user can ‘recommend’ games to friends through his wishlist. The user selects the game(s) they would like to recommend though a checkbox, then selects the friends and email content. The code I have in place for this is as follows:

DECLARE
content VARCHAR2(4000) := :P4_EMAIL ||  'Here are the game(s):';
game VARCHAR2(100);
i    NUMBER := 1;

/*Declare the cursor and it's query */
cursor CURSOR IS
    SELECT name
    from gs_games
    where game_id = APEX_APPLICATION.G_F01(i)
    FOR UPDATE;

BEGIN
FOR i in 1..APEX_APPLICATION.G_F01.count
LOOP
OPEN cursor;
FETCH cursor INTO game;
CLOSE cursor;
END LOOP;
htmldb_mail.Send(p_to   => :P4_FRIENDS,
                 p_from => 'gametracker@gametracker.com',
                 p_subj => 'Game recommendations from ' || :F56_USER_NAME,
                 p_body => content || ' ' || game);
END;

This only partially works. For a single selection, everyone works perfectly, but once the user selects multiple games, then the email only contains the name of the first game checked off, instead of every game as it should. I realize this is tied to the way I’ve got my cursor set up, but I’m not entirely sure how I can use it while keeping that for loop active. Does anyone have any ideas? Thank you.

  • 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-07T02:23:43+00:00Added an answer on June 7, 2026 at 2:23 am

    The immediate problem is that every time you fetch the next row from the cursor into your local variable game, you are overwriting the prior value of that variable. Once you’ve fetched every row from the cursor, game will have the value of whatever the last row you processed was.

    Assuming that you want your email to contain a comma-separated list of game names, you could do something like

    -- You probably want to create this function inside of a package that provides other methods
    -- for interacting with games
    CREATE OR REPLACE FUNCTION get_game_name( p_game_id IN gs_games.game_id%type )
      RETURN gs_games.name%type
    IS
      l_name gs_games.name%type;
    BEGIN
      SELECT name
        INTO l_name
        FROM gs_games
       WHERE game_id = p_game_id;
    
      RETURN l_name;
    END get_game_name;
    
    DECLARE
      l_content   VARCHAR2(4000) := :P4_EMAIL ||  'Here are the game(s):';
      l_game_list VARCHAR2(100);
    BEGIN
      FOR i in 1..APEX_APPLICATION.G_F01.count
      LOOP 
        l_game_list := l_game_list || ', ' || get_game_name( APEX_APPLICATION.G_F01(i) );
      END LOOP;
      l_game_list := LTRIM( ', ' );
    
      apex_mail.send( p_to   => :P4_FRIENDS,
                      p_from => 'gametracker@gametracker.com',
                      p_subj => 'Game recommendations from ' || :F56_USER_NAME,
                      p_body => l_content || ' ' || l_game_list);
    END;
    

    A few notes about style

    • Naming a cursor CURSOR is problematic and should be avoided at all costs. If you do need to declare a cursor, you really ought to give it a meaningful name.
    • Local variables generally ought to be named in such a way that differentiates them from the names of columns in tables (in my case, I use a l_ prefix for local variables and a p_ prefix for parameters though there are many different valid conventions. This is important in PL/SQL because identifiers in SQL statements are resolved first using the names of columns in the table and then using local variables. That makes it far too easy to inadvertently write code that uses a column when you meant for it to use a local variable if you don’t have some convention to make it clear which you’re using.
    • You don’t want to use a cursor to select a single row of data. If you have a query that you know should return exactly 1 row, use a SELECT INTO.
    • I created a separate function to get the name for a particular game_id because that maximizes reuse– there will likely be many other places that you need to do something similar so you want to write that code once and use it many times. It would be perfectly legal to put the SELECT INTO into the loop in your anonymous PL/SQL block, it would be preferable to factor that code out into a function.
    • Assuming you are using a vaguely recent version of APEX, you should be using the apex_mail package not the old htmldb_mail package. There shouldn’t be any functional difference between the two but HTML DB was the old name for Oracle APEX many releases ago so it’s a good idea to phase out the use of the old package names.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't

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.