Scheduling anonymous block
Is it possible to schedule an anonymous block? if so, how can I do it? some sample code is appreciated.
Edited by: jdude on 20-Oct-2011 04:34
This is an example for stored procedure, I can't figure out how to write one for an anonymous block
begin
dbms_scheduler.create_job
(job_name => 'SCOTT.RUN_SCOTTS_PROC',
job_type => 'STORED_PROCEDURE',
job_action=> 'SCOTT.SCOTTS_PROC',
start_date=> trunc(sysdate+1)+1/24,
repeat_interval=> 'FREQ=DAILY; BYDAY=MON,TUE,WED,THU,FRI,SAT; BYHOUR=1;',
enabled=>true,
auto_drop=>false,
comments=>'Converted from job 152152');
end;
Edited by: jdude on 20-Oct-2011 04:42
Thanks guys,
I'm getting strange errors like:
Encountered the symbol "TEST" when expecting one of the following:
) , * & = - + < / > at in is mod remainder not rem
<an exponent (**)> <> or != or ~= >= <= <> and or like like2
like4 likec between || multiset member submultiset
The symbol ", was inserted before "TEST" to continue.
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
Please advise, the anonymous block ran with no issue inside a .sql file until when attempts were made to create a job base on this anonymous block.
Please see:
begin
dbms_scheduler.create_program
(program_name => 'TEST',
program_type => 'PLSQL_BLOCK',
program_action =>'
DECLARE
CURSOR test_cursor IS
SELECT name, data
FROM test_table
WHERE name = 'test';
test test_cursor%ROWTYPE;
BEGIN
OPEN test_cursor;
LOOP
EXIT WHEN test_cursor%NOTFOUND;
FETCH test_cursor INTO test;
END LOOP;
INSERT INTO test_table
VALUES (test.name, test.data);
COMMIT;
CLOSE test_cursor;
END;
enabled => TRUE);
dbms_scheduler.create_job
(job_name => 'TEST',
program_name => 'TEST',
start_date => SYSDATE,
repeat_interval=> 'FREQ=HOURLY;',
auto_drop=>false,
enabled => TRUE,
comments=>'TEST JOB');
end;
I have looked at tutorials here:
http://download.oracle.com/docs/cd/B28359_01/server.111/b28310/schedadmin006.htm#i1009099
but I don't see why it doesn't work..this is strange...
Edited by: jdude on 21-Oct-2011 00:34
Edited by: jdude on 21-Oct-2011 00:36
Edited by: jdude on 21-Oct-2011 00:38
Edited by: jdude on 21-Oct-2011 00:39
Similar Messages
-
INVALID CURSOR - Anonymous Block calling Cursor in function
I am getting an error when trying to call my cursor.
CREATE OR REPLACE PACKAGE tax_update
AS
TYPE gencur IS ref cursor;
FUNCTION tax_sf
p_state IN bb_tax.state%type,
p_thecursor IN OUT gencur
RETURN NUMBER;
END;
CREATE OR REPLACE PACKAGE BODY tax_update
AS
FUNCTION tax_sf
p_state IN bb_tax.state%type,
p_thecursor IN OUT gencur
RETURN NUMBER
IS
lv_taxrate NUMBER;
BEGIN
OPEN p_thecursor FOR
SELECT taxrate
FROM bb_tax
WHERE state = p_state;
RETURN lv_taxrate;
END;
END;
DECLARE
tax_cur tax_update.gencur;
rec_tax bb_tax%rowtype;
BEGIN
LOOP
FETCH tax_cur INTO rec_tax;
EXIT WHEN tax_cur%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(rec_tax.taxrate);
END LOOP;
END;
DECLARE
ERROR at line 1:
ORA-01001: invalid cursor
ORA-06512: at line 6Assignment is to create a package that will hold tax rates by state in a packaged cursor. The package will contain a function that can receive a 2 character state abbr. as an argument and find a match in the cursor and return the tax rate for tha tstate. An anonymous block will test the function with state of NC.
Can anyone assist?You would need to call the function to open the cursor before you try to fetch from the cursor
DECLARE
tax_cur tax_update.gencur;
rec_tax bb_tax%rowtype;
l_some_number number;
BEGIN
l_some_number := tax_update.tax_sf( <<some state parameter>>, tax_cur );
LOOP
FETCH tax_cur INTO rec_tax;
EXIT WHEN tax_cur%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(rec_tax.taxrate);
END LOOP;
END;A couple of points, though.
1) Your function returns a NUMBER but that NUMBER will always be NULL. It seems rather unlikely that this is really what you want. It would seem to make more sense for the function to return the cursor rather than returning a superfluous number.
2) Your function requires a `bb_tax.state%type` parameter. But your anonymous block doesn't seem to have any concept of a state so I'm not sure what you want to pass in there.
3) Looking at the code, it seems a bit odd that your cursor returns a single column of data. If a state can have multiple rates, wouldn't you need to select some additional criteria in order to figure out which sort of tax each row represents or to otherwise differentiate different rows? If a state can only have a single tax rate, it makes no sense to open a cursor that is only going to ever return a single row.
4) There is no need to declare your own weak ref cursor type (tax_update.gencur). You can just use the Oracle built-in type SYS_REFCURSOR.
Justin -
Reference value of an SQLPLUS variable in a PL/SQL anonymous block
All,
Is there a way of referencing an SQLPLUS variable within a PL/SQL anonymous block. See my example below........
sqlplus -s /@${L_DB_SID} <<-ENDOFSQL >> ${L_LOGFILE}
SET FEEDBACK OFF
SET PAGES 0
SET SERVEROUTPUT ON
WHENEVER SQLERROR EXIT SQL.SQLCODE
WHENEVER OSERROR EXIT 2
VARIABLE l_ret_sts NUMBER;
VARIABLE l_ret_msg VARCHAR2(300);
exec sh_plsql_owner.sh\$secure_batch.p\$set_role(p_ret_sts => :l_ret_sts);
begin
if :l_ret_sts > 0 then
dbms_output.put_line('l_ret_sts:'||:l_ret_sts||':SECURITY');
else
${L_PLSQL_PROG}(p_ret_type => 0, p_ret_sts => :l_ret_sts, p_ret_msg => :l_ret_msg);
dbms_output.put_line('l_ret_sts:'||NVL(:l_ret_sts,0));
dbms_output.put_line('l_ret_msg:'||:l_ret_msg);
end if;
end;
exit
ENDOFSQL
I need to be able to reference :l_ret_sts in the begin block using the if statement "if :l_ret_sts > 0 then"
:l_ret_sts is populated in a procedure call beforehand.
However it seems as though the begin block cannot reference the value returned to :l_ret_sts.
Any ideas.
Ian.Managed to solve this. I put my call to the package that the role enables via dynamic sql....
sqlplus -s /@${L_DB_SID} <<-ENDOFSQL >> ${L_LOGFILE}
SET FEEDBACK OFF
SET PAGES 0
SET SERVEROUTPUT ON
WHENEVER SQLERROR EXIT SQL.SQLCODE
WHENEVER OSERROR EXIT 2
VARIABLE l_ret_sts NUMBER;
VARIABLE l_ret_msg VARCHAR2(300);
exec dbms_application_info.set_client_info('CONTROL-M');
exec sh_plsql_owner.sh\$secure_batch.p\$set_role(p_ret_sts => :l_ret_sts);
declare
v_text varchar2(500);
begin
if :l_ret_sts > 0 then
dbms_output.put_line('l_ret_sts:'||:l_ret_sts||':SECURITY');
else
v_text := 'begin ${L_PLSQL_PROG}(p_ret_type => 0, p_ret_sts => :1, p_ret_msg => :2);end;';
execute immediate v_text using in out :l_ret_sts, in out :l_ret_msg;
dbms_output.put_line('l_ret_sts:'||NVL(:l_ret_sts,0));
dbms_output.put_line('l_ret_msg:'||:l_ret_msg);
end if;
end;
exit
ENDOFSQL
Cheers
Ian. -
Schedule line blocked for delivery
Hi Friends,
Can you please tell what does Schedule line blocked for delivery ( LIFSP ) means?can you please explain the business process involved in this?
Regards.
DineshAt schedule line level, the following are some important prerequisites must be fulfilled, else the same would be set as blocked:
1. The schedule line must be due for shipping on the specified selection date.
2. The schedule line is due for shipping as the material availability date or the transportation scheduling date is reached.
3. The schedule line is not blocked for delivery.
4. The delivery quantity must be greater than one.
5. The items in the order must be fully processed.
6. The product status of the material must permit delivery.
7. No credit check are pending.
Regards,
Gauravjit
Reward Points if solution is helpful. -
How to declare in anonymous block
Declare
CURSOR c_je2acct_othr
IS
SELECT j.jemq_num, j.ml_retail_account,
-- (CASE WHEN j.exer_type = 4 THEN j.sar_shares ELSE j.shares END) shares, -- removed * -1 from sar_shares Manu 12/02/04
/* Commented 02/01/07*/
(CASE WHEN j.exer_type = 4 THEN
fn_get_shares(u.user_id,u.exer_num,u.soc_sec,j.
sar_shares)
ELSE (case when u.exer_type=2 and u.opts_exer!=u.shrs_sold and j.shares=u.shrs_sold then 0 else j.shares end)
END) shares,
-- removed * -1 from sar_shares Manu 12/02/04
j.name_first,
j.name_last, j.exer_type, j.ml_sec_num, j.ivr_plan_num,
j.exer_dt, j.grant_dt, j.user_id, j.mlu_rowid, j.settle_dt,
j.exer_num, j.plan_type, j.grant_num, j.acct_num_othr,
j.add_cancel,
/* (CASE WHEN j.exer_type = 4 THEN j.sar_cash_amount * -1 -- turned negative Manu 12/02/04 ml_retail distr
commented the above line for calculation of proceeds into other account for sar sale.
(CASE WHEN j.exer_type = 4 THEN
Pk_Xop_Citibank_Forex.fn_get_netamount(u.user_id,u.
exer_num,u.soc_sec,
u.sar_cash_amount,NVL(u.comm_value, 0),
NVL(u.tot_fee, 0),
NVL(u.multi_curr_handling_fee, 0))
-- Removed the negative as on ml_exer_upload all values are +ve.
ELSE
( (DECODE(u.exer_type,0,u.opts_exer * u.mkt_prc,u.shrs_sold * u.mkt_prc
- ( ROUND((u.opts_exer * NVL (u.opt_prc, 0)),2)
-- SPIF 39060 Added a Round of condition.
+ DECODE (NVL (u.shrs_wthld_for_taxes, 'N'),
'Y', 0,
ROUND (u.tot_tax, 2)
+ u.tot_fee
+ NVL(u.multi_curr_handling_fee,0)
+ u.comm_value
- u.backup_withholding
END ) AS gl_amt,
T.je_othr_mlacct_jemsg AS vc_trailer_desc,
u.opts_exer ,
u.shrs_sold,
u.rsu_type
FROM TB_XOP_JEMQ j, TB_ML_EXER_UPLOAD u, TB_FC_COMPY T
WHERE j.q_flag = 'N' AND u.je_flag = 'Y'
AND j.entry_dttime >= TRUNC (SYSDATE)
AND j.entry_dttime < TRUNC (SYSDATE) +1
AND j.source = 'X'
AND j.acct_num_othr != ' '
and (case when u.exer_type=2 and u.opts_exer!=u.shrs_sold then (case when j.shares=u.shrs_sold then 0 else 1 end) else 1 end)=1 FIx for PCTUP00566081
AND ( disp_flag <> 'D' OR disp_flag IS NULL ) Added by MARAN ARUNACHALAM on 01/25/2011 for PCTUP00493542 Fix
and j.current_status = '2Q' removed not required now in new plan
AND NOT EXISTS (
SELECT 1
FROM TB_XOP_JEMQ j2
WHERE j2.prev_jemq = j.jemq_num
AND source = 'T'
AND j.add_cancel = j2.add_cancel
AND j.user_id = j2.user_id
AND j.exer_num = j2.exer_num)
AND j.mlu_rowid = u.ROWID
AND 'CMS'||T.compy_acronym||'_USER' = j.user_id
ORDER BY add_cancel DESC;
v_mlac_mesg VARCHAR2(1000);
-- JE_OTHR_MLACCT_JEMSG
BEGIN
dbms_output.put_line('success');
FOR v_je2acct_othr IN c_je2acct_othr
LOOP
dbms_output.put_line('success1');
BEGIN
dbms_output.put_line('success2');
IF v_je2acct_othr.add_cancel = 'C'
THEN
dbms_output.put_line('success3');
UPDATE TB_XOP_JEMQ
SET add_cancel = DECODE(current_status,
'RJ',
add_cancel,
'C'),
q_flag = DECODE(current_status, 'RJ', q_flag, 'N'),
activ_dt = DECODE(current_status,
'RJ',
activ_dt,
SYSDATE)
WHERE prev_jemq = v_je2acct_othr.jemq_num
AND user_id = v_je2acct_othr.user_id
AND exer_num = v_je2acct_othr.exer_num
AND source ='T';
dbms_output.put_line('success4');
ELSIF v_je2acct_othr.add_cancel = 'A'
THEN
dbms_output.put_line('success5');
-- manipulating amount and shares to transfer when different exercise types
v_je2acct_othr.gl_amt :=( CASE
WHEN v_je2acct_othr.exer_type = 0 THEN 0
WHEN v_je2acct_othr.exer_type = 2 AND v_je2acct_othr.opts_exer
!= v_je2acct_othr.shrs_sold
THEN v_je2acct_othr.gl_amt
WHEN v_je2acct_othr.exer_type = 2 AND v_je2acct_othr.opts_exer =
v_je2acct_othr.shrs_sold
THEN v_je2acct_othr.gl_amt
ELSE v_je2acct_othr.gl_amt
END );
---- Commented on 11/01/2006 For Fixing 30585
/* v_je2acct_othr.shares :=( CASE
WHEN v_je2acct_othr.exer_type = 0 THEN v_je2acct_othr.opts_exer
WHEN v_je2acct_othr.exer_type = 2 AND v_je2acct_othr.opts_exer != v_je2acct_othr.shrs_sold
THEN v_je2acct_othr.opts_exer - v_je2acct_othr.shrs_sold
WHEN v_je2acct_othr.exer_type = 2 AND v_je2acct_othr.opts_exer = v_je2acct_othr.shrs_sold
THEN 0
ELSE v_je2acct_othr.shares
END );*/
---- Commented on 11/01/2006 For Fixing 30585
v_je2acct_othr.shares :=( CASE
WHEN v_je2acct_othr.exer_type = 0 THEN v_je2acct_othr.
Shares
--- Replaced opts_exer with the Shares amount from the previous journal for fixing 30585
WHEN v_je2acct_othr.exer_type = 2 AND v_je2acct_othr.opts_exer
!= v_je2acct_othr.shrs_sold and v_je2acct_othr.shares!=0 and v_je2acct_othr.plan_type <> 0 -- Added plantype condition for CQ:PCTUP00493542
THEN v_je2acct_othr.Shares - v_je2acct_othr.shrs_sold
--- Replaced opts_exer with the Shares amount from the previous journal for fixing 30585
WHEN v_je2acct_othr.exer_type = 2 AND v_je2acct_othr.opts_exer =
v_je2acct_othr.shrs_sold
THEN 0
ELSE v_je2acct_othr.shares
END );
dbms_output.put_line('success6');
IF LENGTH(TRIM(v_je2acct_othr.acct_num_othr))=8 OR TRIM(v_je2acct_othr.acct_num_othr) IS NULL
THEN
v_mlac_mesg :=NULL;
ELSE
v_mlac_mesg :='Check the ml a/c length';
dbms_output.put_line('success7');
END IF;
INSERT INTO TB_XOP_JEMQ
(jemq_num,
prev_jemq,
ml_retail_account,
wcma_shares,
shares, wcma_taxes, tax_amt,
wcma_reimburse,
reimburse_amt,
name_first,
name_last, exer_type,
ml_sec_num, wcma_bulking, bulking_amt,
ivr_plan_num,
exer_dt, grant_dt,
user_id, source,
mlu_rowid, settle_dt,
exer_num, plan_type,
grant_num,
vc_trailer_desc, rsu_type
VALUES (Pk_Xop_Get_Jemqnum.fn_xop_get_jemqnum,
v_je2acct_othr.jemq_num,
v_je2acct_othr.acct_num_othr,
-- 2nd ml_retail_account,
v_je2acct_othr.ml_retail_account,
-- move shares from old acct to 2nd acct above
v_je2acct_othr.shares,
--this is SHARES
--wcma_taxes
0,
--tax_amt,
v_je2acct_othr.ml_retail_account,
-- move gl_amt from old acct to 2nd acct above
v_je2acct_othr.gl_amt * -1,
v_je2acct_othr.name_first,
v_je2acct_othr.name_last, v_je2acct_othr.
exer_type,
v_je2acct_othr.ml_sec_num, ' ',
--wcma_bulking,
0,
--bulking_amt,
v_je2acct_othr.ivr_plan_num,
v_je2acct_othr.exer_dt, v_je2acct_othr.
grant_dt,
v_je2acct_othr.user_id, 'T',
--source
v_je2acct_othr.mlu_rowid, v_je2acct_othr.
settle_dt,
v_je2acct_othr.exer_num, v_je2acct_othr.
plan_type,
v_je2acct_othr.grant_num,
v_je2acct_othr.vc_trailer_desc,
v_je2acct_othr.
rsu_type
dbms_output.put_line('success8');
END IF;
EXCEPTION
WHEN OTHERS
THEN
Pr_Xop_Log_Errors ( 'Code :'
|| NVL(v_mlac_mesg,SQLERRM)
|| ' at '
|| USER
|| 'at sub exec block in pop_je2acct_othr'
END;
dbms_output.put_line('success9'); -- end of begin within loop
END LOOP;
--COMMIT;
EXCEPTION
WHEN OTHERS
THEN
Pr_Xop_Log_Errors ( 'Code :'
|| NVL(v_mlac_mesg,SQLERRM)
|| ' at '
|| USER
|| 'at pk_xop_jemq.pop_je2acct_othr'
dbms_output.put_line('success10');
END;}
{ORA-06550: line 10, column 31:
PL/SQL: ORA-00904: "FN_GET_SHARES": invalid identifier
ORA-06550: line 6, column 11:
PL/SQL: SQL Statement ignored
ORA-06550: line 81, column 17:
PLS-00364: loop index variable 'V_JE2ACCT_OTHR' use is invalid
ORA-06550: line 81, column 14:
PL/SQL: Statement ignored}
HI friends, as i am getting two errors when running code in the anonymous block, then how to declare that 2 errors in declare section plz guide me}Noone, will read your code unless it is formatted like below. See the comments added
DECLARE
CURSOR c_je2acct_othr
IS
SELECT j.jemq_num,
j.ml_retail_account,
-- (CASE WHEN j.exer_type = 4 THEN j.sar_shares ELSE j.shares END) shares, -- removed * -1 from sar_shares Manu 12/02/04
/* Commented 02/01/07*/
CASE
WHEN j.exer_type = 4
--"The current user is not seeing the below function fn_get_shares.Privilege issue probably.
THEN fn_get_shares(u.user_id,u.exer_num,u.soc_sec,j. sar_shares)
ELSE (
CASE
WHEN u.exer_type=2
AND u.opts_exer!=u.shrs_sold
AND j.shares =u.shrs_sold
THEN 0
ELSE j.shares
END)
END) shares,
-- removed * -1 from sar_shares Manu 12/02/04
j.name_first,
j.name_last,
j.exer_type,
j.ml_sec_num,
j.ivr_plan_num,
j.exer_dt,
j.grant_dt,
j.user_id,
j.mlu_rowid,
j.settle_dt,
j.exer_num,
j.plan_type,
j.grant_num,
j.acct_num_othr,
j.add_cancel,
/* (CASE WHEN j.exer_type = 4 THEN j.sar_cash_amount * -1 -- turned negative Manu 12/02/04 ml_retail distr
commented the above line for calculation of proceeds into other account for sar sale.
CASE
WHEN j.exer_type = 4
THEN Pk_Xop_Citibank_Forex.fn_get_netamount(u.user_id,u. exer_num,u.soc_sec, u.sar_cash_amount,NVL(u.comm_value, 0), NVL(u.tot_fee, 0), NVL(u.multi_curr_handling_fee, 0))
-- Removed the negative as on ml_exer_upload all values are +ve.
ELSE ( (DECODE(u.exer_type,0,u.opts_exer * u.mkt_prc,u.shrs_sold * u.mkt_prc )) - ( ROUND((u.opts_exer * NVL (u.opt_prc, 0)),2)
-- SPIF 39060 Added a Round of condition.
+ DECODE (NVL (u.shrs_wthld_for_taxes, 'N'), 'Y', 0, ROUND (u.tot_tax, 2) ) + u.tot_fee + NVL(u.multi_curr_handling_fee,0) + u.comm_value ) - u.backup_withholding )
END ) AS gl_amt,
T.je_othr_mlacct_jemsg AS vc_trailer_desc,
u.opts_exer ,
u.shrs_sold,
u.rsu_type
FROM TB_XOP_JEMQ j,
TB_ML_EXER_UPLOAD u,
TB_FC_COMPY T
WHERE j.q_flag = 'N'
AND u.je_flag = 'Y'
AND j.entry_dttime >= TRUNC (SYSDATE)
AND j.entry_dttime < TRUNC (SYSDATE) +1
AND j.source = 'X'
AND j.acct_num_othr != ' '
--and (case when u.exer_type=2 and u.opts_exer!=u.shrs_sold then (case when j.shares=u.shrs_sold then 0 else 1 end) else 1 end)=1 -- FIx for PCTUP00566081
--AND ( disp_flag <> 'D' OR disp_flag IS NULL ) -- Added by MARAN ARUNACHALAM on 01/25/2011 for PCTUP00493542 Fix
--and j.current_status = '2Q' -- removed not required now in new plan
AND NOT EXISTS
(SELECT 1
FROM TB_XOP_JEMQ j2
WHERE j2.prev_jemq = j.jemq_num
AND source = 'T'
AND j.add_cancel = j2.add_cancel
AND j.user_id = j2.user_id
AND j.exer_num = j2.exer_num
AND j.mlu_rowid = u.ROWID
AND 'CMS'
||T.compy_acronym
||'_USER' = j.user_id
ORDER BY add_cancel DESC;
v_mlac_mesg VARCHAR2(1000);
-- JE_OTHR_MLACCT_JEMSG
BEGIN
dbms_output.put_line('success');
FOR v_je2acct_othr IN c_je2acct_othr
LOOP
dbms_output.put_line('success1');
BEGIN
dbms_output.put_line('success2');
IF v_je2acct_othr.add_cancel = 'C' THEN
dbms_output.put_line('success3');
UPDATE TB_XOP_JEMQ
SET add_cancel = DECODE(current_status, 'RJ', add_cancel, 'C'),
q_flag = DECODE(current_status, 'RJ', q_flag, 'N'),
activ_dt = DECODE(current_status, 'RJ', activ_dt, SYSDATE)
WHERE prev_jemq = v_je2acct_othr.jemq_num
AND user_id = v_je2acct_othr.user_id
AND exer_num = v_je2acct_othr.exer_num
AND source ='T';
dbms_output.put_line('success4');
ELSIF v_je2acct_othr.add_cancel = 'A' THEN
dbms_output.put_line('success5');
-- manipulating amount and shares to transfer when different exercise types
--"You cannot assign values to the recor variable declared for a loop. Either define seperate variables or use explicit record variable"
v_je2acct_othr.gl_amt :=
CASE
WHEN v_je2acct_othr.exer_type = 0 THEN
0
WHEN v_je2acct_othr.exer_type = 2 AND v_je2acct_othr.opts_exer != v_je2acct_othr.shrs_sold THEN
v_je2acct_othr.gl_amt
WHEN v_je2acct_othr.exer_type = 2 AND v_je2acct_othr.opts_exer = v_je2acct_othr.shrs_sold THEN
v_je2acct_othr.gl_amt
ELSE
v_je2acct_othr.gl_amt
END );
---- Commented on 11/01/2006 For Fixing 30585
/* v_je2acct_othr.shares :=( CASE
WHEN v_je2acct_othr.exer_type = 0 THEN v_je2acct_othr.opts_exer
WHEN v_je2acct_othr.exer_type = 2 AND v_je2acct_othr.opts_exer != v_je2acct_othr.shrs_sold
THEN v_je2acct_othr.opts_exer - v_je2acct_othr.shrs_sold
WHEN v_je2acct_othr.exer_type = 2 AND v_je2acct_othr.opts_exer = v_je2acct_othr.shrs_sold
THEN 0
ELSE v_je2acct_othr.shares
END );*/
---- Commented on 11/01/2006 For Fixing 30585
v_je2acct_othr.shares :=
CASE
WHEN v_je2acct_othr.exer_type = 0 THEN
v_je2acct_othr. Shares
--- Replaced opts_exer with the Shares amount from the previous journal for fixing 30585
WHEN v_je2acct_othr.exer_type = 2 AND v_je2acct_othr.opts_exer != v_je2acct_othr.shrs_sold AND v_je2acct_othr.shares!=0 AND v_je2acct_othr.plan_type 0 -- Added plantype condition for CQ:PCTUP00493542
THEN
v_je2acct_othr.Shares - v_je2acct_othr.shrs_sold
--- Replaced opts_exer with the Shares amount from the previous journal for fixing 30585
WHEN v_je2acct_othr.exer_type = 2 AND v_je2acct_othr.opts_exer = v_je2acct_othr.shrs_sold THEN
0
ELSE
v_je2acct_othr.shares
END );
dbms_output.put_line('success6');
IF LENGTH(TRIM(v_je2acct_othr.acct_num_othr))=8 OR TRIM(v_je2acct_othr.acct_num_othr) IS NULL THEN
v_mlac_mesg :=NULL;
ELSE
v_mlac_mesg :='Check the ml a/c length';
dbms_output.put_line('success7');
END IF;
INSERT
INTO TB_XOP_JEMQ
jemq_num,
prev_jemq,
ml_retail_account,
wcma_shares,
shares,
wcma_taxes,
tax_amt,
wcma_reimburse,
reimburse_amt,
name_first,
name_last,
exer_type,
ml_sec_num,
wcma_bulking,
bulking_amt,
ivr_plan_num,
exer_dt,
grant_dt,
user_id,
source,
mlu_rowid,
settle_dt,
exer_num,
plan_type,
grant_num,
vc_trailer_desc,
rsu_type
VALUES
Pk_Xop_Get_Jemqnum.fn_xop_get_jemqnum,
v_je2acct_othr.jemq_num,
v_je2acct_othr.acct_num_othr,
-- 2nd ml_retail_account,
v_je2acct_othr.ml_retail_account,
-- move shares from old acct to 2nd acct above
v_je2acct_othr.shares,
--this is SHARES
--wcma_taxes
0,
--tax_amt,
v_je2acct_othr.ml_retail_account,
-- move gl_amt from old acct to 2nd acct above
v_je2acct_othr.gl_amt * -1,
v_je2acct_othr.name_first,
v_je2acct_othr.name_last,
v_je2acct_othr. exer_type,
v_je2acct_othr.ml_sec_num,
--wcma_bulking,
0,
--bulking_amt,
v_je2acct_othr.ivr_plan_num,
v_je2acct_othr.exer_dt,
v_je2acct_othr. grant_dt,
v_je2acct_othr.user_id,
'T',
--source
v_je2acct_othr.mlu_rowid,
v_je2acct_othr. settle_dt,
v_je2acct_othr.exer_num,
v_je2acct_othr. plan_type,
v_je2acct_othr.grant_num,
v_je2acct_othr.vc_trailer_desc,
v_je2acct_othr. rsu_type
dbms_output.put_line('success8');
END IF;
EXCEPTION
WHEN OTHERS THEN
Pr_Xop_Log_Errors ( 'Code :' || NVL(v_mlac_mesg,SQLERRM) || ' at ' || USER || 'at sub exec block in pop_je2acct_othr' );
END;
dbms_output.put_line('success9'); -- end of begin within loop
END LOOP;
--COMMIT;
EXCEPTION
WHEN OTHERS THEN
Pr_Xop_Log_Errors ( 'Code :' || NVL(v_mlac_mesg,SQLERRM) || ' at ' || USER || 'at pk_xop_jemq.pop_je2acct_othr' );
dbms_output.put_line('success10');
END;
{code}   -
Cursor query works in anonymous block but not in procedure
Hello,
My cursor query works fine in anonymous blcok but fails in pl/sql block.
Anonymous block:
declare
cursor c1 is
select object_name
from all_objects
where owner='IRIS_DATA'
and object_type='SEQUENCE';
v_string varchar2(2000);
begin
for c2 in c1 loop
v_string := 'DROP SEQUENCE IRIS_DATA.'||c2.object_name;
execute immediate v_string;
end loop;
commit;
exception
when others then
dbms_output.put_line('Exception :'||sqlerrm);
end;
works fine.
but inside the procedure the it doesn't go inside the cursor loop
procedure get_sequence is
l_dp_handle NUMBER;
v_job_state varchar2(4000);
l_last_job_state VARCHAR2(30) := 'UNDEFINED';
l_job_state VARCHAR2(30) := 'UNDEFINED';
l_sts KU$_STATUS;
v_logs ku$_LogEntry;
v_row PLS_INTEGER;
v_string1 varchar2(2000);
cursor seq_obj is
select object_name
from all_objects
where owner='IRIS_DATA'
and object_type='SEQUENCE';
begin
log_status('get_sequence started.');
--Cursor records to drop the sequences before importing.
for seq_obj_rec in seq_obj loop
log_status('get_sequence: Dropping sequence started.');
v_string1 := 'DROP SEQUENCE IRIS_DATA.'||seq_obj_rec.object_name;
execute immediate v_string1;
end loop;
log_status('get_sequence: Dropping sequence completed.');
exception
WHEN OTHERS THEN
log_status('get_sequence: exception.');
end get_sequence;
it's not going into the seq_obj_rec cursor.
I granted select on all_objects to the user.this user is also having the DBA role as well.
Please advice.PROCEDURE Get_sequence
IS
l_dp_handle NUMBER;
v_job_state VARCHAR2(4000);
l_last_job_state VARCHAR2(30) := 'UNDEFINED';
l_job_state VARCHAR2(30) := 'UNDEFINED';
l_sts KU$_STATUS;
v_logs KU$_LOGENTRY;
v_row PLS_INTEGER;
v_string1 VARCHAR2(2000);
CURSOR seq_obj IS
SELECT object_name
FROM all_objects
WHERE owner = 'IRIS_DATA'
AND object_type = 'SEQUENCE';
BEGIN
Log_status('get_sequence started.');
--Cursor records to drop the sequences before importing.
FOR seq_obj_rec IN seq_obj LOOP
Log_status('get_sequence: Dropping sequence started.');
v_string1 := 'DROP SEQUENCE IRIS_DATA.'
||seq_obj_rec.object_name;
EXECUTE IMMEDIATE v_string1;
END LOOP;
Log_status('get_sequence: Dropping sequence completed.');
EXCEPTION
WHEN OTHERS THEN
Log_status('get_sequence: exception.');
END get_sequence; How do I ask a question on the forums?
SQL and PL/SQL FAQ
scroll down to #9 & use tags in the future. -
Getting value with an anonymous block using ODP
Hi all!
I have a problem I hope someone can help me with. I believe it to be a minor one. I am trying to imbed an anonymous block into my .net app and use it dynamically to get a value from the database depending on the values in a tables. Since my procedure is quite large I am displaying a small example proc for simplicity purposes. Basically I want to execute an anonymous block from my app that will return a value (not a row or rows) from the database. The code is below:
Private Sub test()
Dim cn As New OracleConnection(profileString)
Try
Dim sb As New System.Text.StringBuilder
sb.Append("Declare ")
sb.Append("v_maxnum varchar2(6); ")
sb.Append("Begin ")
sb.Append("Select max(to_number(email_address_id)) into ")
sb.Append("v_maxnum from CVWH14_CDRV_TEST.EMAIL_ADDRESS_TBL; ")
sb.Append("dbms_output.put_line(v_maxnum); ")
sb.Append("Exception ")
sb.Append("When Others ")
sb.Append("Then ")
sb.Append("dbms_output.put_line('Program run errors have occurred.'); ")
sb.Append("End; ")
Dim cmd As New OracleCommand(sb.ToString, cn)
With cmd
cmd.CommandType = CommandType.Text
Dim parm As New OracleParameter
parm.ParameterName = "v_maxnum"
parm.OracleType = OracleType.VarChar
parm.Direction = ParameterDirection.Output
parm.Size = 6
cmd.Connection.Open()
Dim ret As Object = cmd.ExecuteScalar()
Dim res As String = cmd.Parameters.Item(0).Value.ToString -- **Error is occuring here**
cmd.Connection.Close()
cmd.Dispose()
End With
Catch ex As Exception
MessageBox.Show(ex.Message, "Error")
'End If
If cn.State = ConnectionState.Open Then
cn.Close()
End If
End Try
End Sub
The exception error reads "Invalid Index 0 for this OracleParameterCollection with Count=0."
If I can figure out how to get a parameter value from the database via the anonymous block, I can apply the logic to the real application. Any help or direction I could receive would be greatly appreciated. Thanks for reading this post!Thank you for responding. The code that I posted was just one of many ways I have tried. I retried the proc making just 2 changes:
Private Sub test()
Dim cn As New OracleConnection(profileString)
Try
Dim sb As New System.Text.StringBuilder
sb.Append("Declare ")
sb.Append("v_maxnum varchar2(6); ")
sb.Append("Begin ")
sb.Append("Select max(to_number(email_address_id)) into ")
sb.Append("v_maxnum from CVWH14_CDRV_TEST.EMAIL_ADDRESS_TBL; ")
sb.Append("dbms_output.put_line(:v_maxnum); ") -- !Changed this to a bind variable!
sb.Append("Exception ")
sb.Append("When Others ")
sb.Append("Then ")
sb.Append("dbms_output.put_line('Program run errors have occurred.'); ")
sb.Append("End; ")
Dim cmd As New OracleCommand(sb.ToString, cn)
With cmd
cmd.CommandType = CommandType.Text
Dim parm As New OracleParameter
parm.ParameterName = ":v_maxnum" -- !Changed this to a bind variable!
parm.OracleType = OracleType.VarChar
parm.Direction = ParameterDirection.Output
parm.Size = 6
cmd.Connection.Open()
Dim ret As Object = cmd.ExecuteScalar() -- !The error is now occuring here!
Dim res As String = cmd.Parameters.Item(0).Value.ToString
cmd.Connection.Close()
cmd.Dispose()
End With
Catch ex As Exception
MessageBox.Show(ex.Message, "Error")
If cn.State = ConnectionState.Open Then
cn.Close()
End If
End Try
End Sub
I am now getting the error message "Not all variables bound". Any more help or direction that you could throw my way would be greatly appreciated. -
Performance problem due to anonymous blocks
Hi,
One of the users on our database has created a procedure consisting of many blocks like the one given below:
begin
select func1(var1,var2,var3)into vcompvalue from dual;
if vcompvalue < 0 then
vcompvalue := 0;
end if;
exception when no_data_found then
vcompvalue := 0;
end;
The procedure takes a long time to execute.Instead of writing a block, will writing SQL%NOTFOUND instead of the exception and merging the blocks with rest of the code improve performance?
Thanks for the help!
Vinayak ThatteI would guess it might; you'd be cutting down the number of PL/SQL clauses that have to be parsed, etc, so if you have enough anonymous blocks you may see a difference.
On a more specific note can I just ask why you're checking for NO_DATA_FOUND? If DUAL ever throws this exception you've got serious problems with your database. If it's being thrown by your FUNC1 you might be better off (from a performance point of view) handling that exception within the function.
rgds, APC -
Printing the Package output from Anonymous block
Hi,
I need to call the below package from anonymous block and get the output.
Could you let me know.
I tried using this, but i don't get data.
===========Anonymous Block=====================================================================
declare
var xxdc.xxdc_sr_log_his_pkg.sr_tbl_type;
l_sr_idx_bi BINARY_INTEGER := 0;
BEGIN
xxdc.xxdc_sr_log_his_pkg.service_record('14040',var);
dbms_output.put_line('CLAIM_CREDIT_OFFERS :'||var(l_sr_idx_bi).qa_credit_offers(l_sr_idx_bi).character1 );
end;
=============================================================================================
============================================================================================
Package Spec
TYPE cr_offer_type IS TABLE OF apps.qa_results_v%ROWTYPE
INDEX BY BINARY_INTEGER;
TYPE sr_rec_type IS RECORD
(task_status apps.jtf_task_statuses_tl.name%TYPE
,task_type apps.jtf_task_types_tl.name%TYPE
,qa_credit_offers cr_offer_type
TYPE sr_tbl_type IS TABLE OF sr_rec_type
INDEX BY BINARY_INTEGER;
PROCEDURE service_record(p_service_req_num IN VARCHAR2
,p_service_req_tbl OUT sr_tbl_type
Package Body
FOR emp_row_rec IN cur_credit_off
LOOP
l_sr_tbl(l_sr_idx_bi).qa_credit_offers(l_sr_idx_bi).character1 := emp_row_rec.character1;
--dbms_output.put_line( l_sr_tbl(l_sr_idx_bi).qa_credit_offers(l_sr_idx_bi).character1); --commenting for testing
l_sr_idx_bi := l_sr_idx_bi + 1;
END LOOP;
p_service_req_tbl := l_sr_tbl;
=============================================================================================
ThankHi,
Did you issue the SQL*Plus command
SET SERVEROUTPUT ON
or, if you're using some other front end, its equivalent?
Can you ever see output from dbms_output? For example, what happens when you run this?
SET SERVEROUTPUT ON
BEGIN
dbms_output.put_line ('Hello, world!');
END;
Since I don't have your tables, I can't actually run your code. If you'd post CREATE TABLE and INSERT statements, or re-write the package to reference commonly available tables, such as those in the scott schema, then I could test it. -
Error in Stoerd Procedure But working in Anonymous Block.
declare
Cursor Cur Is
Select 'Alter '||Object_Type||' '||Object_Name||' Compile' Invalid_Obj, Object_Type, Object_Name
From Dba_Objects A
Where A.Owner='Dataload' And A.Status='Invalid' ;
Begin
For I In Cur
Loop
Begin
Execute Immediate I.Invalid_Obj;
Exception
When Others Then
Null;--Dbms_Output.Put_Line(Sqlerrm||' : '||I.Object_Type||' '||I.Object_Name);
End;
End Loop;
Exception
When Others Then
Null;--Dbms_Output.Put_Line(Sqlerrm);
End;
Above anonymous block Run successfully.
but when I create it as stored procedure then, it give error like
Dba_Objects does not exist.
Please, suggest what I do for stored procedure?
Edited by: Nilesh Hole on Jun 2, 2010 12:00 AMIf you don't have any sys rights you either should
a) ask the DBA to run utlrp (preferred, as that always executes compilation in the right order)
b) do not use dba_objects but user_objects, assuming you are connected as DATALOAD
In a normal situation this shouldn't be necessary, so you should still question why you even want to do this (and are reinventing the wheel). Also the dbms_utility package has a COMPILE_SCHEMA procedure.
Sybrand Bakker
Senior Oracle DBA -
Handling loop exception in an anonymous block
hI ,
I have a an anonymous block
declare
cursor
local variables
begin
open cursor
some statements
loop
some statement ;
some othet statement;
select something from sometablein local variable where some field = cursor.value ;
some more statements
end loop
some more statements
exception
when whatever
then whatever
end;
Now my select statement may give a NO_DATA_FOUND error which i want to catch and ignore .
Pls tell me how to do it.So that mean you can have multiple exception blocks
in a pl/sql script ?You can have one exception handler per execution block.
Execution blocks can be nested inside other execution blocks.
Handling the error within one exception handler causes execution to return out to the execution of the parent block.
Raising an error within one exception handler causes the execution to go straight to the exception handler of the parent block.
e.g.
-- execution block 1
BEGIN
-- execution block 2
DECLARE
myvar number;
BEGIN
SELECT mynumber INTO myvar FROM mytable;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL; -- handle error and return execution to block 1
WHEN OTHERS THEN
RAISE; -- raise any other errors to block 1 exception handler
END; -- block 2
DBMS_OUTPUT.PUT_LINE('Select took place successfully or no data was found');
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('An error occurred either in block1 or in block 2 (except for NO_DATA_FOUND in block2)');
END; -
How to use anonymous block in select statement
Hello Experts.
I have one requirement which i can resolve using anonymous block in plsql. But i want implement it in select query only.
Database: Oracle 11.2.0
select count(*) from emp where name='xyz' and sal=50
if count(*)>0
then
select dept,sector from emp where name='xyz' and sal=50
here i dont have any primary key.
How can i achieve above using sql query not plsql. Here is one sloution which i have got but its not satisfying above requiremnt as i dont have any primary key columns
select toll_number from toll_details
where toll_id =(select toll_id from toll_details where toll_new_id='5263655214' group by toll_id having count(*)>0)
here toll_id is primary key, so used group by. But how to do this in my above requirement as i dont have primary key.
Appreciate any help on this.
Thank you897112 wrote:
Hello Experts.
I have one requirement which i can resolve using anonymous block in plsql. But i want implement it in select query only.
Database: Oracle 11.2.0
select count(*) from emp where name='xyz' and sal=50
if count(*)>0
then
select dept,sector from emp where name='xyz' and sal=50
here i dont have any primary key.
How can i achieve above using sql query not plsql. Here is one sloution which i have got but its not satisfying above requiremnt as i dont have any primary key columns
select toll_number from toll_details
where toll_id =(select toll_id from toll_details where toll_new_id='5263655214' group by toll_id having count(*)>0)
here toll_id is primary key, so used group by. But how to do this in my above requirement as i dont have primary key.
Appreciate any help on this.
Thank youTry this
SQL> create table plch_test(id number,name varchar2(20),sal number);
Table created.
SQL> insert into plch_test values(1,'XYZ',50);
1 row created.
SQL> insert into plch_test values(2,'AAA',100);
1 row created.
SQL> insert into plch_test values(3,'BBB',200);
1 row created.
SQL> insert into plch_test values(4,'CCC',400);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from plch_test;
ID NAME SAL
1 XYZ 50
2 AAA 100
3 BBB 200
4 CCC 400
SQL> ed
Wrote file afiedt.buf
1 select id,name
2 from plch_test a
3 where 1=(select count(*) from plch_test b where a.id=b.id)
4* and id=&id
SQL> /
Enter value for id: 2
old 4: and id=&id
new 4: and id=2
ID NAME
2 AAA
SQL> /
Enter value for id: 0
old 4: and id=&id
new 4: and id=0
no rows selectedHope this helps!!!
Regards,
Achyut -
Oracle SQL Developer 3.0: PL/SQL debugging of anonymous blocks: ISSUES
Hello,
I just downloaded the Oracle SQL Developer 3.0. I have been using the EA releases as they came into existence and was happy to see the released version. So I immediately tried to debug an anonymous block (something I did not try to do in the EA releases), and nothing happened.
The "Debug" was grayed out and the key-chord "ctrl-shift-F10" did nothing. I found this forum:
Re: 30EA1: anonymous block debugging?
and followed Vadim Tropashko's advice. This did nothing for my anon. block but worked fine for the simple example.
So I started to whittle my anon. block down to find the culprit, here is a repeatable breaking point for me:
declare
stmt1 long;
stmt2 long;
stmt3 long;
stmt4 long;
p_data varchar2( 500 );
i varchar2( 10 );
BEGIN
STMT1 := 1;
STMT2 := 1;
STMT3 := 1;
STMT4 := 1;
--the moment this is in the block "Debug" is no longer an option
select
SendDocumentResult
into
p_data
from
XMLTABLE( '/data'
PASSING
xmltype.createxml( '<?xml version="1.0" encoding="utf-8"?><data><SendDocumentResult>test</SendDocumentResult></data>' )
COLUMNS SendDocumentResult varchar2( 1000 ) PATH 'SendDocumentResult' ) ;
end;The moment I have the SELECT INTO ... XMLTABLE() it fails (a normal SELECT INTO works just fine).
Is this a problem with my environment or is a problem with SQL Developer 3.0.04. Looking over K's comments, it seems the debug worked for 'simple' blocks, so I wonder if this is just out-of-scope...
My environment:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for IBM/AIX RISC System/6000: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
and Oracle SQL Developer
3.0.04 (Buld Main 04.34 with bundled Java) on a Window's XP box.Thanks, I'll survive. Just my luck, the first item I try to anon. debug didn't work! :)
thanks, hopefully this problem will be few and far between -
Can select resource content in anonymous block, but not in stored procedure
I know the problem relates to the ACLs but am curious about the following behaviour:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
running on Windows XP sp2
Trying to access an existing resource '/home/test/test.dtd'
/home is owned by SYS
/home/test is owned by me
/home/test.test.dtd is owned by me
The following SQL and anonymous block retrieve the content of the resource:
select extract(p.res,'/*').getClobVal()
from resource_view p
where p.any_path = '/home/test/test.dtd'
declare
alldata clob;
begin
select extract(p.res,'/*').getClobVal()
into alldata
from resource_view p
where p.any_path = '/home/test/test.dtd'
dbms_output.put_line(substr(alldata, 1, 255));
end;
BUT when I encapsulate the anonymous block in a stored procedure, I am told that the folder '/home/test/' does not exist.
As said, the problem related to the ACL on the folders, what I cannot understand, and caused me considerable confusion, is why I was unable to get the content from a stored procedure when I was able to do so from an anonymous block.
regards
RichardUse equals_path(res,'/home/test/test.dtd') = 1OK, OK, but how do you use wildcards (if you want to) since any_path like '/home/test%' works?
Who was the stored procedure owned by. Was it a stand-alone stored procedure or a
method on a package. If it was a method on a package is it AUTHID creator or AUTHID
definer.Everything apart from the '/home' folder is owned by the current user.
The PL/SQL was in a packaged procedure, a stand-alone stored procedure, and an anonymous block. It exhibited the same behaviour in each. All were defined with default AUTHID which is definers rights which is the same as the current user in this case. -
Calling PL/SQL anonymous block from href in tabular report
apex 2.2.
I've got a tabular report where I've added some img columns with a href to call diff processes
for example
"<a href="f?p=&APP_ID.:22:&APP_SESSION.:BRANCH_TO_PAGE_ACCEPT|NEW_PROXY:NO:::22,ABCDEF ><img src="/i/asyl.gif" border="0" alt="Runprocess"></a>"
When clicking on an image column in row x then I would like to run the process - no page submit.
The pl/sql anonymous block process source calls package.storedproc(p1,p2) - two in parameters
I'm struggling with the syntax and is wondering if there's a smarter way to achieve the same function
Any ideas most welcome
Thanks
Peter<a href="f?p=&APP_ID.:22:&APP_SESSION.:BRANCH_TO_PAGE_ACCEPT|NEW_PROXY:NO:::22,ABCDEFG" ><img src="/i/asylogin.gif" border="0" alt="Process"></a>Question is how can you pass values from a row in a tabular report to the application process ?
Maybe you are looking for
-
Return Purchase Order (MVT #161) Sales Area Determination on Purchase Order
Hi, I am working on return purchase order (Purchase order with return check box ON at item level) and creating outbound delivery with VL10B and doing PGI to vendor. Can someone help to figure out how sales area (sales org/distribution channel/Divisio
-
Getin error when implementing BADI
Hi All, I am geting an error while I am trying to implement the BADI FISPLIT. The error is "BADI definaition is FISPLIT is only provided for SAP internal use". how can I implement this BADI. Can anyone help me please. Thanks. lucky
-
How to make reports based on Data block work on web?
I am using form 6i and oracle 9ias I have successfully call the common reports from the form on the web using run_report_object, then web.show_documnet(..); But when it come to the reports based on the data block from the form, it doesn't work. it al
-
New Window Opens Under The Toolbar
When I open a new window, the left side always falls under the toolbar, hiding the red button that closes the window. I think this is something new. I don't remember having to move each window after it opens in the past. Anybody else? Any solutions?
-
Hi, I installed Jdev recently and am having quite a few issues with it. 1. I could not make the HelloWorld message spit out a message. That is being following up on another thread. I still can't do so. 2. So I went ahead and created the Empsearch tut