I see the error but the account is valid - sql

SQL> CREATE or REPLACE FUNCTION custord (custNo IN number)
2 RETURN NUMBER
3 IS cust_tot NUMBER(11,2);
4 BEGIN
5 SELECT sum(cust_total_field)
6 INTO cust_tot
7 FROM ord
8 WHERE cust_number_field=custNo;
9 RETURN(cust_tot);
10 END;
11 /
Warning: Function created with compilation errors.
SQL> begin
2 dbms_output.put_line('customer 102 total is ' || custord(102));
3 end;
4 /
dbms_output.put_line('customer 102 total is ' || custord(102));
*
ERROR at line 2:
ORA-06550: line 2, column 52:
PLS-00905: object CIS605.CUSTORD is invalid
ORA-06550: line 2, column 3:
PL/SQL: Statement ignored
SQL>
I see the error but object cis605 is valid. Any ideas what I am missing?
Using the ORD table create a stored function called custord that will use a customer id (CUSTID) that will return the sum of the specified customer id TOTAL field.
When your function has been stored run the following SQL:
begin
dbms_output.put_line('customer 102 total is ' || custord(102));
end;
Your output should look like:
Results
Explain
Describe
Saved SQL
History
customer 102 total is 27775.5
Statement processed.

Try
SHOW ERRORS FUNCTION custord
Your custord function was created with compilation errors, so there is something wrong with it. This is why you're getting the object CIS605.CUSTORD is invalid error.

Related

Error: ORA-06550: line 7, column 21: PLS-00306: wrong number or types of arguments in call to 'PROD_ORDERED_FUNC'

just wanted to ask how to resolve the error above. I am trying to create a function that will generate how many product were ordered per product category.
Here is my function. The function compiled but when I try to run the declare part that's where I get the error.
DECLARE
CURSOR this_category IS
SELECT category_id
from comm_order_details;
prod_ordered comm_order_details.quantity%type;
BEGIN
For rec_category IN this_category
LOOP
prod_ordered := prod_ordered_func(rec_category.category_id);
DBMS_OUTPUT.PUT_LINE('Category ID:' || rec_category.category_id||'-' || 'Total Order:' || prod_ordered );
END LOOP;
END;
Try to run inner queries

Oracle function compiles successfully but throws error while executing PLS-00221: is not a procedure or is undefined

I have simple oracle function
create or replace function abs.test_func(test_in in number)
return number
is
test_out number ;
BEGIN
test_out:=test_in;
RETURN test_out;
END;
if I compile it - it compiles successfully.
but when I run from PLSQL Developer SQL Window
BEGIN abs.test_func(5); END;
it I gets the following errors
ORA-06550: line1, column8;
PLS-00221: 'TEST_FUNC' is not a procedure or is undefined
ORA-06550: line1, column8;
PL/SQL: Statement ignored
What's wrong with my function ?
Your create function code looks good, however you are not invoking the function properly. A function returns something, that you must either select, assign, print, or evaluate.
Here are a few examples of valid function calls:
-- print the return value
begin
dbms_output.put_line(test_func(5));
end;
/
1 rows affected
dbms_output:
5
-- select the return value
select test_func(5) from dual;
| TEST_FUNC(5) |
| -----------: |
| 5 |
Demo on DB Fiddle

PL SQL Loop Table after insert and update

I'm trying loop through a table called broker after an insert to a different table called appointment and update a value on the broker table this what i have. When i try to create the trigger it comes up with an error saying "Trigger created with compilation errors"
CREATE OR REPLACE TRIGGER broker_level_trigger
AFTER INSERT ON appointment
DECLARE
counter integer := 1;
BEGIN
for o in (SELECT * FROM broker)
loop
SELECT COUNT(appointment.broker_id) INTO app_number FROM appointment INNER JOIN broker ON broker.broker_id = appointment.broker_id WHERE broker.broker_id = counter;
IF app_number > 15 THEN
UPDATE broker SET broker_level = 'gold' WHERE broker_id = counter;
counter := counter + 1;
end loop;
end;
/
The broker table has a field called broker_level and it changes based on the appointments, i want it to change if the broker_id field on appointments gets to more then 15
show err is a wonderful thing. (I created dummy tables you use).
SQL> CREATE OR REPLACE TRIGGER broker_level_trigger
2 AFTER INSERT ON appointment
3 DECLARE
4 counter integer := 1;
5 BEGIN
6 for o in (SELECT * FROM broker)
7 loop
8 SELECT COUNT(appointment.broker_id)
9 INTO app_number
10 FROM appointment INNER JOIN broker
11 ON broker.broker_id = appointment.broker_id
12 WHERE broker.broker_id = counter;
13
14 IF app_number > 15 THEN
15 UPDATE broker SET
16 broker_level = 'gold'
17 WHERE broker_id = counter;
18 counter := counter + 1;
19
20 end loop;
21 end;
22 /
Warning: Trigger created with compilation errors.
SQL> show err
Errors for TRIGGER BROKER_LEVEL_TRIGGER:
LINE/COL ERROR
-------- -----------------------------------------------------------------
18/7 PLS-00103: Encountered the symbol "LOOP" when expecting one of
the following:
if
If you look closer, you'll see that IF misses its END IF. Let's add it:
SQL> CREATE OR REPLACE TRIGGER broker_level_trigger
2 AFTER INSERT ON appointment
3 DECLARE
4 counter integer := 1;
5 BEGIN
6 for o in (SELECT * FROM broker)
7 loop
8 SELECT COUNT(appointment.broker_id)
9 INTO app_number
10 FROM appointment INNER JOIN broker
11 ON broker.broker_id = appointment.broker_id
12 WHERE broker.broker_id = counter;
13
14 IF app_number > 15 THEN
15 UPDATE broker SET
16 broker_level = 'gold'
17 WHERE broker_id = counter;
18 counter := counter + 1;
19 END IF; --> missing
20 end loop;
21 end;
22 /
Warning: Trigger created with compilation errors.
SQL> show err
Errors for TRIGGER BROKER_LEVEL_TRIGGER:
LINE/COL ERROR
-------- -----------------------------------------------------------------
6/5 PL/SQL: SQL Statement ignored
7/12 PLS-00201: identifier 'APP_NUMBER' must be declared
8/7 PL/SQL: ORA-00904: : invalid identifier
12/5 PL/SQL: Statement ignored
12/8 PLS-00201: identifier 'APP_NUMBER' must be declared
APP_NUMBER is missing now; you use it, but never declared it. Let's do it now:
SQL> CREATE OR REPLACE TRIGGER broker_level_trigger
2 AFTER INSERT ON appointment
3 DECLARE
4 counter integer := 1;
5 app_number number; --> missing
6 BEGIN
7 for o in (SELECT * FROM broker)
8 loop
9 SELECT COUNT(appointment.broker_id)
10 INTO app_number
11 FROM appointment INNER JOIN broker
12 ON broker.broker_id = appointment.broker_id
13 WHERE broker.broker_id = counter;
14
15 IF app_number > 15 THEN
16 UPDATE broker SET
17 broker_level = 'gold'
18 WHERE broker_id = counter;
19 counter := counter + 1;
20 END IF; --> missing
21 end loop;
22 end;
23 /
Trigger created.
SQL>
That would be it.
If you don't use SQL*Plus but some other tool, you can always query user_errors:
Warning: Trigger created with compilation errors.
SQL> select line, position, text from user_errors where name = 'BROKER_LEVEL_TRIGGER' order by sequence;
LINE POSITION TEXT
----- --------- ------------------------------------------------------------
8 12 PLS-00201: identifier 'APP_NUMBER' must be declared
9 7 PL/SQL: ORA-00904: : invalid identifier
7 5 PL/SQL: SQL Statement ignored
13 8 PLS-00201: identifier 'APP_NUMBER' must be declared
13 5 PL/SQL: Statement ignored
SQL>

This is a procedure to update multiple table's data in oracle , as compiler is showing Error: ORA-00922: missing or invalid option error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
This is a procedure to update multiple table's data in oracle , do not know where i am getting wrong as compiler is showing Error: ORA-00922: missing or invalid option error please help
I have checked the syntax I think it is correct .
create or replace procedure add_Course(
p_title_name in course.tilte%type,
p_course_id in course.course_id%type,
p_credits in course.credits%type,
p_program_id in PROGRAMS.program_id%type,
p_grade in PROGRAMS.grade%type,
p_room_type in classroom.room_type%type,
p_room_no in classroom.room_no%type,
p_sec_id in section.sec_id%type,
p_semester in section.semester%type,
p_year in section.year%type,
p_building in section.building%type)
as
cnt number;
begin
select count(*) into cnt from course where title=p_title_name;
if cnt = 1 then
update course set credits=p_credits where title=p_title_name;
update program set program_id=p_program_id,semester=p_semester,year=p_year,grade=p_grade where course_id=p_course_id;
update classroom set room_type=p_room_tpe, room_no=p_room_no, building=p_building where COURSE_TYPE=p_course_type;
update section set sec_id=p_sec_id, semester=p_semestr, year=p_year,BUILDING=p_building,room_type=p_room_type where course_id=p_couse_id;
dbms_output.put_line('course detils is changed');
commit;
else
dbms_output.put_line('couser dose not exist');
end if;
end;
When the procedure is created (with errors), depending on tool you use, see errors. For example, in SQL*Plus:
SQL> create or replace procedure add_Course(
2 p_title_name in course.tilte%type,
3 p_course_id in course.course_id%type,
4 p_credits in course.credits%type,
5 p_program_id in PROGRAMS.program_id%type,
6 p_grade in PROGRAMS.grade%type,
7 p_room_type in classroom.room_type%type,
8 p_room_no in classroom.room_no%type,
9 p_sec_id in section.sec_id%type,
10 p_semester in section.semester%type,
11 p_year in section.year%type,
12 p_building in section.building%type)
13 as
14 cnt number;
15 begin
16 select count(*) into cnt from course where title=p_title_name;
17 if cnt = 1 then
18 update course set credits=p_credits where title=p_title_name;
19 update program set program_id=p_program_id,semester=p_semester,year=p_year,grade=p_grade where course_id=p_course_id;
20 update classroom set room_type=p_room_tpe, room_no=p_room_no, building=p_building where COURSE_TYPE=p_course_type;
21 update section set sec_id=p_sec_id, semester=p_semestr, year=p_year,BUILDING=p_building,room_type=p_room_type where course_id=p_couse_id;
22 dbms_output.put_line('course detils is changed');
23 commit;
24
25 else
26 dbms_output.put_line('couser dose not exist');
27
28 end if;
29 end;
30 /
Warning: Procedure created with compilation errors.
SQL> show err
Errors for PROCEDURE ADD_COURSE:
LINE/COL ERROR
-------- -----------------------------------------------------------------
0/0 PL/SQL: Compilation unit analysis terminated
2/20 PLS-00201: identifier 'COURSE.TILTE' must be declared
SQL>
Option that works everywhere is to select that info from user_erros:
SQL> select * from user_errors where name = 'ADD_COURSE';
NAME TYPE SEQUENCE LINE POSITION
------------------------------ ------------ ---------- ---------- ----------
TEXT
--------------------------------------------------------------------------------
ATTRIBUTE MESSAGE_NUMBER
--------- --------------
ADD_COURSE PROCEDURE 1 2 20
PLS-00201: identifier 'COURSE.TILTE' must be declared
ERROR 201
ADD_COURSE PROCEDURE 2 0 0
PL/SQL: Compilation unit analysis terminated
ERROR 0
SQL>
This should help you fix most errors. Say if there's any you don't understand or can't fix.
There was some syntax error ,
There are several typos in your code: p_semestr, p_couse_id, p_room_tpe. Certainly your code won't compile until you correct those to be the actual parameter names

Wrong number or type in a loop

getting this error:
ERROR at line 5:
ORA-06550: line 5, column 19:
PLS-00306: wrong number or types of arguments in call to 'DAYS'
So it's an issue with that bolded "days" ...why?
CREATE OR REPLACE
TYPE lyrics IS OBJECT
( date_name VARCHAR2(8)
, gift_name VARCHAR2(24));
/
DECLARE
TYPE days IS TABLE OF lyrics;
TYPE gifts IS TABLE OF lyrics;
lv_dates DAYS :=
**days**('first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth', 'tenth', 'eleventh', 'twelth');
That would be something like this; elements inside the array must be "objects", so you have to specify lyrics within the code:
SQL> create or replace
2 type lyrics is object
3 ( date_name varchar2(8)
4 , gift_name varchar2(24));
5 /
Type created.
SQL>
SQL> declare
2 type days is table of lyrics;
3 lv_dates days := days();
4 begin
5 lv_dates := days(lyrics('first', 'second'), lyrics('third', 'fourth'));
6 end;
7 /
PL/SQL procedure successfully completed.
SQL>