Change of anonymous block to a stored procedure
Hi, how can I modify this code to become a procedure stored instead of anonymous block. I need to pass the parameters on a regular basis. which means that I have to perform the procedure on a daily basis with specific parameters. I am running Oracle 11 g and coding with plsql. Thanks in advance for your help.
DECLARE
/*Your query as cursor */
CURSOR emp_cur IS
SELECT ename, sal FROM emp;
/*UTL_SMTP related varriavles. */
v_connection_handle UTL_SMTP.CONNECTION;
v_from_email_address VARCHAR2(30) := '[email protected]';
v_to_email_address VARCHAR2(30) := 'yyyy@[qr.com';
v_smtp_host VARCHAR2(30) := 'x.xxx.xxx.xxx'; --My mail server, replace it with yours.
v_subject VARCHAR2(30) := 'Your Test Mail';
l_message VARCHAR2(200) := 'This is test mail using UTL_SMTP';
/* This send_header procedure is written in the documentation */
PROCEDURE send_header(pi_name IN VARCHAR2, pi_header IN VARCHAR2) AS
BEGIN
UTL_SMTP.WRITE_DATA(v_connection_handle,
pi_name || ': ' || pi_header || UTL_TCP.CRLF);
END;
BEGIN
/*UTL_SMTP related coding. */
v_connection_handle := UTL_SMTP.OPEN_CONNECTION(host => v_smtp_host);
UTL_SMTP.HELO(v_connection_handle, v_smtp_host);
UTL_SMTP.MAIL(v_connection_handle, v_from_email_address);
UTL_SMTP.RCPT(v_connection_handle, v_to_email_address);
UTL_SMTP.OPEN_DATA(v_connection_handle);
send_header('From', '"Sender" <' || v_from_email_address || '>');
send_header('To', '"Recipient" <' || v_to_email_address || '>');
send_header('Subject', v_subject);
--MIME header.
UTL_SMTP.WRITE_DATA(v_connection_handle,
'MIME-Version: 1.0' || UTL_TCP.CRLF);
UTL_SMTP.WRITE_DATA(v_connection_handle,
'Content-Type: multipart/mixed; ' || UTL_TCP.CRLF);
UTL_SMTP.WRITE_DATA(v_connection_handle,
' boundary= "' || 'SAUBHIK.SECBOUND' || '"' ||
UTL_TCP.CRLF);
UTL_SMTP.WRITE_DATA(v_connection_handle, UTL_TCP.CRLF);
-- Mail Body
UTL_SMTP.WRITE_DATA(v_connection_handle,
'--' || 'SAUBHIK.SECBOUND' || UTL_TCP.CRLF);
UTL_SMTP.WRITE_DATA(v_connection_handle,
'Content-Type: text/plain;' || UTL_TCP.CRLF);
UTL_SMTP.WRITE_DATA(v_connection_handle,
' charset=US-ASCII' || UTL_TCP.CRLF);
UTL_SMTP.WRITE_DATA(v_connection_handle, UTL_TCP.CRLF);
UTL_SMTP.WRITE_DATA(v_connection_handle, l_message || UTL_TCP.CRLF);
UTL_SMTP.WRITE_DATA(v_connection_handle, UTL_TCP.CRLF);
FOR i IN emp_cur LOOP
UTL_SMTP.WRITE_DATA(v_connection_handle,
i.ename || '--' || i.sal || UTL_TCP.CRLF);
END LOOP;
UTL_SMTP.WRITE_DATA(v_connection_handle, UTL_TCP.CRLF);
-- Close Email
UTL_SMTP.WRITE_DATA(v_connection_handle,
'--' || 'SAUBHIK.SECBOUND' || '--' || UTL_TCP.CRLF);
UTL_SMTP.WRITE_DATA(v_connection_handle,
UTL_TCP.CRLF || '.' || UTL_TCP.CRLF);
UTL_SMTP.CLOSE_DATA(v_connection_handle);
UTL_SMTP.QUIT(v_connection_handle);
EXCEPTION
WHEN OTHERS THEN
UTL_SMTP.QUIT(v_connection_handle);
RAISE;
END;
CREATE OR REPLACE PROCEDURE BDA. PR_SEND_EMAIL
(p_from_email_address VARCHAR2
p_to_email_address VARCHAR2
p_smtp_host VARCHAR2
p_subject in VARCHAR2 DEFAULT "Test E-mail"
p_message VARCHAR2 DEFAULT ' is the TEST mail with the help of UTL_SMTP "
)
IS
/ Request as cursor * /.
CURSOR emp_cur IS
SELECT ename, sal FROM emp;
/ * Related UTL_SMTP varriavles. */
v_connection_handle UTL_SMTP. CONNECTION;
/ * This procedure of send_header is mentioned in the documentation * /.
PROCEDURE send_header (pi_name IN VARCHAR2, pi_header IN VARCHAR2) AS
BEGIN
UTL_SMTP. WRITE_DATA (v_connection_handle, pi_name |) ': ' || pi_header | UTL_TCP. CRLF);
END;
BEGIN
/ * Associated with coding UTL_SMTP. */
v_connection_handle: = UTL_SMTP. OPEN_CONNECTION (host-online p_smtp_host);
UTL_SMTP. HELO (v_connection_handle, p_smtp_host);
UTL_SMTP. MAIL (v_connection_handle, p_from_email_address);
UTL_SMTP. RCPT (v_connection_handle, p_to_email_address);
UTL_SMTP. OPEN_DATA (v_connection_handle);
send_header ('from', "" sender" <' ||="" p_from_email_address="" ||="" '="">" ");
send_header ('To', ' "receiver" <' ||="" p_to_email_address="" ||="" '="">"");
send_header ('Subject', p_subject);
-MIME header.
UTL_SMTP. WRITE_DATA (v_connection_handle, "MIME-Version: 1.0 ' |") UTL_TCP. CRLF);
UTL_SMTP. WRITE_DATA (v_connection_handle, ' Content-Type: multipart/mixed;) ' || UTL_TCP. CRLF);
UTL_SMTP. WRITE_DATA (v_connection_handle, ' boundary = "' | '") CARINE. SECBOUND' | '"' || UTL_TCP. CRLF);
UTL_SMTP. WRITE_DATA (v_connection_handle, UTL_TCP. CRLF);
-Body of the message
UTL_SMTP. WRITE_DATA (v_connection_handle, '-' |) "JOHAN. SECBOUND' | UTL_TCP. CRLF);
UTL_SMTP. WRITE_DATA (v_connection_handle, ' Content-Type: text/plain;) "|| UTL_TCP. CRLF);
UTL_SMTP. WRITE_DATA (v_connection_handle, 'charset = US-ASCII' |) UTL_TCP. CRLF);
UTL_SMTP. WRITE_DATA (v_connection_handle, UTL_TCP. CRLF);
UTL_SMTP. WRITE_DATA (v_connection_handle, p_message |) UTL_TCP. CRLF);
UTL_SMTP. WRITE_DATA (v_connection_handle, UTL_TCP. CRLF);
I'm IN emp_cur
LOOP
UTL_SMTP. WRITE_DATA (v_connection_handle, i.ename |) '--' || i.SAL | UTL_TCP. CRLF);
END LOOP;
UTL_SMTP. WRITE_DATA (v_connection_handle, UTL_TCP. CRLF);
-E-mail nearby
UTL_SMTP. WRITE_DATA (v_connection_handle, '-' |) "JOHAN. SECBOUND' | '--' || UTL_TCP. CRLF);
UTL_SMTP. WRITE_DATA (v_connection_handle, UTL_TCP. CRLF. '.' || UTL_TCP. CRLF);
UTL_SMTP. CLOSE_DATA (v_connection_handle);
UTL_SMTP. Quit (v_connection_handle);
EXCEPTION
WHILE OTHERS THEN
UTL_SMTP. Quit (v_connection_handle);
LIFT;
END;
/
CREATE OR REPLACE SYNONYM PUBLIC PR_SEND_EMAIL OF BDA. PR_SEND_EMAIL;
BEGIN
BDA. PR_SEND_EMAIL (p_from_email_address => ' [email protected]')
, p_to_email_address => ' [email protected]'
, p_smtp_host-online 'x.xxx.xxx.xxx '.
p_subject-online "TEST Your Mail"
p_message-online "Is the TEST mail with the help of UTL_SMTP"
);
EXCEPTION, THEN THAN OTHERS
THEN DBMS_OUTPUT. Put_line ('ERROR in the procedure PR_SEND_EMAIL-' |) SQLERRM);
LIFT;
END;
/
'>'>
Tags: Database
Similar Questions
-
Works of anonymous block - failure of the procedure
Hi guys,.
I am new to PL/SQL, and right now, I have problems with a new procedure.
If I execute the instructions of an anonymous block, then everything works fine.
As a stored procedure, it fails: PLS-00306: wrong number or types of arguments.
I don't understand - could you please help me?
Oracle Database 10 g Express Edition Release 10.2.0.1.0 - product
PL/SQL Release 10.2.0.1.0 - Production
"CORE 10.2.0.1.0 Production."
AMT for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
The procedure inserts data in multiple tables - so the original procedure has 800 lines.
I tested it with a shorter version, but it still does not work as a procedure.
Here is the execute statement:
and here is the procedure:begin P_P5020_test ( i_GespAnrede_tx => 'Herr', i_GespName_tx => 'GespName', i_GespVorname_tx => 'GespVorname', i_GespTitel_tx => 'GespTitel', i_GespStelle_tx => 'GespStelle', i_GespFunktion_isn => 1, i_GespBereich_isn => 1, i_GespTelNr_nr => '1111', i_GespTelNrArt_isn => 1, -- Daten vom Ansprechpartner: i_ApAnrede_tx => 'Frau', i_ApName_tx => 'ApName', i_ApVorname_tx => 'ApVorname', i_ApTitel_tx => 'Aptitel', i_ApStelle_tx => 'ApStelle', i_ApFunktion_isn => 2, i_ApBereich_isn => 2, i_ApTelNr_nr => '2222', i_ApTelNrArt_isn => 1, -- Allgemeine Parameter: i_UN_nr => 110532, i_TelNr_isn => 54, i_hiber_isn => 4, i_AnlVon_tx => 'SMY', i_TaskArt_isn => 12, i_Bemerkung_tx => 'Bemerkung' ); END;
Here are the variables of the anonymous block work - the instructions are the same:create or replace PROCEDURE p_P5020_test -- -- Parameter: -- ( -- Daten vom Gesprächspartner: i_GespAnrede_tx varchar2, i_GespName_tx varchar2, i_GespVorname_tx varchar2, i_GespTitel_tx varchar2, i_GespStelle_tx varchar2, i_GespFunktion_isn number, i_GespBereich_isn number, i_GespTelNr_nr varchar2, i_GespTelNrArt_isn number, -- Daten vom Ansprechpartner: i_ApAnrede_tx varchar2, i_ApName_tx varchar2, i_ApVorname_tx varchar2, i_ApTitel_tx varchar2, i_ApStelle_tx varchar2, i_ApFunktion_isn number, i_ApBereich_isn number, i_ApTelNr_nr varchar2, i_ApTelNrArt_isn number, -- Allgemeine Parameter: i_UN_nr number, i_TelNr_isn number, i_hiber_isn number, i_anlVon_tx varchar2, i_TaskArt_isn number, i_sonstGrund_tx varchar2, i_Bemerkung_tx varchar2, -- für die Task: i_BeginnDatum_dt date, i_BeginnZeit_ts timestamp, i_FaelligVonDatum_dt date, i_FaelligVonZeit_ts timestamp, i_FaelligBisDatum_dt date, i_FaelligBisZeit_ts timestamp, i_TaskPrio_isn number ) -- -------------------------------------------------------------------------------- -- IS -- -- Variablen: -- v_MA_nr number := 4; v_GespBez_nr number; -- return BezNr vom Gesprächspartner v_ApBez_nr number; -- return BezNr vom Ansprechpartner v_Task_nr number; -- return TaskNr für die Kon v_TaskThema_tx varchar2(40); -- anhand taskart ermitteln -- für die Beziehung: v_BezGueltigVon_dt date := sysdate; v_BezGueltigBis_dt date := to_date('31.12.2099', 'DD.MM.YYYY'); -- für die Notiz / Kon: v_KonThema_tx varchar2(40); v_KonArt_isn number; v_KonWeg_isn number := 2; -- 2 = Telefon v_KonDatum_dt date := sysdate; v_KonUhrzeit_ts timestamp := systimestamp; -- -- -------------------------------------------------------------------------------- -- BEGIN -- select into für variablen durchführen -- -- -- v_taskThema_tx füllen IF i_taskArt_isn != 999999 THEN SELECT TASK_ART_NAME INTO v_taskThema_tx FROM T_TASK_ART WHERE task_art_isn = i_taskArt_isn; -- -- -- v_KonArt_ISN füllen IF i_TaskArt_isn = 10 -- Nennung verweigert THEN v_KonArt_ISN := 13; END IF; IF i_TaskArt_isn = 11 -- krank THEN v_KonArt_ISN := 7; END IF; IF i_TaskArt_isn = 12 -- Urlaub THEN v_KonArt_ISN := 8; END IF; IF i_TaskArt_isn = 13 -- nicht am Platz THEN v_KonArt_ISN := 9; END IF; IF i_TaskArt_isn = 14 -- Feierabend THEN v_KonArt_ISN := 10; END IF; IF i_TaskArt_isn = 15 -- Besprechung THEN v_KonArt_ISN := 11; END IF; IF i_TaskArt_isn = 16 -- zu Tisch THEN v_KonArt_ISN := 12; END IF; IF i_TaskArt_isn = 17 -- sonstiger Grund THEN v_KonArt_ISN := 14; END IF; -- -- -- v_konThema_tx füllen SELECT kon_art_name INTO v_konThema_tx FROM T_KON_ART WHERE kon_art_isn = v_konArt_isn; -- -- END IF; -- i_taskArt_isn != 999999 -- -- -------------------------------------------------------------------------------- -- -- -- IF i_ApName_tx IS NOT NULL -- AP gefüllt? -- dann Gesp anlegen THEN INSERT INTO t_bez ( bez_un_nr, bez_anrede, bez_titel, bez_name, bez_vorname, bez_stelle, bez_funktion_isn, bez_bereich_isn, bez_bemerkung, bez_gueltig_von, bez_gueltig_bis, bez_anlvon ) VALUES ( i_un_nr, -- bez_un_nr i_GespAnrede_tx, -- bez_anrede i_GespTitel_tx, -- bez_titel i_GespName_tx, -- bez_name i_GespVorname_tx, -- bez_vorname i_GespStelle_tx, -- bez_stelle i_GespFunktion_isn, -- bez_funktion_isn i_GespBereich_isn, -- bez_bereich_isn 'Als Gesprächspartner angelegt, '|| -- bez_bemerkung to_char(sysdate, 'DD.MM.YYYY - hh24:mi')|| ' '|| i_AnlVon_tx|| ' ', v_BezGueltigVon_dt, -- bez_gueltig_von v_BezGueltigBis_dt, -- bez_gueltig_bis i_AnlVon_tx -- bez_anlvon ) RETURN t_bez.bez_nr INTO v_GespBez_nr; -- telefonnummer anlegen INSERT INTO t_telnr ( telnr_von, telnr_vonnr, telnr_nr, telnr_art_isn, telnr_anlvon ) VALUES ( 'BEZ', -- telnr_von v_GespBez_nr, -- telnr_vonnr i_GespTelNr_nr, -- telnr_nr i_GespTelNrArt_isn, -- telnr_art_isn i_AnlVon_tx -- telnr_anlvon ) ; -- -- -- jetzt AP anlegen INSERT INTO T_BEZ ( bez_un_nr, bez_anrede, bez_titel, bez_name, bez_vorname, bez_stelle, bez_funktion_isn, bez_bereich_isn, bez_bemerkung, bez_gueltig_von, bez_gueltig_bis, bez_anlvon ) VALUES ( i_un_nr, -- bez_un_nr i_ApAnrede_tx, -- bez_anrede i_ApTitel_tx, -- bez_titel i_ApName_tx, -- bez_name i_ApVorname_tx, -- bez_vorname i_ApStelle_tx, -- bez_stelle i_ApFunktion_isn, -- bez_funktion_isn i_ApBereich_isn, -- bez_bereich_isn 'Als Ansprechpartner angelegt, '|| -- bez_bemerkung to_char(sysdate, 'DD.MM.YYYY - hh24:mi')|| ' '|| i_AnlVon_tx|| ' ', v_BezGueltigVon_dt, -- bez_gueltig_von v_BezGueltigBis_dt, -- bez_gueltig_bis i_AnlVon_tx -- bez_anlvon ) RETURN t_bez.bez_nr INTO v_ApBez_nr; -- jetzt TelNr anlegen INSERT INTO t_telnr ( telnr_von, telnr_vonnr, telnr_nr, telnr_art_isn, telnr_anlvon ) VALUES ( 'BEZ', -- telnr_von v_ApBez_nr, -- telnr_vonnr i_ApTelNr_nr, -- telnr_nr i_ApTelNrArt_isn, -- telnr_art_isn i_AnlVon_tx -- telnr_anlvon ) ; END IF; -- i_ApName_tx IS NOT NULL -- --------------------------------------- -- -- -- AP nicht gefüllt: -- IF i_ApName_tx IS NULL THEN -- Gesprächspartner als Ansprechpartner anlegen INSERT INTO t_bez ( bez_un_nr, bez_anrede, bez_titel, bez_name, bez_vorname, bez_stelle, bez_funktion_isn, bez_bereich_isn, bez_bemerkung, bez_gueltig_von, bez_gueltig_bis, bez_anlvon ) VALUES ( i_un_nr, -- bez_un_nr i_GespAnrede_tx, -- bez_anrede i_GespTitel_tx, -- bez_titel i_GespName_tx, -- bez_name i_GespVorname_tx, -- bez_vorname i_GespStelle_tx, -- bez_stelle i_GespFunktion_isn, -- bez_funktion_isn i_GespBereich_isn, -- bez_bereich_isn 'Als Ansprechpartner angelegt, '|| -- bez_bemerkung to_char(sysdate, 'DD.MM.YYYY - hh24:mi')|| ' '|| i_AnlVon_tx|| ' ', v_BezGueltigVon_dt, -- bez_gueltig_von v_BezGueltigBis_dt, -- bez_gueltig_bis i_AnlVon_tx -- bez_anlvon ) RETURN t_bez.bez_nr INTO v_ApBez_nr; -- Achtung: wird als AP angelegt! -- telefonnummer anlegen INSERT INTO t_telnr ( telnr_von, telnr_vonnr, telnr_nr, telnr_art_isn, telnr_anlvon ) VALUES ( 'BEZ', -- telnr_von v_ApBez_nr, -- telnr_vonnr ACHTUNG: vom AP! i_GespTelNr_nr, -- telnr_nr i_GespTelNrArt_isn, -- telnr_art_isn i_AnlVon_tx -- telnr_anlvon ) ; END IF; -- i_ApName_tx IS NULL -------------------------------------------------------------------------------- -- END;
Why is - it works for anonymous block - bute the procedure fails with PLS-00306: wrong number or types of arguments?declare i_GespAnrede_tx varchar2(4) := 'Herr'; i_GespName_tx varchar2(60) := 'GespName'; i_GespVorname_tx varchar2(30) := 'GespVorname'; i_GespTitel_tx varchar2(10) := 'GespTitel'; i_GespStelle_tx varchar2(60) := 'GespStelle'; i_GespFunktion_isn number := 1; i_GespBereich_isn number := 1; i_GespTelNr_nr varchar2(20) := '111111'; i_GespTelNrArt_isn number := 1; -- Daten vom Ansprechpartner: i_ApAnrede_tx varchar2(4) := 'Frau'; i_ApName_tx varchar2(60) := 'ApName'; i_ApVorname_tx varchar2(30) := 'ApVorname'; i_ApTitel_tx varchar2(10) := 'ApTitel'; i_ApStelle_tx varchar2(60) := 'ApStelle'; i_ApFunktion_isn number := 2; i_ApBereich_isn number := 2; i_ApTelNr_nr varchar2(20) := '222222'; i_ApTelNrArt_isn number := 1; -- Allgemeine Parameter: i_UN_nr number := 110532; i_TelNr_isn number := 54; i_hiber_isn number := 4; i_AnlVon_tx varchar2(5) := 'SMY'; i_TaskArt_isn number := 12; i_sonstGrund_tx varchar2(15); i_Bemerkung_tx varchar2(50); -- v_MA_nr number := 4; v_GespBez_nr number; -- return BezNr vom Gesprächspartner v_ApBez_nr number; -- return BezNr vom Ansprechpartner v_Task_nr number; -- return TaskNr für die Kon v_TaskThema_tx varchar2(40); -- anhand taskart ermitteln -- für die Beziehung: v_BezGueltigVon_dt date := sysdate; v_BezGueltigBis_dt date := to_date('31.12.2099', 'DD.MM.YYYY'); -- für die Notiz / Kon: v_KonThema_tx varchar2(40); v_KonArt_isn number; v_KonWeg_isn number := 2; -- 2 = Telefon v_KonDatum_dt date := sysdate; v_KonUhrzeit_ts timestamp := systimestamp;
Thank you
Sven
Edited by: 923182 the 25.03.2012 06:38Welcome to the forum!
Thank you for providing your information to Oracle version. You must provide this whenever you post a new question.
All parameters for procedures and functions must be listed in the method call unless the parameter has a DEFAULT value.
You said a procedure with 32 settings but have listed only 24 in the method call.
It's ok if the 8 other parameters have default values, but they do not. You can use NULL by DEFAULT, if a parameter does not need to have a value or cannot be used.Your anonymous block does not call the procedure, there is no 'settings', that's why you don't see the problem there.
See specification of default values for the parameters of subprogramme in the PL/SQL language reference
http://docs.Oracle.com/CD/B28359_01/AppDev.111/b28370/subprograms.htm#i23202>
By initializing formal IN the settings to the default values, you can pass a different number of actual parameters to a subprogram, accepting the default values to the actual parameters is omitted. You can also add new formal parameters without having to change all calls to the subprogramme.If a real parameter is omitted, the default value of the corresponding formal parameter is used.
You can't ignore a formal parameter by omitting its actual parameter. To omit the first parameter and specify the second, use named notation (see passing parameters real subprogramme positional, Named or mixed Notation).
You cannot assign NULL to an uninitialized formal parameter by omitting its actual parameter. You must assign NULL as default or explicitly pass null.
>
You can also use nototation "Named" when you specify parameters by nameSee passing parameters real subprogramme positional, Named or mixed Notation in the same doc.
raise_salary(amount => bonus, emp_id => emp_num);
-
anonymous block of pl/sql procedure ended with no result
started just learning oracle pl/sql and I am facing a problem here.
I have no problem to compile, but whenever I run the nth procedure would seem except the following message is displayed and not showing any output that should not be the case: block anonymous filled
I tried to set serveroutput size 50000; changes but nth.
Here is my pl/sql procedure not sure if I'm doing things.
CREATE OR REPLACE PROCEDURE CHECK AS
empnum NUMBER;
EmpName VARCHAR2 (50);
BEGIN
Select employee.e #.
, Employee.Name since it is
in empnum
empname
Join driver used on driver.e # employee.e = #.
Mechanic to join on mechanic.e # driver.e = #;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT. Put_line ('ok');
END CHECK;
/
I'm trying to achieve the same result in the following sql query:
select employee.name, employee.e#
from employee join driver
on driver.e# = employee.e#
join mechanic
on mechanic.e# = driver.e#
where rownum = 1;If there is no similar records if it will display the employee name and numbers. If there is no such document found it will show an ok message.
My bad, NO_DATA_FOUND is not triggered when a select statement is used like that. This is a way to approach it.
create or replace procedure check
as
number of empnum;
EmpName varchar2 (50);
is_exist boolean;
Start
I'm in)
Select employee.e #.
, Employee.Name since it is
Join driver used on driver.e # employee.e = #.
Mechanic to join on mechanic.e # driver.e = #.
)
loop
is_exist: = true;
dbms_output.put_line (' e #-' | lpad (IE #, 20, ' ') |) ' name ' - | i.Name);
end loop;If not is_exist then
raise the no_data_found;
end if;exception
When no_data_found then
dbms_output.put_line ('ok');
end check;
/This isn't a very elegant way of doing things. But I am limited to knowledge of the requirement of the company. Therefore, the best I could come up with. If you can explain how you're going to put this procedure into your business situation we could help you better.
-
DECLARE
the stored procedure varchar2 (25);
BEGIN
-DBMS_OUTPUT. Put_line ("enter the name of the procedure :'||: procname");
the stored procedure: =: procname;
DBMS_OUTPUT. Put_line (' procedure :'|| stored procedure);
stored procedure.
END;
: procname is a variable binding in the apex to switch the running value.
This is the error I get
ORA-06550: line 7, column 2:
PLS-00221: "STORED procedure" is not a procedure or is not defined
ORA-06550: line 7, column 2:
PL/SQL: Statement ignored
5the stored procedure: =: procname;
6 DBMS_OUTPUT. Put_line (' procedure :'|| stored procedure);
7. the stored procedure.
8 END;
SmtWtL wrote:
DECLARE
the stored procedure varchar2 (25);
BEGIN
-DBMS_OUTPUT. Put_line ("enter the name of the procedure :'||: procname");
the stored procedure: =: procname;
DBMS_OUTPUT. Put_line (' procedure :'|| stored procedure);
stored procedure.
END;
: procname is a variable binding in the apex to switch the running value.
This is the error I get
ORA-06550: line 7, column 2:
PLS-00221: "STORED procedure" is not a procedure or is not defined
ORA-06550: line 7, column 2:
PL/SQL: Statement ignored
5. the stored procedure: =: procname;
6 DBMS_OUTPUT. Put_line (' procedure :'|| stored procedure);
7. the stored procedure.
8 END;
What you're trying to achieve?
Bind variables cannot be used for the dynamic execution of stored programs. Dynamic SQL using lexical rather than bind substitution must be used to run when the program name is not known until execution of the programs.
declare sproc varchar2(25); begin sproc := :procname; dbms_output.put_line('procedure:'||sproc); execute immediate 'begin ' || sproc || '; end;'; -- DO NOT DO THIS! end;
It is a fundamental design flaw and a security disaster. It's stops essential compilation controls is performed and is open to attack by SQL injection and other security vulnerabilities. There is no good reason to do this.
-
create or replace FUNCTION get_table_md (p_owner in varchar2, p_table IN VARCHAR2) RETURN CLOB IS
-Define local variables.
/ * declare
p_owner varchar2 (30): = "AVTYM";
p_table IN VARCHAR2 (30): = "TRANSACTION_HEADER";
*/
h NUMBER; -handle returned by OPEN
e NUMBER; -handle returned by ADD_TRANSFORM
p_tableref varchar2 (30);
doc CLOB.
Doc2 CLOB.
BEGIN-Specify the type of object.
h: = DBMS_METADATA. OPEN ('TABLE');-Use filters to specify the desired object.
DBMS_METADATA. SET_FILTER (h, 'SCHEMA', p_owner);
DBMS_METADATA. SET_FILTER (h, 'NAME', p_table);-Request that the metadata be transformed into creation DDL.
th: = DBMS_METADATA. ADD_TRANSFORM (h, 'DDL');-Retrieves the object.
doc: = DBMS_METADATA. FETCH_CLOB (h);
-Free resources.
DBMS_METADATA. Close (h);
p_tableref: = substr (p_table, 1, 25). ' $RDEF';
Doc2: is REGEXP_replace(doc,p_table,p_tableref,1,1,'im');.
doc: = REGEXP_replace(doc2,'"CREATE_DT"','"EXCHANGE_DT"',1,2,'im');
-dbMS_OUTPUT. Put_line (doc);
RETURN doc;END;
Hello
check the privilege you may have granted by a role that you need direct access to the object and not by the role. You can test if you are granted by a role, by running the SET command role no and see if you can still run the anonymous block.
Thank you
-
anonymous block procedure.
Hi experts,
If I wrote the procedure and the means of functions and tables
I use able to recover. USER_TABLES, such user_functions, user_objects. Ok
Only once if I wrote an anonymous block of procedure. »
How I see it. is there a way to drop that...
is this possible?
Oracle db10g
Sorry for the delay of edition.ADF 7 wrote:
If I wrote the procedure and the means of functions and tables
I use able to recover. USER_TABLES, such user_functions, user_objects. Ok
Only once if I wrote an anonymous block of procedure. »
How I see it. is there a way to drop that...There are 2 types of units of PL/SQL code.
Named units of PL/SQL. Here are the packages, procedures and functions. They are named. They are stored within the database. They are compiled. The compiled version is also stored in the database.
Units of PL/SQL without name. They are anonymous PL/SQL blocks. These are created by the client. They have no name. They cannot be procedures, functions or packages. They may contain a function or procedure localized nested. They went through the Oracle client. Oracle creates a cursor by analyzing the block and then running the cursor. Client bind variables are supported in the anonymous PL/SQL block.
Unnamed (anonymous) PL/SQL is used by customers to call units named PL/SQL.
Named units generally contains business and the processing logic and validation - providing an interface for the client to the logical database in Oracle.
As nameless units exist only as sliders in the memory of the server (LMS), these impossible to remove, because there is no static database object to drop.
-
Error in procedure Stoerd, but working in anonymous block.
declare
CUR cursor is
Select 'Edit'. Object_type | » '|| Object_name | ' Compile ' Invalid_Obj, Object_Type, Object_Name
From Dba_Objects has
Where A.Owner = 'Dataload' and A.Status = 'Invalid';
Begin
For I In news
Loop
Begin
Immediately run I.Invalid_Obj;
Exception
While others then
NULL; - Dbms_Output.Put_Line (Sqlerrm |': ' |) I.Object_Type |' '|| I.Object_Name);
End;
End loop;
Exception
While others then
NULL; - Dbms_Output.put_line (SQLERRM);
End;
Above anonymous block execute successfully.
but when I create as stored procedure then, it gives the error as
There is no such thing as Dba_Objects.
Please, suggest what I do for the stored procedure?
Published by: Nilesh hole on June 2, 2010 12:00 AMIf you don't have any rights sys you that should
(a) request the administrator to run utlrp (preferably, as this always runs compilation in the right order)
(b) do not use dba_objects but user_objects, assuming that you are connected as a LOADINGIn a normal situation, this should not be necessary, so you should always question why you even want to do (and are reinventing the wheel). The dbms_utility package also has a COMPILE_SCHEMA procedure.
-----------
Sybrand Bakker
Senior Oracle DBA -
Block based on the stored procedure cannot modify Default_where clause
Hi all
I tried to create a block based on the stored procedure that it works very well with the result set for the refcursor. But if I need to add filters on the block using where clause in the palette of goods or
using the property block set in where clause, it does not error but does not review filters .
tried everything to you please let me know. This is a restriction whereby we can set filters on the block when we create the block based on the stored procedure.
Thank you
Check in Form Builder Help:
Creating a block of data from a procedure that uses a ref cursor
... You can't pass a WHERE or ORDER BY clause clause in a stored procedure.
But you can send your WHERE condition using the query Source Arguments.
If the procedure is on the side of the database (not in the forms module), ensure that the procedure is not vulnerable to injection of SQL code.
Kind regards
Zlatko
-
How to run four procedures, in order, by using anonymous block
Hello
I am trying to run four procedures, in order, by using anonymous block. If one of the procedure fails remaining should get executed. How can I achieve this?
For example:
BEGIN
PROC1;
Proc2; -Suppose that Proc2 will fail, it should not affect the execution of Proc3 and proc 4
Proc3;
Proc 4;
END;Thank you!
Hello
Maybe this can help you:
BEGIN begin Proc1; exception when others then dbms_output.put_line('proc1 ' || sqlcode || ' ' || sqlerrm); end; begin Proc2; exception when others then dbms_output.put_line('proc2 ' || sqlcode || ' ' || sqlerrm); end; begin Proc3; exception when others then dbms_output.put_line('proc3 ' || sqlcode || ' ' || sqlerrm); end; begin Proc4; exception when others then dbms_output.put_line('proc4 ' || sqlcode || ' ' || sqlerrm); end; END;
In your case, it may be useful if your procedures have their own exception handlers, so they never fail. But then you need a sort of exception information that is displayed.
concerning
Kay -
Appellant DB stored procedures before committing changes.
Hello
I use JDeveloper 11.1.1.6.0.
I have a use case that requires me to do the following:
When you create a new transaction in master-detail, I have to call a stored procedure that selects the transaction full master/detail and insert it into a table to archive. To resolve this problem, I have substituted the beforeCommit method in the implementation of AM class and call the stored procedure from the pharmacokinetics of the current line in my header VO. I found this solution after reading [http://www.oracle.com/technetwork/developer-tools/jdev/index-092937.html] written by Steve Meunch. More specifically the following, that I needed the whole transaction in the database before calling the stored procedure.
+ POST-FORMULAIRES-COMMIT
Run the code after the "posted" all the lines necessary for the database, but before issuing the VALIDATION data at the end of the transaction. If you want a single block of code for the entire transaction, you can override the doCommit() method in a custom DBTransactionImpl object and write code before calling super. To run the code specific to the entity before validation for each entity affected under the operation, override the method beforeCommit() on your entity object and write the code it. +
The second part of the use case allows a deletion on the header only. This action should also call the stored procedure and insert the transaction full master/detail in the table of archive. To do this, my previous solution does not work. The current line is not the line that has been deleted. In the article referenced above, I assumed that the following could offer me the solution,
+ PRE DELETE
Run the code before the line removed the datablock is REMOVED from the database during the processing of "post". Method doDML() override in your entity class and if the operation is equal to DML_DELETE, then write the code before you call the super. +
Actually it works, but the overridden beforeCommit also runs, so I have the deleted record and the next record in the VO inserted in my table of archives.
I tried a few options by exposing the method that calls that the stored procedure for my UI project, but it has also some problems, as my PK is filled with DBSequences and at the point of my workflow when I run the sequence method is not yet filled.
Ideally, I'd like that some entries in how I might solve this problem to my business services layer.
Concerning
Leon.To be honest I would always fix this to the database layer, copy the following code is negligible in the PLSQL triggers, why clutter up the average level by additional detours?
CM.
-
block of data based on a stored procedure with the input arguments
Hello
I am able to create a block of data based on the stored procedure.
but I want that procedure to take both of the input arguments and I am facing issue while setting the value for this input arguments from another block element.
Please someone help, how to set the value of the input of another block-element of control argument? (Note: data block is based on the stored procedure)
Thanks in advance,
Jean François AnandanI have an example that really works
in the ownership of block
arguments of data source query that you have two sections
names one argument he write the name of the argument on the right, type the setting, fashion and value: block1.name and then pass the value to the procedure
-
change the caption of the label of a result of the stored procedure
I have need to change the caption of the label on the report using the generator of reports and the source of data to a stored procedure.
Your information and your help is much appreciated,
Kind regards
Iccsi
There are at least two ways to handle this.
The first is to transmit the column headings to the State as parameters.
The second is to use a subreport that uses a record-results set that contains the column headers. You will need to set the sub-rapport to zero margins to get things to line up correctly.
-
How to edit or change a stored procedure?
I created a stored procedure with the name getRecords 1 months ago
I want to change this getRecords of stored procedure
Please tell me how to change the stored procedureSo what you would do is
Starting sqldeveloper, connecting as the owner of the procedure.
In the tree list, expand the entry procedures.
You will see all the procedures in this scheme.
Double-click the procedure that you want to modify, and a window opens with the source code.-----------
Sybrand Bakker
Senior Oracle DBA -
Re: "insufficient privileges" error when you run the Java stored procedure in another schema
I get an "insufficient privileges" error when you run the Java stored procedure in another schema, see details below. I don't know what are missing privileges (I already granted the EXECUTE privilege), suggestions? -Thank you.
Define a simple java class and deploy it as a Java stored procedure to test:
Schema: User1
test of the package;
public class HelloWorld {}
public HelloWorld() {
Super();
}
public static String Hello () {}
Return "HELLO";
}
}
CREATE or REPLACE FUNCTION HELLO RETURN VARCHAR2 AUTHID CURRENT_USER AS LANGUAGE JAVA NAME ' test. HelloWorld.hello () return java.lang.String';
Grant execute on USER2 HELLO
Test the Java stored procedure through the PL/SQL function call (in the same schema):
Schema: User1
SET SERVEROUTPUT ON
DECLARE
v_Return VARCHAR2 (200);
BEGIN
v_Return: = User1. HELLO;
DBMS_OUTPUT. Put_line ('v_Return =' | v_Return);
END;
anonymous block filled
v_Return = HELLO
Test the Java stored procedure through the PL/SQL function call in a different pattern:
Schema: USER2
SET SERVEROUTPUT ON
DECLARE
v_Return VARCHAR2 (200);
BEGIN
v_Return: = User1. HELLO;
DBMS_OUTPUT. Put_line ('v_Return =' | v_Return);
END;
Error report-
ORA-01031: insufficient privileges
ORA-06512: at "User1." HELLO', line 1
ORA-06512: at line 4 level
01031 00000 - "insufficient privileges".
* Cause: An attempt was made to change the user name or password
without the privilege appropriate. This error also occurs if
trying to install a database without the need for employment
access privileges.
When Trusted Oracle is configure in DBMS MAC, this error may occur
If the user has been granted the privilege necessary for a higher label
that the connection is active.
* Action: Ask the database to perform the operation or grant administrator
the required privileges.
For users Trusted Oracle get this error, well that granted the
the privilege that is suitable for the top label, ask the database
administrator to grant the privilege to the appropriate label.
You have created the function with AUTHID CURRENT_USER, which means that the function is executed with the rights of the applicant (but not with the rights of the author). This means that the applicant must have grants (directly or through roles) on all used/accessible objects in the service. In your case the user USER2 has not granted with EXECUTE on the class/source Java test. Class HelloWorld, causing the ORA-01031 exception. You create service without AUTHID CURRENT_USER (i.e. with AUTHID DEFINE, which is by default, if you do not have a specific reason to use AUTHID CURRENT_USER) or grant EXECUTE on JAVA test SOURCE. Class HelloWorld to User2.
Dimitar
-
Error of insufficient privileges on the creation of model running in a stored procedure
Hello
I get the error of insufficient privileges on execution of the DBMS_DATA_MINING. Script CREATE_MODEL in a stored procedure.
If I run the same DBMS_DATA_MINING. Script CREATE_MODEL in an anonymous block with just begin... end;
I am able to create a model successfully, but if I do the same thing after having stored the script in the stored procedure, it is throwing error of insufficient privileges.
Scripts:
BEGIN
DBMS_DATA_MINING. () CREATE_MODEL
Model_name = > < template name >
mining_function = > dbms_data_mining. CLASSIFICATION,
DATA_TABLE_NAME = > < data table name >
CASE_ID_COLUMN_NAME = > < case ID >
target_column_name = > < target column >
SETTINGS_TABLE_NAME = > < settings table >
DATA_SCHEMA_NAME = > < schema >
SETTINGS_SCHEMA_NAME = > < schema >
);
END;
The foregoing, works very well and created a model with the model given with success.
But if I keep the above, in a stored procedure as - MINING_TESTING
create or replace procedure MINING_TESTING as
BEGIN
DBMS_DATA_MINING. () CREATE_MODEL
Model_name = > < template name >
mining_function = > dbms_data_mining. CLASSIFICATION,
DATA_TABLE_NAME = > < data table name >
CASE_ID_COLUMN_NAME = > < case ID >
target_column_name = > < target column >
SETTINGS_TABLE_NAME = > < settings table >
DATA_SCHEMA_NAME = > < schema >
SETTINGS_SCHEMA_NAME = > < schema >
);
END;
Compiles correctly.
Enforcement - EXEC MINING_TESTING;
Error message throw sufficient privileges.
The error message complete below:
Error report:
ORA-01031: insufficient privileges
ORA-06512: at "SYS." DBMS_DATA_MINING', line 1798
ORA-06512: at "MIS_ORABI_ODM.CA_MINING_TESTER", line 3
ORA-06512: at line 1
01031 00000 - "insufficient privileges".
* Cause: An attempt was made to change the user name or password
without the privilege appropriate. This error also occurs if
trying to install a database without the need for employment
access privileges.
When Trusted Oracle is configure in DBMS MAC, this error may occur
If the user has been granted the privilege necessary for a higher label
that the connection is active.
* Action: Ask the database to perform the operation or grant administrator
the required privileges.
For users Trusted Oracle get this error, well that granted the
the privilege that is suitable for the top label, ask the database
administrator to grant the privilege to the appropriate label.
Hello
DataMiner UI grants privileges to a role, so if you're depending on these privileges you must proceed as follows when you create a stored procedure.
Your stored procedure was created with the default authid which is definers. It will not use the privileges for the role. Solution is to create the stored procedure with authid current_user. This will pick up the privileges for the role. Another option is to apply the following subsidies directly to the user account:
grant CREATE MINING MODEL
CREATE THE TABLE,
IN ORDER TO CREATE
Example of stored procedure:
create or replace procedure MINING_TESTING AUTHID CURRENT_USER as
BEGIN
DBMS_DATA_MINING. () CREATE_MODEL
MODEL_NAME =>
mining_function-online dbms_data_mining. CLASSIFICATION,
DATA_TABLE_NAME =>
CASE_ID_COLUMN_NAME =>
target_column_name =>
SETTINGS_TABLE_NAME =>
DATA_SCHEMA_NAME =>
SETTINGS_SCHEMA_NAME =>
);
END;
Thank you, Mark
Maybe you are looking for
-
I have an old 40GB iPod system. He has not been charged in awhile. Now when I try to load makes it unit beep and the screen becomes between the Apple and the www.apple.com/support/iPod is my ipod cooked or can I reset. Is - this battery? Help!
-
IOS 9.3.3 e-mail bug looking IPAD
DO NOT UPDATE THE IOS 9.3.3 The e-mail search engine died as a stiff on my iPad. Wait until you receive 9.3.4.
-
Scheduler of tasks, possible malware attack vector
I noticed that more and more PC I clean have tasks in Task Scheduler that point to malicious sites. I see also a few comments of MSE responses stating the same thing. This might be a reason why some of the software malicious guard re-appearance. A
-
I can't uninstall Zoom of USB Modem on my Windows Vista computer
I have problems to uninstall the Modem USB Zoom on HP Windows Vista Home Premium computer, it does not give me any error message. He asks me to continue and click on continue and then it comes back from the beginning. EarthLink advised me to uninstal
-
SSH on vShield Edge using Java CCES
I am trying to connect to vShield Edge using jsch for SSH connection library.Connection to a linux server it works perfectly, but connected to the vShield edge server, the output is:vtysh: invalid option-'c '.Try "vtysh - help ' for more information.