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 ''.
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?
Last two line show error .MY sqlwork bench show syntax error in last two line Limit 1
End
trying to run Database procedures.Error code Error 1064 you have error in Mysql bench syntax
CREATE PROCEDURE `xyz_Get`(
IN pPlaceId BIGINT,
IN pSwitchedCompanyId BIGINT,
IN pRequestedBy BIGINT
)
BEGIN
SELECT
`PlaceId`,
`CategoryCode`,
`CategoryName`,
`Description`,
`ParentCategoryId_FK`,
`ModuleId_FK`,
`LanguageId_FK`,
`CompanyId_FK`,
`OwnerCompanyId_FK`,
`IsDeleted`,
`IsArchived`,
`CreatedDate`,
`ModifiedDate`,
`CreatedBy_FK`,
`ModifiedBy_FK`
FROM `xyz_Place`
WHERE
`PlaceId` = pPlaceId AND
(
`CompanyId_FK` = pSwitchedCompanyId OR
`OwnerCompanyId_FK` = pSwitchedCompanyId
)
AND `IsDeleted` = 0
LIMIT 1;
END
oracle query This works
select *
from (
select to_number(substr(app_cluster,6,2), '99') as b
from xtern_app_info
WHERE app_cluster IS NOT NULL
AND APP_CLUSTER <> 'CLUSTER'
);
but when adding 'where b > 2' makes an error, why?
select *
from (
select to_number(substr(app_cluster,6,2), '99') as b
from xtern_app_info
WHERE app_cluster IS NOT NULL
AND APP_CLUSTER <> 'CLUSTER'
) where b > 2;
ORA-29913: error in executing ODCIEXTTABLEFETCH callout
ORA-01722: invalid number
29913. 00000 - "error in executing %s callout"
*Cause: The execution of the specified callout caused an error.
*Action: Examine the error messages take appropriate action.
I need to check if a record exists in the table or not from a SELECT statement. If the record exists, do an update otherwise create a record on the table. I'm trying to but i'm getting PLS-00103 error.
These are the errors that I'm getting when i run my code in DBVisaulzier:
18:00:09 [DECLARE - 0 row(s), 0.000 secs] [Error Code: 6550, SQL State: 65000] ORA-06550: line 2, column 12:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
:= . ( # % ; not null range default character
18:00:09 [BEGIN - 0 row(s), 0.000 secs] [Error Code: 6550, SQL State: 65000]
ORA-06550: line 2, column 97:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
;
18:00:09 [IF - 0 row(s), 0.000 secs] [Error Code: 900, SQL State: 42000] ORA-00900: invalid SQL statement
18:00:09 [ELSE - 0 row(s), 0.000 secs] [Error Code: 900, SQL State: 42000]
ORA-00900: invalid SQL statement
18:00:09 [END - 0 row(s), 0.000 secs] [Error Code: 900, SQL State: 42000] ORA-00900: invalid SQL statement
18:00:09 [END - 0 row(s), 0.000 secs] [Error Code: 900, SQL State: 42000] ORA-00900: invalid SQL statement
... 6 statement(s) executed, 0 row(s) affected, exec/fetch time: 0.000/0.000 sec [0 successful, 0 warnings, 6 errors]
The following is my code:
DECLARE a NUMBER;
BEGIN
SELECT 1
INTO a
FROM FREC_EMAIL t
WHERE t.FranchiseNo = '208254846'
AND t.ReportID = 1
AND t.id = 165;
IF a=1 THEN
UPDATE FREC_EMAIL
SET email = 'blah#foo.com'
WHERE FranchiseNo = '208254846'
AND ReportID = 1
AND ID = 165;
ELSE
INSERT INTO FREC_EMAIL
(FranchiseNo, Email, ReportID)
VALUES
('208254846', 'blah#foo.com', 1);
END IF;
END;
We should always use SQL whenever possible, and avoid using Pl/SQL unless it is strictly necessary. SQL statements perform faster, they usually require less typing and they are easier to get right.
Since 9i Oracle has provided MERGE, a single SQL statement which executes an "upsert" statement.
MERGE INTO frec_email t
USING (SELECT 'blah#foo.com' as email
, '208254846' as FranchiseNo
, 1 as ReportID
, 165 as ID
FROM dual ) s
ON (s.ID = t.ID)
WHEN MATCHED THEN
UPDATE SET t.email = s.email
WHEN NOT MATCHED THEN
INSERT (t.FranchiseNo, t.Email, t.ReportID)
VALUES (s.FranchiseNo, s.Email, s.ReportID)
/
In a pl/sql block, you can do this:
update table set column=....
where.....;
if SQL%ROWCOUNT = 0 THEN
insert......
END IF;
K
Use the MERGE command (also called upsert by some). Oracle's reference (with example) here.
On a side note, if you are new to Oracle, it is worth spending time getting to grips with the offical documentation. Although it might appear difficult where to start with it, Tom Kyte's Road Map is good place to get a list of must reads.
Good luck!
I usually use the following concept, which I think is more readable than merge::
BEGIN
UPDATE FREC_EMAIL
SET email = 'blah#foo.com'
WHERE FranchiseNo = '208254846'
AND ReportID = 1
AND ID = 165;
IF SQL%NOTFOUND THEN
INSERT INTO FREC_EMAIL
(FranchiseNo, Email, ReportID, ID)
VALUES
('208254846', 'blah#foo.com', 1, 165);
END IF;
END;