Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt5 QSqlDatabase: read PL/SQL variable from oracle
Forum Updated to NodeBB v4.3 + New Features

Qt5 QSqlDatabase: read PL/SQL variable from oracle

Scheduled Pinned Locked Moved Unsolved General and Desktop
qsqldatabaseoraclevariablesql
2 Posts 2 Posters 2.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hans Hupe
    wrote on 25 Nov 2015, 07:42 last edited by
    #1

    I want to execute the following PL/SQL block in my Qt-code using a QSqlDatabase connection to an oracle database.

    DECLARE
    var_id NUMBER;
    BEGIN
    INSERT INTO TEST_TABLE(NAME)
    VALUES('TEST') RETURNING ID INTO var_id;
    END;

    The statement inserts a value into the PL/SQL variable 'var_id'. After executing the statement I want to read the value of 'var_id' in Qt, but it doesn't work. Any ideas how to read a PL/SQL variable with QSqlDatabase? Thanks!

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mjsurette
      wrote on 19 Dec 2015, 16:55 last edited by
      #2

      I'm not familiar with Oracle, but this looks close enough to Postgresql that I'll show how I would do it in PG/SQL in hopes that it will be useful.

      I would create the function in the database

      CREATE OR REPLACE FUNCTIOM test_fucntion(_name TEXT)
      RETURNS BIGINT AS $BODY$
      DECLARE
      _rv BIGINT
      BEGIN
      INSERT INTO test_table(name)
      VALUES(_name) RETURNING id into _rv;
      RETURN _rv;
      END;
      $BODY$
      LANGUAGE plpgsql;

      After adding that function to the database you can simply execute the query
      SELECT * from test_function("name");
      to get your ID.

      As I said, this is Postgres code, but I'm pretty sure the Postgres authors imitated Oracle to some extent.

      Mike

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved