I am trying to send mails through UTL_MAIL.
where I used below code:
declare
v_sender VARCHAR2(30);
v_recipients VARCHAR2(60);
v_subj VARCHAR2(20);
v_msg VARCHAR2(200);
begin
v_sender := 'abc#xyz.com';
v_recipients := 'aaa#xyz.com';
v_subj := 'Info';
v_msg := 'This is an automated mail';
CALL (UTL_MAIL.SEND(v_sender, v_recipients, NULL, NULL, v_subj, v_msg));
END;
and I am receiving an error:
[Error] Execution (12: 9): ORA-06550: line 12, column 9:
PLS-00222: no function with name 'SEND' exists in this scope
ORA-06550: line 12, column 3:
PL/SQL: Statement ignored
Please help me with this..
Thank you
Related
I want to send a collection to a Function, but I keep getting an error.
I defined the RECORD and TYPES in my Package Header and Implemented the body aswell. I dont understand why I cant send a simple collection as a parameter, the idea is for me to loop through the collection and do some comparisation then return a char within a sql statement.
Been struggling with this for a week now, any help is appreciated.
Exact error:
ORA-06550: line 9, column 45:
PLS-00382: expression is of wrong type
ORA-06550: line 9, column 40:
PLS-00306: wrong number or types of arguments in call to 'TEST_F'
ORA-06550: line 9, column 23:
PL/SQL: ORA-00904: "PACKAGE_SS"."TEST_F": invalid identifier
ORA-06550: line 9, column 3:
PL/SQL: SQL Statement ignored
Header:
create or replace
PACKAGE PACKAGE_SS AS
type t_itemnumber is table of varchar2(100) index by BINARY_INTEGER;
type t_alternative_rec is record
(
itemnumber t_itemnumber
);
type t_alternative_prev is table of t_alternative_rec INDEX BY BINARY_INTEGER;
type t_procestype_rec is record
(
procestype char
);
TYPE result_table IS TABLE OF t_procestype_rec;
FUNCTION test_f(p_items_prev IN t_alternative_prev) RETURN result_table PIPELINED;
END AOPA_VALIDATE_SS;
The package body looks like this:
create or replace
PACKAGE BODY PACKAGE_SS AS
FUNCTION test_f(p_items_prev IN t_alternative_prev) RETURN result_table PIPELINED IS
processType char(1) := 'U';
rec t_procestype_rec :=null;
BEGIN
DBMS_OUTPUT.PUT_LINE('ENTERD ');
if (processType= 'U') then
select 'U' into rec from dual;
end if;
if (processType='C') then
select 'C' into rec from dual;
end if;
if (processType='D') then
select 'D' into rec from dual;
end if;
pipe row (rec);
return;
END test_f;
END PACKAGE_SS;
Usage plsql script:
DECLARE
prev_rev_alternatives PACKAGE_SS.t_alternative_prev;
BEGIN
prev_rev_alternatives(1).itemnumber(10) := 'PR454545';
prev_rev_alternatives(1).itemnumber(20) := 'PR333333';
SELECT * FROM table(PACKAGE_SS.test_f(prev_rev_alternatives));
END;
There are two things which my eyes fall upon:
Usage of SELECT without INTO in an anonymous PLSQL block is not supposed to work.
Usage of types in an SQL statement requires the type defined as an object, not within a package specification.
Try
CREATE TYPE
https://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_8001.htm
and
SELECT * INTO ... FROM ...
This might help.
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"
varSQL: = 'DECLARE
varOptionId NUMBER;
varXML XMLTYPE;
varHsCode VARCHAR2(200);
varHsCodeCount NUMBER;
varId NUMBER;
RVAL OBJ_RETURN:=OBJ_RETURN(NULL,NULL,NULL,NULL);
BEGIN
varXML:=:refXML;
varHsCode:= varXML.EXTRACT('/OBJECT/HsCodes/HsCode/text()').GETSTRINGVAL();
:out:=varHsCode;
END';
EXECUTE IMMEDIATE varSQL USING PXML,OUT varOut;
This gives the following error:
ORA-06550: line 9, column 15:
PLS-00382: expression is of wrong type
ORA-06550: line 9, column 2:
PL/SQL: Statement ignored
ORA-06512: at "BIZZXE_V2_SCH.SYSTEM_UTILITY", line 225
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
Is it possible to pass a XML?
Yes, you can pass an XMLType variable as a bind parameter:
declare
varsql varchar2(1024);
varout varchar2(4);
pxml xmltype := xmltype('<OBJECT><HsCodes><HsCode>Test</HsCode></HsCodes></OBJECT>');
begin
varSQL := 'DECLARE
varOptionId NUMBER;
varXML XMLTYPE;
varHsCode VARCHAR2(200);
varHsCodeCount NUMBER;
varId NUMBER;
--RVAL OBJ_RETURN:=OBJ_RETURN(NULL,NULL,NULL,NULL);
BEGIN
varXML:=:refXML;
varHsCode:= varXML.EXTRACT(''/OBJECT/HsCodes/HsCode/text()'').GETSTRINGVAL();
:out:=varHsCode;
END;';
EXECUTE IMMEDIATE varSQL USING PXML,OUT varOut;
dbms_output.put_line(varOut);
end;
/
PL/SQL procedure successfully completed.
Test
The error you are getting is because you have declared PXML as a string; either a varchar2 or CLOB variable:
declare
varsql varchar2(1024);
varout varchar2(4);
</HsCodes></OBJECT>');
pxml varchar2(64) := '<OBJECT><HsCodes><HsCode>Test</HsCode></HsCodes></OBJECT>';
begin
varSQL := 'DECLARE
varOptionId NUMBER;
varXML XMLTYPE;
varHsCode VARCHAR2(200);
varHsCodeCount NUMBER;
varId NUMBER;
--RVAL OBJ_RETURN:=OBJ_RETURN(NULL,NULL,NULL,NULL);
BEGIN
varXML:=:refXML;
varHsCode:= varXML.EXTRACT(''/OBJECT/HsCodes/HsCode/text()'').GETSTRINGVAL();
:out:=varHsCode;
END;';
EXECUTE IMMEDIATE varSQL USING PXML,OUT varOut;
dbms_output.put_line(varOut);
end;
/
Error report -
ORA-06550: line 9, column 10:
PLS-00382: expression is of wrong type
ORA-06550: line 9, column 2:
PL/SQL: Statement ignored
ORA-06512: at line 21
In your example there's no reason to use dynamic SQL anyway, but maybe your real-world example is more complicated.
Procedure:
create or replace
PROCEDURE ADDITION
(
A IN NUMBER
, B IN NUMBER
, C OUT number
) AS
BEGIN
C := A+B;
dbms_output.put_line(c);
END ADDITION;
executing:
begin
addition(4,5);
end;
Error:
PLS-00306: wrong number or types of arguments in call to 'ADDITION'
ORA-06550: line 2, column 2:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
How to rectify this error.Let me know what is the wrong in code
Your procedure expects an out parameter which you also need to provide:
declare
add_result number;
begin
addition(4,5,add_result);
end;
/
DECLARE
TYPE t IS RECORD (
col_name VARCHAR2 (100)
);
t_row t;
cname VARCHAR (100) := 'col_name';
BEGIN
t_row.col_name := 'col';
DBMS_OUTPUT.put_line ('out');
IF t_row.cname IS NULL THEN
DBMS_OUTPUT.put_line ('in');
END IF;
END;
Error at line 1
ORA-06550: line 12, column 12:
PLS-00302: component 'CNAME' must be declared
ORA-06550: line 12, column 3:
PL/SQL: Statement ignored
How can I assign dynamic column name to type variable of record?
You can do that with dynamic sql:
To make the example simpler I'll make your type t a schema object (but basically you don't have to - you can put it in the dynamic part as well)
create or replace type t is object(col_name varchar2(100));
/
Then you can look at this script:
declare
t_row t;
cname varchar2(100) := 'col_name';
begin
t_row := new t('col');
execute immediate 'declare t_in t := :0; begin if t_in.' || cname ||
' is null then dbms_output.put_line(''in''); end if; end;'
using t_row;
end;
Though, I must say, that this is a strange requirement ...
The error is because record t doesn't have a field cname, but col_name:
type t is record (
col_name varchar2(100)
);
One have to know record fields during compile time.
Could tell us what is the real problem you're going to solve ?