I connected to 'user1' and executed following, utplsql is installed in 'utp'. I installed utplsql framework from http://utplsql.sourceforge.net/.
BEGIN
utp.utAssert.eq('test',1,1);
END;
/
Error Output
ORA-02291: integrity constraint (UTP.UTR_ERROR_OUTCOME_FK) violated - parent key not found
ORA-06512: at "UTP.UTRERROR", line 149
ORA-06512: at "UTP.UTRERROR", line 324
ORA-06512: at "UTP.UTROUTCOME", line 146
ORA-01400: cannot insert NULL into ("UTP"."UTR_OUTCOME"."RUN_ID")
ORA-06512: at "UTP.UTRESULT2", line 72
ORA-06512: at "UTP.UTASSERT2", line 137
ORA-06512: at "UTP.UTASSERT2", line 541
ORA-06512: at "UTP.UTASSERT", line 118
ORA-06512: at line 2
But the
Instead of running utAssert.eq directly, you put it inside a test package, then run that with either utPLSQL.test or utPLSQL.run. (I recommend working through the Getting Started section of the utPLSQL documentation).
Define the test package
CREATE OR REPLACE PACKAGE ut_simple IS
PROCEDURE ut_setup;
PROCEDURE ut_teardown;
PROCEDURE ut_simple_test;
END;
CREATE OR REPLACE PACKAGE BODY ut_simple IS
PROCEDURE ut_setup IS
BEGIN
NULL;
END;
PROCEDURE ut_teardown IS
BEGIN
NULL;
END;
PROCEDURE ut_simple_test IS
BEGIN
utp.utAssert.eq('test',1,1);
END;
END;
Run the test
exec utp.utplsql.run ('ut_simple');
Related
I try to alter DB structure via DBMS_METADATA package, but get an error.
This is function inside a package I use:
FUNCTION putxml(
alterxml IN CLOB,
sub_res OUT NOCOPY sys.ku$_SubmitResults
)
RETURN BOOLEAN
IS
ret_val BOOLEAN := true;
openw_handle NUMBER;
transform_handle NUMBER;
BEGIN
openw_handle := DBMS_METADATA.openw ('TABLE');
transform_handle := DBMS_METADATA.add_transform (openw_handle, 'ALTERXML');
dbms_output.put_line(alterxml);
ret_val := DBMS_METADATA.put(openw_handle, alterxml, 0, sub_res);
DBMS_METADATA.close (openw_handle);
return ret_val;
END;
This is an XML:
<ALTER_XML xmlns="http://xmlns.oracle.com/ku" version="1.0">
<OBJECT_TYPE>TABLE</OBJECT_TYPE>
<OBJECT1>
<SCHEMA>GLOBALREF</SCHEMA>
<NAME>EDO_DOC_OUT</NAME>
</OBJECT1>
<OBJECT2>
<SCHEMA>GLOBALREF</SCHEMA>
<NAME>EDO_DOC_OUT</NAME>
</OBJECT2>
<ALTER_LIST>
<ALTER_LIST_ITEM>
<PARSE_LIST>
<PARSE_LIST_ITEM>
<ITEM>NAME</ITEM>
<VALUE>AUTHOR</VALUE>
</PARSE_LIST_ITEM>
<PARSE_LIST_ITEM>
<ITEM>CLAUSE_TYPE</ITEM>
<VALUE>ADD_COLUMN</VALUE>
</PARSE_LIST_ITEM>
</PARSE_LIST>
<SQL_LIST>
<SQL_LIST_ITEM>
<TEXT>ALTER TABLE "GLOBALREF"."EDO_DOC_OUT" ADD ("AUTHOR" VARCHAR2(50))</TEXT>
</SQL_LIST_ITEM>
</SQL_LIST>
</ALTER_LIST_ITEM>
</ALTER_LIST>
</ALTER_XML>
This is version info:
BANNER CON_ID
-------------------------------------------------------------------------------- ----------
Oracle Database 12c Release 12.1.0.1.0 - 64bit Production 0
PL/SQL Release 12.1.0.1.0 - Production 0
CORE 12.1.0.1.0 Production 0
TNS for 64-bit Windows: Version 12.1.0.1.0 - Production 0
NLSRTL Version 12.1.0.1.0 - Production 0
This is an error:
ORA-31607: function PUT (CLOB) is inconsistent with transform.
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 86
ORA-06512: at "SYS.DBMS_METADATA", line 5189
ORA-06512: at "SYS.DBMS_METADATA", line 5315
ORA-06512: at "SYS.DBMS_METADATA", line 10870
ORA-06512: at "ADMIN.PKG_SYNC", line 90
ORA-06512: at "ADMIN.PKG_SYNC", line 143
ORA-06512: at "ADMIN.PKG_SYNC", line 184
ORA-06512: at line 7
31607. 00000 - "function %s is inconsistent with transform."
*Cause: Either (1) FETCH_XML was called when the "DDL" transform
was specified, or (2) FETCH_DDL was called when the
"DDL" transform was omitted.
*Action: Correct the program.
I tried both with DBMS_METADATA.add_transform (openw_handle, 'ALTERXML') and without...
CREATE OR REPLACE PROCEDURE Insert_Job AS
v_job_id VARCHAR2(10) := 'HR_Assistant';
v_job_title VARCHAR2(35) := 'HRessourcesAssistant';
v_Min_Salary NUMBER(22):= 400;
v_max_salary NUMBER (22):= 5000;
BEGIN
INSERT INTO OEHR_JOBS (JOB_ID, JOB_TITLE,MIN_SALARY,MAX_SALARY)
VALUES (v_job_id, v_job_title, v_Min_Salary, v_max_salary);
dbms_output.put_line('Insertion OK');
End;
Write a PL/SQL procedure with no parameters Insert_Job that inserts a new record in the table JOBS: - Job Id: Assistant - Job title: HRessources Assistant - Min Salary: 400 - Max Salary: 5000 The procedure should print a message to the user to inform him about the insertion status (success/ Error). Call the procedure and take a screenshot of the output in both cases.
This is what I try and it doesn't work any help please? It created the procedure but no data into the table, an also when I call it it shows me an error. I'm usnig APEX ORACLE HERE IS THE ERROR MESSAGE BELOW
ORA-06550: line 2, column 1:
PLS-00905: object WKSP_ELIASHOME.INSERT_JOB is invalid
ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_200200", line 626
ORA-06550: line 2, column 1:
PL/SQL: Statement ignored
ORA-06512: at "SYS.DBMS_SYS_SQL", line 1658
ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_200200", line 612
ORA-06512: at "APEX_200200.WWV_FLOW_DYNAMIC_EXEC", line 1749
When I read your error message: numeric or value error: character string buffer too small
This mean your length is too small.
In your code:
v_job_id VARCHAR2(10) := 'HR_Assistant';
It was because length 'HR_Assistant' is longer then 10
Try to change lenght v_job_id into:
v_job_id VARCHAR2(12) := 'HR_Assistant';
Or you can remove some character, into:
v_job_id VARCHAR2(10) := 'Assistant';
Or, maybe you must check first length from column JOB_ID in table OEHR_JOBS
Sorry if my english bad and I don't really familiar with PLSQL.
My code
CREATE OR REPLACE proc_grade IS
v varchar2(20);
c varchar2(20);
t integer(10);
x integer(10);
CURSOR s IS
SELECT total_marks,name,roll_no FROM STUD_MARKS ORDER BY roll_no;
BEGIN
OPEN s;
LOOP
FETCH s INTO x,c,t;
BEGIN
v:=grade(x);
INSERT INTO result VALUES(t,c,v);
dbms_output.put_line('ROLL_NO : '||t||'NAME: '||c||' CLASS: '||v);
END;
EXIT WHEN s%notfound;
END LOOP;
CLOSE s;
END;
Error that I am getting is as follows:
ORA-00922: missing or invalid option
ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_200100", line 581
ORA-06512: at "SYS.DBMS_SYS_SQL", line 1658
ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_200100", line 567
ORA-06512: at "APEX_200100.WWV_FLOW_DYNAMIC_EXEC", line 2127
c varchar2(20);
t integer(10);
x integer(10);
CURSOR s IS
It is not
CREATE OR REPLACE proc_grade
but
CREATE OR REPLACE PROCEDURE proc_grade
By the way, you could have done it way simpler by running only this instead of all the PL/SQL you wrote.
INSERT INTO result
SELECT roll_no, name, grade (total_marks)
FROM stud_marks;
I'm able to run an anonymous PL/SQL block and set an initial_rsrc_consumer_group via DBMS_RESOURCE_MANAGER in Oracle 19; however, when I attempt to name it as a stored procedure it throws ORA-00942: table or view does not exist.
Anonymous plsql block that runs ok:
SQL> begin
2 dbms_resource_manager_privs.grant_switch_consumer_group('TESTUSR', 'TEST_GROUP', false);
3 dbms_resource_manager.create_pending_area();
4 dbms_resource_manager.set_initial_consumer_group('TESTUSER', 'TEST_GROUP');
5 dbms_resource_manager.validate_pending_area();
6 dbms_resource_manager.submit_pending_area();
7 dbms_resource_manager.clear_pending_area();
8 end;
9
10 /
PL/SQL procedure successfully completed
The definition of the procedure is below
create or replace procedure jomccr.set_consumer_group (
p_username dba_users.username%type
) is
begin
dbms_resource_manager_privs.grant_switch_consumer_group(upper(p_username), 'TEST_GROUP', false);
dbms_resource_manager.create_pending_area();
dbms_resource_manager.set_initial_consumer_group(upper(p_username), 'TEST_GROUP');
dbms_resource_manager.validate_pending_area();
dbms_resource_manager.submit_pending_area();
dbms_resource_manager.clear_pending_area();
end ;
Whenever I execute it, I receive the following error:
SQL> execute jomccr.set_consumer_group('TESTUSR')
ORA-00942: table or view does not exist
ORA-06512: at "SYS.DBMS_RMIN", line 36
ORA-06512: at "SYS.DBMS_RMIN", line 85
ORA-06512: at "SYS.DBMS_RESOURCE_MANAGER_PRIVS", line 96
ORA-06512: at "JOMCCR.SET_CONSUMER_GROUP", line 6
ORA-06512: at line 1
What changed now that I've named the procedure?
I have this procedure:
create or replace
PROCEDURE P_P2
IS
v_str varchar2(1000);
v_file_name varchar2(1000);
BEGIN
P_P1(v_str, 'EXPORT_CSV',v_file_name);
v_str := 'select * from H----)';
v_file_name := 'H_'||to_char(sysdate,'DD-MM-YYYY')||'.csv';
END;
I am getting error "ORA-06561: given statement is not supported by package DBMS_SQL" when I execute it:
Error starting at line : 165 in command -
exec P_P1
Error report -
ORA-06561: given statement is not supported by package DBMS_SQL
ORA-06512: at "SYS.DBMS_SQL", line 1120
ORA-06512: at "BIDB.P_P1", line 40
ORA-06512: at "BIDB.P_P2", line 7
ORA-06512: at line 1
06561. 00000 - "given statement is not supported by package DBMS_SQL"
*Cause: Attempting to parse an unsupported statement using procedure
PARSE provided by package DBMS_SQL.
*Action: Only statements which begin with SELECT, DELETE, INSERT, UPDATE,
LOCK, BEGIN, DECLARE or << (PL/SQL label delimiter) are supported.
I cannot see why. What am I doing wrong?
You haven't shown what P_P1 is doing, but from what you have shown, your P_P2 procedure may just be calling it too early; you have a call to P_P1 which uses v_str as a parameter, but it's null at that point - you set it after the call that uses it.
That means that somewhere in P_P1 you are probably ending up doing the equivalent of:
dbms_sql.parse(c, null, dbms_sql.native);
which throws the error you are seeing. You're doing the same with v_filename, which will presumably cause other issues.
So for a start, swap those lines around so the procedure is called last:
create or replace
PROCEDURE P_P2
IS
v_str varchar2(1000);
v_file_name varchar2(1000);
BEGIN
v_str := 'select * from H----)';
v_file_name := 'H_'||to_char(sysdate,'DD-MM-YYYY')||'.csv';
-- call this AFTER populating the variables
P_P1(v_str, 'EXPORT_CSV',v_file_name);
END;
/
You may have other problems of course - the table name looks odd, both because of the dashes and the closing parenthesis; but you may have just hidden the real name oddly. You seem to have changed the procedure names too (though inconsistently, as your exec seems to be calling the wrong one...).