Oracle DBMS_SCHEDULER.DROP_JOB fails to drop a job - oracle11g

In Oracle 11g, I am trying to drop a job; but, it gives me the below error:
SQL> exec DBMS_SCHEDULER.DROP_JOB(job_name => "MyCaseSensitiveJobName");
BEGIN DBMS_SCHEDULER.DROP_JOB(job_name => "MyCaseSensitiveJobName"); END;
*
ERROR at line 1:
ORA-06550: line 1, column 44:
PLS-00905: object Job_Owner.MyCaseSensitiveJobName is invalid
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
Please help! Thanks!

For anyone interested, I found my mistake!
The below execution was successful:
SQL> exec DBMS_SCHEDULER.DROP_JOB(job_name => '"MyCaseSensitiveJobName"');
PL/SQL procedure successfully completed.
i.e. I should have wrapped the double-quoted job name in single qoutes!

Related

Getting error while assigning values to records inside collection

I need to loop through some values inside the plsql code.
so trying to create a collection of records .
getting error as mentioned below.
Please help me to resolve
-- please see the code below
declare
type tab_name is record (t_name varchar2(30),col_name varchar2(30));
type tab_list is table of tab_name;
table_names tab_list:=tab_list(tab_name('ABC','abc'),tab_name('XYZ','xyz'));
begin
for i in table_names.first..table_names.last loop
dbms_output.put_line(table_names(i).t_name||'-'||table_names(i).col_name);
end loop;
end;
/
Error report -
ORA-06550: line 4, column 32:
PLS-00222: no function with name 'TAB_NAME' exists in this scope
ORA-06550: line 4, column 13:
PL/SQL: Item ignored
ORA-06550: line 6, column 10:
PLS-00320: the declaration of the type of this expression is incomplete or malformed
ORA-06550: line 6, column 1:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
Record type's name is not its initializer.
In fact, there is no initialization-like function for record types at all in oracle:
Documentation
Note that values are assigned separately to each field of a record in
Example 5-47. You cannot assign a list of values to a record using an
assignment statement. There is no constructor-like notation for
records.
You have to create each object separately and then create collection with them:
declare
type tab_name is record (t_name varchar2(30),col_name varchar2(30));
type tab_list is table of tab_name;
name_1 tab_name;
table_names tab_list;
begin
name_1.t_name := 'ABC';
name_1.col_name := 'abc';
table_names := tab_list();
table_names.extend;
table_names(table_names.last) := name_1;
name_1.t_name := 'XYZ';
name_1.col_name := 'xyz';
table_names.extend;
table_names(table_names.last) := name_1;
for i in table_names.first..table_names.last
loop
dbms_output.put_line(table_names(i).t_name||'-'||table_names(i).col_name);
end loop;
end;
Collections DO have initializers. However, in your case you have a collection of record types, so you would have to have your records pre-created to make use of it.

How to fetch data in nested record in PL/SQL?

I was trying to work on nested record example.
Please have a look at declaration section.
DECLARE
TYPE r_emp IS RECORD (
name VARCHAR2(50),
dept_rec departments%ROWTYPE
);
r_emp_row r_emp;
BEGIN
SELECT emp.first_name||' '||emp.last_name,dept.*
INTO r_emp_row
FROM employees emp,departments dept
WHERE emp.department_id = dept.department_id
AND emp.employee_id = 100;
DBMS_OUTPUT.PUT_LINE('Name:'||r_emp_row.name);
DBMS_OUTPUT.PUT_LINE('Department ID:'||r_emp_row.dept_rec.department_id);
DBMS_OUTPUT.PUT_LINE('Department Name:'||r_emp_row.dept_rec.department_name);
EXCEPTION
when others then
null;
END;
I am trying to run above block but getting error as below:
Error report -
ORA-06550: line 10, column 8:
PLS-00597: expression 'R_EMP_ROW' in the INTO list is of wrong type
ORA-06550: line 11, column 3:
PL/SQL: ORA-00904: : invalid identifier
ORA-06550: line 9, column 3:
PL/SQL: SQL Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
Help appreciated.
Your record type r_emp is a composite of one scalar attribute and one record, so you will need to reflect that in the select into. Something like:
select emp.first_name||' '||emp.last_name, dept.*
into r_emp_row.name, r_emp_row.deptrec.dempno, r_emp_row.deptrec.dname ...
btw unrelated to the problem, when others then null is a famously dangerous construction:
What is bad in "When Others Then Null" in PL/SQL?
http://www.orafaq.com/wiki/WHEN_OTHERS
http://tkyte.blogspot.co.uk/2008/06/when-others-then-null-redux.html
What if there is no employee 100? Fine, it does nothing - perhaps that's OK. What if there is an employee 100 but there is a corrupt block in the index causing the query to fail with ORA-01578: ORACLE data block corrupted, or not, depending on the execution plan? It does nothing and doesn't tell you, and you'll think there's no employee 100.

PL/SQL compilation error

What is wrong with the following statement:
DECLARE
int_exists INTEGER;
BEGIN
SELECT COUNT(ItemKey)
INTO int_exists
FROM BIR_TabsForDashboard
WHERE ItemKey = 'Position';
IF( int_exists = 0 ) THEN --doesnt exist
EXECUTE IMMEDIATE 'ALTER TABLE BIR_TabsForDashboard ADD Position int NULL';
END IF;
END;
I get this report error:
ORA-06550: line 7, column 9:
PL/SQL: ORA-00904: "ITEMKEY": invalid identifier
ORA-06550: line 4, column 3:
PL/SQL: SQL Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
What could be wrong? It seems to work when I use it on another table but for some reason it comes up with this error when I do it to this specific table?
The table BIR_TabsForDashboard does not have a column named ItemKey.
Make sure the procedure which you are using is should properly declared in the place which you are using it. For an example if it is under an another user and in an another package then it should be in that same order. The username, package and procedure name.

Script that exec other scripts

I want to execute this script in PL/SQL but it keeps getting error
set serveroutput on;
set echo on;
declare
v_code varchar2(250);
v_errm varchar2(250);
begin
##"1.sql";
##"2.sql";
##"II_load_438865311678_Reg.sql";
exception
when others then
v_code := sqlcode;
v_errm := substr(sqlerrm, 1, 64);
DBMS_OUTPUT.PUT_LINE('ERROR! - '||DBMS_UTILITY.FORMAT_ERROR_STACK|| DBMS_UTILITY.FORMAT_ERROR_BACKTRACE);
rollback;
end;
/
What is wrong with this.
Error: ORA-06550: line 5, colunm 3: (...) ORA-06550: line 6, colunm 3:
(...) ORA-06550: line 7, colunm 3: PLS-00103: Encountered the symbol
"#" when expecting one of the following: ( begin case declare end
exception exit for goto if loop mod null pragma raise return select
update while with... and
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
You only use the PL/SQL code to show the error. That is not necessary; SQL*Plus will already show you any SQL error. Use whenever sqlerror to trigger the rollback.
whenever sqlerror continue rollback
##"1.sql"
##"2.sql"
##"II_load_438865311678_Reg.sql"

PLSQL record created with %rowtype being used as element for table gives compile/run error

I am declaring a table custom data-type of a record , the record is created by %rowtype of a table nemed : TMP_UNREGISTER_TAB , this table exists in the DB . While trying to execute the below plsql anon block i get the error specified below.
PLSQL CODE:
declare
rec_tmp_tab TMP_UNREGISTER_TAB%rowtype ;
v_rec_tmp_tab rec_tmp_tab;
TYPE tab_rec_tmp IS TABLE OF v_rec_tmp_tab%type
INDEX BY BINARY_INTEGER;
v_tab_rec_tmp tab_rec_tmp;
begin
null;
end;
/
SCRIPT OUTPUT:
Error report:
ORA-06550: line 3, column 18:
PLS-00488: 'REC_TMP_TAB' must be a type
ORA-06550: line 3, column 18:
PL/SQL: Item ignored
ORA-06550: line 4, column 33:
PLS-00320: the declaration of the type of this expression is incomplete or malformed
ORA-06550: line 4, column 4:
PL/SQL: Item ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
declare
rec_tmp_tab TMP_UNREGISTER_TAB%rowtype ;
TYPE tab_rec_tmp IS TABLE OF TMP_UNREGISTER_TAB%rowtype
INDEX BY BINARY_INTEGER;
v_tab_rec_tmp tab_rec_tmp;
begin
null;
end;
/

Resources