Select statement with array is throwing error - sql

This statement is throwing error:
FOR _i2 IN 1 .. array_upper(p_extra_info, 1) LOOP
....
SELECT currval('ad_extra_info_id_seq') INTO _new_extra_info_ids[_i2];
....
END LOOP;
ERROR: syntax error at or near "["
LINE 179: ...rrval('ad_extra_info_id_seq') INTO _new_extra_info_ids[_i2];
^
********** Error **********
ERROR: syntax error at or near "["
SQL state: 42601
Character: 7907
Variable _new_extra_info_ids is declared like this: _new_extra_info_ids integer[];
Do you know what is wrong?

Use a direct assignment instead of a select:
FOR _i2 IN 1 .. array_upper(p_extra_info, 1) LOOP
....
_new_extra_info_ids[_i2] := currval('ad_extra_info_id_seq');
....
END LOOP;

Related

Replace function not supporting for bigger text and text has single quote

this is the statement execute from SNowflake SP.
var sql_Statement = "select regexp_replace ('" + mainSIDColsSrc + "'', 'source_doc:','') " ;
form the query like this :
select regexp_replace ('(trim(NVL(SOURCE_DOC:claimNumber::string,'~')) ||'^'|| trim(NVL(SOURCE_DOC:notificationType::string,'~')) ||'^'|| trim(NVL(SOURCE_DOC:estimateId::string,'~')) ||'^'|| trim(NVL(SOURCE_DOC:assignmentId::string,'~')))'', 'source_doc:','')
if run the above query :
SQL compilation error: syntax error line 1 at position 82 unexpected '~'. syntax error line 1 at position 153 unexpected '~'. syntax error line 1 at position 305 unexpected ':'. parse error line 1 at position 311 near ''.

Insert 0 values into Postgres: Numeric Field Error

I have a problem when inserting "0" value into numeric field in PostgreSQL via PHP.
insert into canalis_db.cor_cust_corp_fncl_rprt
(corp_fncl_rprt_id,
customer_id,
rprt_period,
asset) values(
'ca423557-7788-36e3-7788-d36f8c130a83',
'ca4160e2-0189-12b7-e6a6-635819ac9aa2',
'2020', 
0) 
it well show error message.
Error: ERROR: syntax error at or near "0"
Position: 395
SQLState: 42601
ErrorCode: 0
Is there something error in my sql syntax?

Syntax error near "," with postgres go lib pq

I try to create a simple insert statement and get the error:
pq: syntax error at or near ","
txn, err := db.Begin()
stmt, err := db.Prepare(`INSERT INTO advertiser_per_day (id,advertiser_name,additional,customer_id,site_id,tracking,counter,day,month,year) VALUES (?,?,?,?,?,?,?,?,?,?)`)
If I put the statement into a query tool for postgres all works fine...
Any ideas?
You should use ($n) instead of ? for the bound parameters.

`FOR UPDATE` breaks batch execution in HANA

HANA 102.05 fails to execute the following code:
CREATE TABLE ATABLE( f INT );
CREATE PROCEDURE TestProc()
AS
BEGIN
SELECT f FROM ATABLE
FOR UPDATE; -- Without FOR UPDATE it works
END;
SELECT 'Hello' FROM DUMMY;
complaining that:
SAP DBTech JDBC: [257]: sql syntax error: incorrect syntax near "SELECT": line 8 col 2 (at pos 124)
which points outside the proceudure, at SELECT 'Hello'. The procedure itself compiles without error. The entire script completes successfully if I remove the FOR UPDATE directive. What is wrong with the original?
Update
When I execute the same query from hdbsql.exe I get:
0 rows affected (overall time 26,076 msec; server time 6518 usec)
* 257: sql syntax error: line 5 col 9 (at pos 71) SQLSTATE: HY000
* 257: sql syntax error: incorrect syntax near "END": line 2 col 1 (at pos 32) SQLSTATE: HY000
'Hello'
"Hello"
1 row selected (overall time 4644 usec; server time 143 usec)

"PLS-00103: Encountered the symbol "END" when expecting one of the following: := . ( % ; The symbol ";" was substituted for "END" to continue. "

create or replace trigger employee_age_constraint
before insert on employee
for each row
begin
if floor(months_between(current_date,:New.employee_birthdate)/12) < 13 then
raise_application_error(123123, 'asf')
end if;
end;
I keep on getting this error with this code on Oracle SQL developer, i have no idea why, help please!
You have to insert ; after :
raise_application_error(123123, 'asf')
you must end your line with this.
have a good time.