Trying to run Oracle Stored Procedure Results in: ORA-00900: invalid SQL statement - dbeaver

How can I run the following code in DBEAVER? It will not execute the stored procedure and I have been told the code is OK to execute in SQL+ and Toad.
set serveroutput on;
set autoprint on;
var x0 refcursor;
var x1 refcursor;
exec pkg_organisation.p_list_org_by_uuid(123456, :x0, :x1);
I asked a DB dev to run this in toad, I dont have a licence and the procedure works as expected, but I would like to run this in DBEAVER.
With the set statements left in I get the following error:
SQL Error [922] [42000]: ORA-00922: missing or invalid option
Error : 922, Position : 4, Sql = set serveroutput on, OriginalSql = set serveroutput on, Error Msg = ORA-00922: missing or invalid option
ORA-00922: missing or invalid option
And if I remove these (as it appears this is what DBEAVER complains about), I get the following error:
SQL Error [900] [42000]: ORA-00900: invalid SQL statement
Error : 900, Position : 0, Sql = var x0 refcursor, OriginalSql = var x0 refcursor, Error Msg = ORA-00900: invalid SQL statement
ORA-00900: invalid SQL statement
I am using the Execute Script option to try to run the stored procedure and I would like to be able to get up and running with testing the procedures.

Related

Writing a for-loop using psql

I am trying to run a for loop via psql command in Linux to do some spatial operations in PostGIS database
My SQL command which I successfully ran in dbeaver looks something like this
DO $$
declare
the_name varchar(50);
BEGIN
FOR the_name IN
SELECT "name" FROM myschema.mytable WHERE "idcolumn" = 'selected id' LIMIT 4
LOOP
some operations inside the loop...
END LOOP;
RAISE NOTICE 'the name - (%)', the_name;
END;
$$;
I usually copy-paste the dbeaver SQL command inside psql -c and it runs fine. But I am getting a syntax error when using the above code. I am a beginner in SQL and any help is appreciated. Thanks.
Edit
This is the error message - it's weird because I don't have this number in the code. It's probably reading from memory or something.
ERROR: syntax error at or near "377643"
LINE 1: DO 377643 declare the_name varchar(50); BEGIN FOR the_...

why does this DO block have "syntax error near declare" in pgagent?

I have the following code:
DROP TABLE IF EXISTS pltest;
CREATE TABLE pltest (x jsonb);
DO $$
DECLARE startdate text := to_char(current_date - 1, 'YYYYMMDD');
BEGIN
EXECUTE format(
'COPY pltest FROM PROGRAM ''curl "https://example.com/events/start_date=%sT000000Z"''',
startdate
);
END
$$ ;
It basically imports the URL with a parameterized COPY statement so it always imports the data of the last 24 hours, it runs perfectly in SQL shell, but when i tried adding a pgagent job with that code, pgagent returns "syntax error near DECLARE".
PostgreSQL version: 13.3
PgAgent version: 13
This code looks correct. It fails with expected error.
ERROR: invalid input syntax for type json
DETAIL: Token "<" is invalid.
CONTEXT: JSON data, line 1: <...
COPY pltest, line 1, column x: "<!doctype html>"
SQL statement "COPY pltest FROM PROGRAM 'curl "https://example.com/events /start_date=20210526T000000Z"'"
PL/pgSQL function inline_code_block line 5 at EXECUTE
Maybe your client breaks source code, or maybe your Postgres is too old.

Attempting to run a query and set the count to a low number

PostgreSQL syntax problem.
Query below will run but result is:
ERROR: out of memory for query result
SELECT
AD.ADDRESS_DETAIL_PID as ADDRESS_DETAIL_PID,
AD.STREET_LOCALITY_PID as STREET_LOCALITY_PID,
AD.LOCALITY_PID as LOCALITY_PID,
AD.BUILDING_NAME as BUILDING_NAME
When the query is amended to:
set FETCH_COUNT=1000
SELECT
AD.ADDRESS_DETAIL_PID as ADDRESS_DETAIL_PID,
AD.STREET_LOCALITY_PID as STREET_LOCALITY_PID,
AD.LOCALITY_PID as LOCALITY_PID,
AD.BUILDING_NAME as BUILDING_NAME
the result is:
ERROR: syntax error at or near "SELECT" LINE 3: SELECT
^ SQL state: 42601 Character: 23
except that when a colon ; is included at the end the rssult is:
ERROR: unrecognized configuration parameter "fetch_count" SQL state:
42704
I am seeking help with the syntax.
FETCH_COUNT is a psql interval variable and is not executed on the server.
SET is a SQL command that's executed on the server and cannot be used for setting psql internal variables. use \set instead.
\set FETCH_COUNT 1000

PostgreSQL JDBC execute PL/pgSQL

While trying to run PL/pgSQL via JDBC driver (postgresql-9.4.1211.jre7.jar; using ANT) I get following error: ERROR: syntax error at or near "$"
Is there any way howto fix this via setting JDBC properties or changing the query of PL/pgSQL?
query:
DO $$
BEGIN
CREATE SEQUENCE id_sequence_SEQ OWNED BY id_sequence.id;
EXCEPTION WHEN duplicate_table
THEN
END
$$
LANGUAGE plpgsql;
error:
org.postgresql.util.PSQLException: ERROR: syntax error at or near "$"
Position: 5
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2458)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2158)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:291)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:432)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:358)
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:305)
at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:291)
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:269)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:265)
I tried executing a DO statement with JDBC and it works just fine.
There must be something weird in your statement. Try and log the statement by setting log_min_error_statement and log_min_messages to error. Execute the statement, then look at the message in the PostgreSQL log file. It should contain the statement that was actually executed. Examine it for weird characters and other strangeness.
Please also note that there is a syntax error in you PL/pgSQL: there must be something between THEN and END. For a no-op, use the statement NULL;.

Issue Creating a trigger on MySQL Ver 14.14 Distrib 5.5.44

For the life of me I can't see to find out what's wrong with the syntax of this trigger. MySQLworkbench says i'm missing a semicolon at the end of the first SET command but added another doesn't help. Here is the sql:
create trigger insert_user_trigger
before insert
on ds_users
for each row
BEGIN
IF (char_length(new.FirstName) + char_length(new.LastName)) <= 20 THEN
set new.Username = concat(new.FirstName,'.',new.LastName);
ELSE
set new.Username = concat(LEFT(new.FirstName,1),'.', LEFT(new.LastName,18));
ENDIF;
END;
What I'm trying to accomplish is build the username column value from the first and last name column. However, the "First.Last" combination can't exceed 20 characters. So I want to just go ahead and use the first char of the firstname, the "." and up to 18 chars of the last name if the total exceeds 20 chars.
The output from running the create via the mysql command line interface:
mysql> create trigger insert_user_trigger
-> before insert
-> on ds_users for each row
-> BEGIN
-> IF (char_length(new.FirstName) + char_length(new.LastName)) <= 20 THEN SET new.Username = concat(new.FirstName,'.',new.LastName);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 5
mysql> ELSE SET new.Username = concat(LEFT(new.FirstName,1),'.', LEFT(new.LastName,18));
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ELSE SET new.Username = concat(LEFT(new.FirstName,1),'.', LEFT(new.LastName,18)' at line 1
mysql> ENDIF;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ENDIF' at line 1
mysql> END;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'END' at line 1