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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:33:40+00:00 2026-06-11T20:33:40+00:00

I have the following code: CREATE OR REPLACE FUNCTION repeatable_rand_text(ftype IN VARCHAR2 , in_val

  • 0

I have the following code:

CREATE OR REPLACE FUNCTION repeatable_rand_text(ftype    IN VARCHAR2
                                              , in_val   IN VARCHAR2)
    RETURN VARCHAR2 IS
    workval         VARCHAR2(64);
    insert_needed   BOOLEAN := FALSE;
BEGIN
    BEGIN
        SELECT new_name
        INTO   workval
        FROM   ps_dt_mixnames_preserve
        WHERE  name_type = ftype AND old_name = in_val;

    EXCEPTION
        WHEN NO_DATA_FOUND THEN
            workval := rand_text(ftype);
            insert_needed := TRUE;
    END;

    IF insert_needed THEN
        INSERT INTO ps_dt_mixnames_preserve(name_type, old_name, new_name)
        VALUES      (ftype, in_val, workval);
    END IF;

    RETURN workval;
END repeatable_rand_text;

The purpose of this routine, is to mask names in a database as part of the preparation to create a development database from Production.

We want to mask the names, but we want them to be repeatable so that our result is something like: (input on the left; output on the right)

JOHN JONES  -> STEEL POTATO
SAM JONES   -> LARGE POTATO
MARY JONES  -> WHITE POTATO
SUE SMITH   -> LARGE CARROT
FRED JONES  -> RED POTATO
JOHN SMITH  -> GREEN CARROT

You probably get the idea: family name is changed to a random value, but repeats when it is again encountered. Given name is simply random. It is the family name that’s a concern here.

Arrays and other non-permanent solutions won’t work well for us, because this will actually be executed as a large series of UPDATE statements all executed within the same session. GTT seemed a perfect fit for this type of thing.

Ultimately, we’ll want to execute an Update similar to:

UPDATE MY_TABLE
SET ORIG_NAME = repeatable_rand_text('last', ORIG_NAME)

But in an effort to “prove the results of this routine, we execute the following SQL:

SELECT ORIG_NAME, repeatable_rand_text('last',ORIG_NAME)
FROM MY_TABLE

Now, obviously the INSERT in that function will execute as a result of the SELECT, and that’s a no-no. (And without being able to do that, we’re loathe to try the UPDATE that naturally follows. For all we know, it may fail with a similar message.) The question is, is there a reasonable way around this scenario?

  • 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-11T20:33:41+00:00Added an answer on June 11, 2026 at 8:33 pm

    I finally used an autonomous block. Those are rarely a good idea, but in this case I think it’s just the ticket. here’s how it looks:

    function repeatable_rand_text(ftype IN VARCHAR2, in_val IN VARCHAR2)
        -- The idea is to assign random values to an entity (such as family name),
        -- and to repeat that value each time that entity is seen again.  In this
        -- manner, we can assign random values without losing associations such as
        -- (again) family NAMES.
        --     JONES  -> POTATO
        --     SMITH  -> CARROT
        --     DOE    -> ONION
        --     JONES  -> POTATO
        --
        -- Parameters:
        --    field-type  ('ADJ'  'NOUN'   'BOTH')
        --    field-value
        --
        RETURN VARCHAR2
        DETERMINISTIC IS
        PRAGMA AUTONOMOUS_TRANSACTION;
        workval         VARCHAR2(64);
        insert_needed   BOOLEAN := FALSE;
    BEGIN
        BEGIN
            SELECT new_name
            INTO   workval
            FROM   ps_dt_mixnames_preserve
            WHERE  name_type = UPPER(ftype) AND old_name = UPPER(in_val);
        EXCEPTION
            WHEN NO_DATA_FOUND THEN
                workval := rand_text(ftype);
                insert_needed := TRUE;
        END;
    
        IF insert_needed THEN
            INSERT
            INTO   ps_dt_mixnames_preserve(name_type, old_name, new_name)
            VALUES (UPPER(ftype), UPPER(in_val), UPPER(workval));
    
            COMMIT;
        END IF;
    
        RETURN workval;
    END repeatable_rand_text;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code to return multiple values from pl/python: CREATE TYPE named_value
I have the following type and function: CREATE OR REPLACE TYPE SERIAL_NUMBER_TABLE AS TABLE
I have used following code to create a simple PDF file. It executes fine
I have the following test-code: CREATE TABLE #Foo (Foo int) INSERT INTO #Foo SELECT
I have the following code to create and apply a few styles for a
I have the following code to create a music playlist based on files in
I have the following code to create my window, my view and my sub
I have the following code: // GET: /PlayRoundHole/Create public ActionResult Create(int id) { DB
I have the following code: // // POST: /PlayRoundHole/Create [AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(FormCollection collection)
I have the following code. I need to create list separators before A elements,

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.