I am trying to run insert-select query. But whatever I do, I get "Invalid Number" error.
My query is like this;
INSERT INTO banka_odeme (banka_id, banka_ad, banka_tutar, aciklama, banka_ismi)
SELECT
(SELECT MAX(banka_id) + 1 FROM banka_odeme),
w.first_name || ' ' || w.last_name,
TO_NUMBER(w.total),
TO_NUMBER(w.id),
'SiPay'
FROM
woo_orders w
WHERE
NOT EXISTS (SELECT 1 FROM banka_odeme WHERE banka_odeme.aciklama = TO_NUMBER(w.id));
My table structure is like this; (Please check the image links below)
Thanks in advance to anyone who tries to help :))
I've tried every possible query combinations and it still gives the same error. :(
w.totalandw.idare already numbers - don't useTO_NUMBERon them.(SELECT MAX(banka_id) + 1 FROM banka_odeme)to generate the next number in a sequence, use a properSEQUENCE.banka_odeme.aciklamais a string andw.idis a number. When you compare them either convert the string to a numberTO_NUMBER(banka_odeme.aciklama) = w.id(but if it's always convertible to a numeric then why are you storing it as a string) or convert the number to a stringbanka_odeme.aciklama = TO_CHAR(w.id).MERGEstatement.So:
Then:
fiddle