Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
Is the usage of CASE wrong in the code below?
I am getting an error:
"PLS-00103: Encountered the symbol ";" when expecting one of the
following:
case The symbol "case" was substituted for ";" to continue. "
Code is :
create or replace PROCEDURE MIK_3PL_ITEM_ERRORS_PROC_1 IS
i_error_code varchar2(5);
i_desc varchar2(200);
CURSOR c_3pl_error IS
SELECT mie.client_item_id, mie.message_id,
mie.error_desc, mis.process_flag
FROM mik_3pl_item_error_etl mie,
dummy_staging mis
WHERE mie.client_item_id = mis.client_item_id
AND mie.message_id = mis.message_id;
BEGIN
dbms_output.put_line ('hello');
for i in c_3pl_error
loop
dbms_output.put_line ('in loop');
DECLARE
-- L_relations_exist VARCHAR2(1);
L_error_message VARCHAR2(255) := NULL;
L_return BOOLEAN := FALSE;
BEGIN
select error_code
into i_error_code
from mik_3pl_error_desc
where description = i.error_desc;
-- dbms_output.put_line(i_error_code);
CASE i_error_code
WHEN 'E2' THEN dbms_output.put_line ('in case');
END; -- end of CASE */
END; /*End of begin */
end loop;
END MIK_3PL_ITEM_ERRORS_PROC_1;
It needs to be:
...
CASE i_error_code
WHEN 'E2' THEN dbms_output.put_line ('in case');
END CASE; -- end of CASE */
END;
It's trying to treat the END; as the end of the block - matching that END with the BEGIN - and it knows the case is still open.
The documentation for the CASE statement shows that. (Not to be confused with a CASE expression, which does just have END. Ahem. Thank you Nicholas!)
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
In my for loop I used break statement to break loop after some match. But when I compile my code I got error for break:
Error: Illegal expression
Could you help me? I should add some unit?
for i:=0 to length(carsList)-1 do
begin
if numer <> carsList[i].numer then
begin
tmpKw2 := carsList[i].rectangleRotate(carsList[i].angle);
if((polyLine(tmpKw2,linia.p1.x,linia.p1.y,linia.p2.x,linia.p2.y))) then
begin
kolizja := true;
break:=true;
maxV := carsList[i].v;
Break;
end;
end;
end;
The code below works for me:
program Testbreak;
procedure TestBreakInFor;
var
i : Integer;
begin
for i := 0 to 10 do begin
if Odd(i) then
Break;
end;
end;
begin
TestBreakInFor;
readln;
end.
The reason you are getting the "Illegal expression" error is that you are attempting to use Break as if it were a variable (Break := True) when it is not, it is an execution flow-control instruction, like Continue. Omit the := True and it should compile corrrectly.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Hey Im Looking at this Triggers for hours now can someone help me ?
These Triggers Are for a Database appenrently . I made sure all those tables exist.S
create or replace TRIGGER postleizahl_check
BEFORE
INSERT or UPDATE on Kunden
FOR EACH ROW
BEGIN
DECLARE PLZ varchar(5) ;
SET PLZ := (Select PLZ from PLZVERZEICHNIS where Ort = new.Ort) ;
if :new.Postleitzahl = PLZ then
INSERT INTO Kunden (KUNDEN_NUMMER,NACHNAME, VORNAME, STRAßE , POSTLEITZAHL, HAUSNUMMER,ORT )
VALUES (new.KUNDEN_NUMMER,new.NACHNAME,new.VORNAME, new.STRAßE ,new.POSTLEITZAHL, new.HAUSNUMMER,new.ORT );
else
RAISE_APPLICATION_ERROR
(-20001, 'PLZ Exestiert nicht. ');
end if ;
end;
CREATE OR REPLACE TRIGGER nachbestellen
AFTER INSERT ON Bestellungen
For Each Row
BEGIN
if Bestellungen.Datum = GETDATE THEN
INSERT INTO LIEFERANTENBESTELLUNG(Artikel_Nummer,LIEFERANTEN_NUMMER,DATUM,Artikel_Name)
VALUES(new.Artikel_Nummer,new.Artikel_Namen,new.DATUM,new.LIEFERANTEN_NUMMER);
END IF ;
END;
Your declare statement must come before your begin, and 'set' is a SQL*Server construct, not Oracle. All of your 'new' should be prefixed with a colon (:);
Additional comment: varchar is a valid type, but in Oracle you should be using varchar2. Currently they work the same way in Oracle, but Oracle reserves the right to change it in the future, most likely to conform to the ANSI standard for varchar.
CREATE OR REPLACE TRIGGER postleizahl_check
BEFORE INSERT OR UPDATE
ON kunden
FOR EACH ROW
DECLARE
plz VARCHAR (5);
BEGIN
plz := (SELECT plz
FROM plzverzeichnis
WHERE ort = :new.ort);
IF :new.postleitzahl = plz
THEN
INSERT INTO kunden (
kunden_nummer, nachname, vorname
, straße, postleitzahl, hausnummer
, ort
)
VALUES (
:new.kunden_nummer, :new.nachname, :new.vorname
, :new.straße, :new.postleitzahl, :new.hausnummer
, :new.ort
);
ELSE
raise_application_error (-20001, 'PLZ Exestiert nicht. ');
END IF;
END;
CREATE OR REPLACE TRIGGER nachbestellen
AFTER INSERT
ON bestellungen
FOR EACH ROW
BEGIN
IF bestellungen.datum = getdate
THEN
INSERT INTO lieferantenbestellung (
artikel_nummer, lieferanten_nummer, datum
, artikel_name
)
VALUES (
:new.artikel_nummer, :new.artikel_namen, :new.datum
, :new.lieferanten_nummer
);
END IF;
END;
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I'm looking for a way to return one case-insensitive varchar2 from a table given as a parameter.
The database is configured to have as the first column the one I'll look into.
This is what I got to:
create or replace function generic_return(nam varchar2, table_n varchar2)
return varchar2
as
case_insensitive varchar2(300);
case_ins varchar2(300);
colu varchar2(30);
t_nam varchar2(30):=upper(table_n);
cursor point is execute inmediate select colu from t_nam;
cursor col is select column_name from cols where table_name=t_nam;
non_existent_table exception;
begin
case_ins:=upper(rtrim(ltrim(nam)));
open col;
fetch col into colu;
close col;
select column_name from cols where table_name=upper(table_n);
if colu is null then
raise non_existent_table;
end if;
open point;
loop
fetch point into case_insensitive;
exit when point%notfound;
if upper(case_insensitive)=case_ins then
return case_insensitive;
end if;
end loop;
close point;
return null;
end;
/
The function receives what to look for, and the name of the table to look into, then the first variables are to compare them, t_nam is to use the uppercased version of the second parameter... and from that there's the huge mess: I get the column name from the table in col, from cols, and then I try to make a cursor that goes around checking if what the tuple, going by the same modifications, is the first parameter, or not, if it happens to be, then it should return the unmodified version of the one in the table. Otherwise, it should return "null", which I'll treat differently on each procedure that uses it.
By null I mean nothingness, not the string.
Yes, you are right. That's a pretty huge mess. :-)
For starters, you cannot declare an explicit cursor as an execute immediate statement.
Next, if you want the first column in the table, you need to specify
WHERE column_id = 1
and then you can just grab it via a SELECT-INTO, no need for an explicit cursor.
Then you could try something like:
my_cur SYS_REFCURSOR;
BEGIN
...
OPEN my_cur FOR 'SELECT ' || first_col || ' FROM ' || t_name;
LOOP
FETCH my_cur INTO case_insensitive;
EXIT WHEN my_cur%NOTFOUND;
... logic for match ....
END LOOP;
CLOSE my_cur;
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I need to extract last day of a specific week of the year. For example the last day of the 51st week of 2013.
I need a PL/SQL Procedure/Function which can do that.
Assuming LAST DAY in a week is 'SUNDAY'
A PL/SQL Function!
CREATE OR REPLACE FUNCTION GET_LAST_DATE_IN_WEEK( p_WEEK INTEGER, p_YEAR INTEGER)
RETURN DATE
IS
v_DATE DATE := NULL;
BEGIN
IF(p_WEEK IS NULL OR p_YEAR IS NULL) THEN
-- Handle the data validation here
v_DATE := NULL;
RETURN v_DATE;
END IF;
v_DATE := next_day(TRUNC(to_date(p_YEAR,'YYYY'),'YYYY')+(p_WEEK-1)*7,'SUNDAY');
IF TO_CHAR(v_DATE,'YYYY') > p_YEAR THEN
v_DATE := LAST_DAY(to_date('12'||p_YEAR,'MMYYYY'));
END IF;
RETURN v_DATE;
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Error in GET_LAST_DATE_IN_WEEK : '||SQLERRM);
RETURN NULL;
END GET_LAST_DATE_IN_WEEK;
/
You invoke it this way!
SELECT GET_LAST_DATE_IN_WEEK(51,2013) FROM DUAL;
Good Luck!
This should be possible with dbms_scheduler:
declare
result_ date;
begin
dbms_scheduler.evaluate_calendar_string (
calendar_string => 'FREQ=YEARLY; BYWEEKNO=51; BYDAY=sun',
start_date => date '2013-01-01',
return_date_after => date '2013-01-01',
next_run_date => result_);
dbms_output.put_line(' Sunday of 51st week in 2013: ' || result_);
end;
/
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
By using the bulk collect into, how you can detect when a query that does not return results to prevent an exception is thrown when trying to loop through the results?
An example from documentation:
http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/tuning.htm#BABCCJCB
OPEN c1;
LOOP
FETCH c1 BULK COLLECT INTO names, sals LIMIT v_limit;
EXIT WHEN names.COUNT = 0;
print_results();
END LOOP;
CLOSE c1;
You can use this code:
open rc for select descr from hardware;
loop
fetch rc bulk collect into l_rows limit l_fetch_sizes(i);
exit when rc%notfound;
end loop;
close rc;
Exit When finalize the loop.
To catch exception for bulk collect DML operations you could you SQL%BULK_EXCEPTIONS:
BEGIN
-- DML operations
EXCEPTION
WHEN operation_erros THEN
l_error := SQL%BULK_EXCEPTIONS.count;
FOR ind IN 1 .. l_error LOOP
DBMS_OUTPUT.put_line('Error: ' || ind || ' Array Index: ' || SQL%BULK_EXCEPTIONS(ind).ERROR_INDEX || ' Message: ' || SQLERRM(-SQL%BULK_EXCEPTIONS(ind).ERROR_CODE));
END LOOP;
END;