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

  • Home
  • SEARCH
  • 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 623829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:08:07+00:00 2026-05-13T19:08:07+00:00

(This is similar to a question I asked earlier: Porting Oracle Procedure to PostgreSQL

  • 0

(This is similar to a question I asked earlier: Porting Oracle Procedure to PostgreSQL)

I need to port:

/*
||  The following private procedure will execute a dynamic pl/sql
||  statement passed to it.
*/
   CREATE OR REPLACE FUNCTION DB_SHELL_UTIL_PKG.EXECUTE_STMT (stmt VARCHAR) IS
    v_num_rows      integer;
    v_cursor_table  integer;
  BEGIN
    v_cursor_table := dbms_sql.open_cursor;
    dbms_sql.parse (v_cursor_table, stmt, dbms_sql.v7);
    v_num_rows := dbms_sql.execute (v_cursor_table);
    dbms_sql.close_cursor(v_cursor_table);
  END execute_stmt;

and

/*
||  The following private procedure will write out to a system
||  file the statement passed to it.
*/
   CREATE OR REPLACE FUNCTION DB_SHELL_UTIL_PKG.write_log_info (p_path IN VARCHAR2,
                             p_file_name IN VARCHAR2,
                             stmt IN VARCHAR2 ) IS
      log_file UTL_FILE.FILE_TYPE;
   BEGIN
      log_file := UTL_FILE.FOPEN (p_path, p_file_name, 'A');
      UTL_FILE.PUT_LINE (log_file,stmt);
      UTL_FILE.FCLOSE(log_file);
   EXCEPTION
      WHEN OTHERS THEN
      UTL_FILE.FCLOSE(log_file);
      RAISE;
   END write_log_info;

and

/*
||  The following procedure will drop the user passed to it
|| and then record its action by writing out to a system file
*/
  PROCEDURE DROP_DB_PRO (  p_db_name IN VARCHAR2,
                  p_path IN VARCHAR2,
                  p_file_name IN VARCHAR2,
                  p_status OUT VARCHAR2  ) IS
    v_stmt  VARCHAR2(1500);
  BEGIN
    v_stmt :=  'DROP USER '||p_db_name||' CASCADE';
    execute_stmt (v_stmt);
    p_status := 'USER '||p_db_name|| ' HAS BEEN DROPPED';
    v_stmt :=  'THE USER '||p_db_name||' HAS BEEN DROPPED';
    write_log_info(p_path, p_file_name, v_stmt);
  EXCEPTION
    WHEN OTHERS THEN
    v_stmt := 'EXCEPTION raised in DROP_DB_PRO';
    write_log_info (p_path, p_file_name, v_stmt);
    RAISE;
  END DROP_DB_PRO;

From Oracle to PG/PLSQL…

I have gotten this far:

  CREATE OR REPLACE FUNCTION DB_SHELL_UTIL_PKG.EXECUTE_STMT (stmt VARCHAR)
  RETURNS void as '
  DECLARE
    v_num_rows      integer;
    v_cursor_table  integer;
  BEGIN
    v_cursor_table := dbms_sql.open_cursor;
    dbms_sql.parse (v_cursor_table, stmt, dbms_sql.v7);
    v_num_rows := dbms_sql.execute (v_cursor_table);
    dbms_sql.close_cursor(v_cursor_table);
  END execute_stmt;
' LANGUAGE plpgsql;

Which chokes on:

ERROR:  syntax error at or near "dbms_sql"
LINE 1: dbms_sql.parse ( $1 ,  $2 , dbms_sql.v7)

and

CREATE OR REPLACE FUNCTION DB_SHELL_UTIL_PKG.write_log_info (p_path VARCHAR,
                             p_file_name VARCHAR,
                             stmt VARCHAR ) 
RETURNS void as '
      log_file UTL_FILE.FILE_TYPE;
   BEGIN
      log_file := UTL_FILE.FOPEN (p_path, p_file_name, ''A'');
      UTL_FILE.PUT_LINE (log_file,stmt);
      UTL_FILE.FCLOSE(log_file);
   EXCEPTION
      WHEN OTHERS THEN
      UTL_FILE.FCLOSE(log_file);
      RAISE;
   END write_log_info;
' LANGUAGE plpgsql;

which chokes on:

ERROR:  syntax error at or near "log_file"
LINE 6:       log_file UTL_FILE.FILE_TYPE

and

  CREATE OR REPLACE FUNCTION DB_SHELL_UTIL_PKG.DROP_DB_PRO (  p_db_name VARCHAR,
                  p_path VARCHAR,
                  p_file_name VARCHAR,
                  p_status VARCHAR  )
   RETURNS varchar as ' 
   DECLARE
    v_stmt  VARCHAR(1500);
  BEGIN
    v_stmt :=  'DROP USER '||p_db_name||' CASCADE';
    execute_stmt (v_stmt);
    p_status := 'USER '||p_db_name|| ' HAS BEEN DROPPED';
    v_stmt :=  'THE USER '||p_db_name||' HAS BEEN DROPPED';
    write_log_info(p_path, p_file_name, v_stmt);
    return(p_status);
  EXCEPTION
    WHEN OTHERS THEN
    v_stmt := 'EXCEPTION raised in DROP_DB_PRO';
    write_log_info (p_path, p_file_name, v_stmt);
    RAISE;
  END DROP_DB_PRO;
  ' LANGUAGE plpgsql;

Help with any of these would be much appreciated (I am new to the world of functions/stored procedures)

  • 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-05-13T19:08:07+00:00Added an answer on May 13, 2026 at 7:08 pm

    For the DBMS_SQL one, look at Dynamic SQL in plpgsql

    For UTL_FILE, you’ll have to look beyond plpgsql or at Orafce

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

Sidebar

Related Questions

i have asked a similar question earlier, but this time i need a method
This question is very similar to an earlier question I asked ( This Question
I've kind of asked this question earlier so sorry for asking a bit similar
This is similar to a question I asked earlier . The answers to that
I know this sounds strange earlier I asked about similar question in one of
Guys I asked a similar question like this earlier since I was unable to
This is very similar to this question I asked earlier. I am hoping to
This question is similar to what has been asked earlier but I think memory
I asked a similar question earlier and we came down to this CSS solution
In this earlier question , the OP asked for a data structure similar to

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.