i've been stuck with this error for a while, could you help me with this?
This's the code i'm trying to run:
CREATE OR REPLACE TRIGGER set_gal_trig
BEFORE INSERT ON MEDIA_CONTENUTI
FOR EACH ROW
DECLARE
tipo_coll VARCHAR2(15);
user2 VARCHAR2(30);
user1 VARCHAR2(30);
BEGIN
SELECT C.Tipo INTO tipo_coll FROM Collezione C WHERE :new.Cod_Collezione = C.Cod_Collezione;
SELECT C.Nome_Utente INTO user1 FROM Collezione C WHERE :new.Cod_Collezione = C.Cod_Collezione;
SELECT M.Nome_Utente INTO user2 FROM Media M WHERE :new.Cod_Media = M.Cod_Media;
IF (tipo = 'SET' AND user1 <> user2)
THEN
Raise_application_error(-20075, 'Inserimento non valido, un SET puo contenere solo media appartenenti al proprietario');
ELSIF (tipo = 'GALLERIA' AND user1= user2)
THEN
Raise_application_error(-20076, 'Inserimento non valido, una GALLERIA puo contenere solo media non appartenenti al proprietario');
END IF;
END;
The error is: Error at line 9: PL/SQL: Statement ignored. Thanks for the help!
Without the full error stack, the obvious error is in line 9 as the top-level error message says (where line numbers are counted only within the PL/SQL part of the statement, not the first three non-PL/SQL lines):
IF (tipo = 'SET' AND user1 <> user2)
You don't have a variable called tipo, so this should be:
IF (tipo_coll = 'SET' AND user1 <> user2)
...
ELSIF (tipo_coll = 'GALLERIA' AND user1= user2)
Related
here i'm trying to create a sort of a boolean function but when i try to compile it, it says me that my instruction "truth INTEGER;" is not correct. I can't figure out where does the problem come from because every code sample that i've seen on Google is quite similar to mine. Using Oracle is totally new for me so i'm kinda lost if someone is okay to help me...
I tried a lot of things by searching but nothing works so i'm here to ask for some help...
CODE:
CREATE OR REPLACE FUNCTION HISTOTOX.matching_idipl (iDiplNumero INTEGER) RETURN INTEGER
AS
cpt INTEGER;
truth INTEGER;
BEGIN
SELECT count(*) INTO cpt FROM GARNUCHE.INSC_DIPL WHERE IDIPL_NUMERO = iDiplNumero;
IF cpt = 1 THEN
truth := 1;
ELSE
truth := 0;
END IF;
RETURN truth;
END;
What you reported isn't Oracle error. I replicated your code in my 11g and everything works just fine:
SQL> CREATE OR REPLACE FUNCTION matching_idipl (iDiplNumero INTEGER) RETURN INTEGER
2 AS
3 cpt INTEGER;
4 truth INTEGER;
5
6 BEGIN
7 SELECT count(*) INTO cpt FROM INSC_DIPL WHERE IDIPL_NUMERO = iDiplNumero;
8 IF cpt = 1 THEN
9 truth := 1;
10 ELSE
11 truth := 0;
12 END IF;
13 RETURN truth;
14 END;
15 /
Function created.
SQL> select matching_idipl(1) from dual;
MATCHING_IDIPL(1)
-----------------
1
SQL>
So: where exactly did you execute that code? Which error did you get (exact message and error code, please)?
I get this error
23/112 PL/SQL: ORA-00920: invalid relational operator
It's pointing to AND CURRENT OF statement..
CREATE OR replace PROCEDURE alga_uz_pasirodyma(grupe_id in grupes.id%TYPE, alga in out number)
IS
v_kliento_id nariai.asm_kodas%TYPE;
TYPE bendras IS RECORD (
alga number
);
globalus bendras;
CURSOR c_klientai IS
SELECT nariai.asm_kodas
FROM nariai
where nariai.fk_grupe = grupe_id
FOR UPDATE OF nariai.alga;
BEGIN
globalus.alga:= alga;
IF grupe_id <= 0 THEN
raise_application_error(-20101, 'Nepavyko surasti grupes');
END IF;
OPEN c_klientai;
LOOP
FETCH c_klientai INTO v_kliento_id;
EXIT WHEN c_klientai%NOTFOUND;
UPDATE nariai set nariai.alga = nariai.alga * globalus.alga where nariai.asm_kodas = v_kliento_id AND CURRENT OF c_klientai;
END LOOP;
UPDATE grupes set grupes.pasirodymu_kiekis = grupes.pasirodymu_kiekis + 1 where grupes.id = grupe_id;
SELECT max(nariai.alga) into alga from nariai where nariai.fk_grupe = grupe_id;
CLOSE c_klientai;
END alga_uz_pasirodyma;
What should I do? I believe everything is declared correctly in the where statement..
"CURRENT OF" should be by itself in the where clause. It allows you to update or delete the record at the current loop iteration of the cursor.
On a different note, I don't see you doing anything significant in the loop to warrant a cursor. Ignore this note if that will change, otherwise just run the update "where nariai.fk_grupe = grupe_id"
How can I resolve the first comma? There is a syntax error.
if (#BAAgtNo = '0000ZV') and
(#ProfileNumber = '902876'***,*** '903673', '903674', '903675', '903676', '903677', '903678', '903679') -- If the booking agent result is 0 then..
begin
I think you want IN:
if #BAAgtNo = '0000ZV' and
#ProfileNumber in ('902876', '903673', '903674', '903675', '903676', '903677', '903678', '903679') -- If the booking agent result is 0 then..
begin
I am trying to run a query for liquibase update and I have a PLSQL block in there, the block has over 500 lines so I only post a few lines where the error is happening for now.
BEGIN
IF NOT EXISTS(select 1 from "public"."eod_report" where "id" = NEW."id") THEN
-- LOADING STRUCTURE SECTION
select "id" into NEW.organization_unit_id from organization_unit where site_id = NEW.organization_unit_id;
orgUnitId := CAST(NEW.organization_unit_id as int8);
--INSERT
IF (NEW.transactions_count is NULL) THEN
NEW.transactions_count := 0;
END IF;
IF (NEW.total_sales is NULL) THEN
NEW.total_sales := 0;
END IF;
INSERT INTO "public"."eod_report"("id",batch,total_sales,transactions_count,organization_unit_id,pos_total_sales,pos_transactions_count,pos_total_points,total_points,transaction_date)
VALUES (NEW."id",NEW.batch,NEW.total_sales,NEW.transactions_count,orgUnitId,NEW.pos_total_sales,NEW.pos_transactions_count,NEW.pos_total_points,NEW.total_points,NEW.transaction_date);
-- updates delay transaction or each batch
select max(id) into lastEodId from "public"."transaction" where transaction_type = 4 and org_unit_id = orgUnitId and id < ;NEW."id";
for eodRow IN
select count(case when transaction_type = 3 then -1 else 1 end) as trCount,sum(case when report_prefix = true then points else -points end) as ptSum,sum(case when report_prefix = true then amount else -amount end) as trSum, batch as trBatch from "public"."transaction"
where id > ;lastEodId and id < ;NEW."id" and report_prefix is not null and org_unit_id = orgUnitId
and batch < ;NEW.batch group by batch
LOOP
UPDATE "public"."eod_report" SET delayed_points =
(delayed_points + eodRow.ptSum),former_delayed_sales =
END LOOP;
END IF;
RETURN NULL;
And I am getting this error when I try to execute the query:
ERROR:
syntax error at or near ";"
LINE 453: ..._type = 4 and org_unit_id = orgUnitId and id < ;NEW."id";
^
SQL state: 42601
Character: 15018
there is a screenshot where the error is highlighted
Looks like the < and > chars are replaced with < ; so the syntax is incorrect.
fix the SQL by replacing all < ; with < to have
... org_unit_id = orgUnitId and id < NEW."id";
Also > ; must be replaced with >
It could happens e.g. because of URL encoding of text sent from UI (browser)
You find the same problem in multiple parts of your query, because HTML entities like "< ;" and "> ;" are not legal in an SQL query, which the error points to. You should change them to "<" and ">" accordingly.
I am trying to create a script that will allow the user to select which CASE population to use from an ACCEPT when gathering student contact info.
PROMPT 'Select a popluation for emails'
PROMPT '1. Currently registered'
PROMPT '2. New Applicants'
PROMPT
ACCEPT cnt number PROMPT 'Selection: ';
...
CURSOR stu_lst IS
CASE &cnt
WHEN 1 THEN -- Current registered students.
select distinct SFRSTCA_PIDM pidm
from SFRSTCA
where SFRSTCA_TERM_CODE = '201403' and
SFRSTCA_LEVL_CODE = '01' and
SFRSTCA_RSTS_CODE = 'RE';
WHEN 2 THEN -- New applicants
select app_pidm pidm
from app
where app_term = 'Fall 2014';
ELSE
-- Incorrect selection.
DBMS_OUTPUT.PUT_LINE('Incorrect selection made.');
exit;
END;
END;
Assuming the two queries return the same data type, you could use a union with a filter that checks the variable in each part; something like:
DECLARE
CURSOR stu_lst IS
-- Current registered students.
select distinct SFRSTCA_PIDM pidm
from SFRSTCA
where &cnt = 1 and
SFRSTCA_TERM_CODE = '201403' and
SFRSTCA_LEVL_CODE = '01' and
SFRSTCA_RSTS_CODE = 'RE';
UNION ALL
-- New applicants
select app_pidm
from app
where &cnt = 2 and
app_term = 'Fall 2014';
invalid_argument EXCEPTION;
...
BEGIN
IF &cnt NOT IN (1, 2) THEN
RAISE invalid_argument;
END IF
FOR rec IN stu_lst LOOP
h_pidm := rec.pidm;
...
END LOOP;
EXCEPTION
WHEN invalid_argument THEN
dbms_output.put_line('Incorrect selection made.');
END;
/
You could also declare a cursor variable and open that with the appropriate query, inside a case statement within the main body of the block. This sticks with your explicit cursor syntax though.