1. Olan Knight
  2. PowerBuilder
  3. Monday, 25 January 2021 21:54 PM UTC

PowerBuilder 2019R2
Oracle 12C
Windows 10 64 bit platform, SP-1

 

Summary:  What's wrong with the dynamic SQL below?

Details:   When the SQL below was run, it generated the following error when the FETCH was executed:


SQL:
DECLARE my_cursor DYNAMIC CURSOR FOR SQLSA;
string  ls_sql, ls_data


    // Use the pk_column_name to get the next UID
    ls_sql = 'SELECT MAX (' + ls_pk_column + ') FROM ' + as_tablename + "; "


    // Process the dymanic sql
    PREPARE SQLSA FROM :ls_sql USING SQLCA ;

    OPEN DYNAMIC my_cursor ;
    
    
    FETCH my_cursor INTO :UID ;        <---- Error occurs on the FETCH
    
    ll_rc = sqlca.sqlCode
    IF (ll_rc = 0 AND NOT (IsNull (UID)) AND (UID > 0)) THEN
        
        // Success
        al_uid              = UID + 1
        lb_update_table_uid = TRUE
        
    ELSE
        MessageBox ("Get Next UID Error", "An error occurred while trying to "       + &
                        "get the next UID for the table ~"" + as_tablename + "~".~r~n "  + &
                        "~r~n sqlErrCode:  " + string (sqlca.sqlCode)                         + &
                        "~r~n sqlErrText:  " + sqlca.sqlErrText, StopSign!)
        al_uid = 0
        GOTO GOT_UID
    END IF


    CLOSE my_cursor ;



Thank You,

Olan

 

Accepted Answer
Arnd Schmidt Accepted Answer Pending Moderation
  1. Tuesday, 26 January 2021 15:13 PM UTC
  2. PowerBuilder
  3. # Permalink

If the ";" causes the error, why not just type the SQL Statement without the ";" at the end

 ls_sql = 'SELECT MAX (' + ls_pk_column + ') FROM ' + as_tablename

hth

Arnd

 

Comment
  1. Olan Knight
  2. Tuesday, 26 January 2021 15:45 PM UTC
Thank you, Arnd!

I removed the ";" from the end and it worked like a champ!



Later -
  1. Helpful
  1. Kevin Ridley
  2. Tuesday, 26 January 2021 18:50 PM UTC
If you added using SQLCA then you'd need the ;
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Tuesday, 26 January 2021 01:31 AM UTC
  2. PowerBuilder
  3. # 1

Hi, Olan -

Maybe you've disparaged Oracle in the past and the server got wind of it?wink It wouldn't surprise me.

I'm sorry I can't offer anything more helpful - I've managed to stay Oracle ignorant my entire career and hope to retire in the same condition.

Good luck! John

Comment
  1. Olan Knight
  2. Tuesday, 26 January 2021 14:12 PM UTC
Heh, maybe so.

Thanks anyway, John!



Olan
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.