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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:35:18+00:00 2026-06-01T07:35:18+00:00

I wrote an Oracle function (for 8i) to fetch rows affected by a DML

  • 0

I wrote an Oracle function (for 8i) to fetch rows affected by a DML statement, emulating the behavior of RETURNING * from PostgreSQL. A typical function call looks like:

SELECT tablename_dml('UPDATE tablename SET foo = ''bar''') FROM dual;

The function is created automatically for each table and uses Dynamic SQL to execute a query passed as an argument. Moreover, a statement that executes the query dynamically is also wrapped in a BEGIN .. END block:

EXECUTE IMMEDIATE 'BEGIN'||query||' RETURNING col1, col2 BULK COLLECT INTO :1, :2;END;' USING OUT col1_t, col2_t;

The reason behind this perculiar construction is that it seems to be the only way to get values from the DML statement that affects multiple rows. Both col1_t and col2_t are declared as collections of the types corresponding to the table columns.

Finally, to the problem. When the query passed contains a subselect, execution of the function produces a syntax error. Below is a simpe example to illustrate this:

CREATE TABLE xy(id number, name varchar2(80));
CREATE OR REPLACE FUNCTION xy_fn(query VARCHAR2) RETURN NUMBER IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
EXECUTE IMMEDIATE 'BEGIN '||query||'; END;';
ROLLBACK;
RETURN 5;
END;
SELECT xy_fn('update xy set id = id + (SELECT min(id) FROM xy)') FROM DUAL;

The last statement produces the following error: (the SELECT that is mentioned there is the SELECT min(id))

ORA-06550: line 1, column 32: PLS-00103: Encountered the symbol
“SELECT” when expecting one of the following: ( – + mod not null
others avg count current exists max min prior sql stddev sum
variance execute forall time timestamp interval date

This problem occurs on 8i (8.1.6), but not 10g.
If BEGIN .. END blocks are removed – the problem disappears.
If a subselect in a query is replaced with something else, i.e. a constant, the problem disappears.

Unfortunately, I’m stuck with 8i and removing BEGIN .. END is not an option (see the explanation above).

Is there a specific Oracle 8i limitation in play here? Is it possible to overcome it with dynamic SQL?

  • 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-01T07:35:19+00:00Added an answer on June 1, 2026 at 7:35 am

    Not sure why you need to do all this work. Oracle 8i supported RETURNING INTO with bulk collection. Find out more

    So you should just be able to execute this statement in non-dynamic SQL. Something like this:

    UPDATE tablename 
    SET foo = 'bar' 
    returning  col1, col2 bulk collect into col1_t, col2_t;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've converted a bunch of DML (INSERT/UPDATE/DELETE) queries from Oracle into PostgreSQL and now
I have to write an Oracle procedure which should invoke an Oracle function returning
I wrote a package to query rows from a table. This select query will
I am trying to read a BLOB from an Oracle database. The function GetFileContent
I wrote a small script to extract data from Oracle using Takusen: {-# LANGUAGE
Recently I had to write an oracle function, and the error ora-06575 popped up
i wrote program to connect oracle database 11g for my android application to store
i wrote a java app that communicates and stores data in oracle; my question
I am using Oracle SQL and I want to group some different rows that
I want to use an equivalent of Oracle's nvl() function in Ruby. Is there

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.