Using DML in PLsql
Hi,
Can DML queries like insert into be executed in PLSQL?
I have below code, it is a part of a procedure
BEGIN
-- Start entering LOG messages from here
xxmck.mck_write_log_msg.get_log_params('GLTD',gv_prog_src);
IF gv_prog_src = 'NOTASKSUB' THEN
-- check for another program
-- mck_write_log_msg.get_log_params('WIPRPT',gv_prog_src);
NULL;
ELSE
gv_prog_parent:='GLTD';
END IF;
xxmck.mck_write_log_msg.log(gv_prog_parent,'Entering in LOAD_GLTD_TABLES.populate_gltd_tabs11','prg',gv_prog_src);
xxmck.mck_write_log_msg.log_tail(gv_prog_parent,'Entering in LOAD_GLTD_TABLES.populate_gltd_tabs11','prg',gv_prog_src);
BEGIN
DBMS_OUTPUT.PUT_LINE('DROPPING INDEX ON MCK_GLTD_11...');
EXECUTE IMMEDIATE 'DROP INDEX mck_gltd_11_m1';
DBMS_OUTPUT.PUT_LINE('DELETING DATA FROM MCK_GLTD_11...');
DELETE FROM MCK_GLTD_11;
DBMS_OUTPUT.PUT_LINE('Inserting data into table MCK_GLTD_11...');
INSERT INTO mck_gltd_11
SELECT * FROM xxmck.mck_gltd_11_vw
WHERE period_name LIKE '%-'||to_char((sysdate-30),'RR');
DBMS_OUTPUT.PUT_LINE('Updating status and start date of control table...');
UPDATE mck_gltd_mozart_built
SET end_date = sysdate,
status = 'C'
WHERE table_name = 'MCK_GLTD_11';
COMMIT;
DBMS_OUTPUT.PUT_LINE('CREATING INDEX ON MCK_GLTD_11...');
EXECUTE IMMEDIATE 'CREATE INDEX mck_gltd_11_m1 ON mck_gltd_11(code_combination_id,period_name)';
--UNRECOVERABLE;
DBMS_OUTPUT.PUT_LINE('Analyzing tables MCK_GLTD_11...');
--ANALYZE TABLE mck_gltd_11 COMPUTE STATISTICS FOR TABLE FOR INDEXES FOR ALL INDEXED COLUMNS;
END;
xxmck.mck_write_log_msg.log(gv_prog_parent,'Exiting from LOAD_GLTD_TABLES.populate_gltd_tabs11','prg',gv_prog_src);
xxmck.mck_write_log_msg.log_tail(gv_prog_parent,'Exiting from LOAD_GLTD_TABLES.populate_gltd_tabs11','prg',gv_prog_src);
xxmck.mck_write_log_msg.set_decision_param(v_status,gv_prog_src);
-- update MCK_LOG_CONT_EXIT_CHK set cont_exit= v_status, source ='TASK1';
commit;
The code after the inner BEGIN-END block is not getting executed.
I tried using EXECUTE IMMEDIATE for insert and update but there were syntax errors related to '.
Kindly help.
Thanks,
Aditya
Yes, code has exception block...
Here is entire code...
PROCEDURE populate_gltd_tabs11
IS
BEGIN
-- Start entering LOG messages from here
xxmck.mck_write_log_msg.get_log_params('GLTD',gv_prog_src);
IF gv_prog_src = 'NOTASKSUB' THEN
-- check for another program
-- mck_write_log_msg.get_log_params('WIPRPT',gv_prog_src);
NULL;
ELSE
gv_prog_parent:='GLTD';
END IF;
xxmck.mck_write_log_msg.log(gv_prog_parent,'Entering in LOAD_GLTD_TABLES.populate_gltd_tabs11','prg',gv_prog_src);
xxmck.mck_write_log_msg.log_tail(gv_prog_parent,'Entering in LOAD_GLTD_TABLES.populate_gltd_tabs11','prg',gv_prog_src);
BEGIN
DBMS_OUTPUT.PUT_LINE('DROPPING INDEX ON MCK_GLTD_11...');
EXECUTE IMMEDIATE 'DROP INDEX mck_gltd_11_m1';
DBMS_OUTPUT.PUT_LINE('DELETING DATA FROM MCK_GLTD_11...');
DELETE FROM MCK_GLTD_11;
DBMS_OUTPUT.PUT_LINE('Inserting data into table MCK_GLTD_11...');
INSERT INTO xxcognos.mck_gltd_11
SELECT * FROM xxmck.mck_gltd_11_vw
WHERE period_name LIKE '%-'||to_char((sysdate-30),'RR');
DBMS_OUTPUT.PUT_LINE('Updating status and start date of control table...');
UPDATE mck_gltd_mozart_built
SET end_date = sysdate,
status = 'C'
WHERE table_name = 'MCK_GLTD_11';
COMMIT;
DBMS_OUTPUT.PUT_LINE('CREATING INDEX ON MCK_GLTD_11...');
EXECUTE IMMEDIATE 'CREATE INDEX mck_gltd_11_m1 ON mck_gltd_11(code_combination_id,period_name)';
--UNRECOVERABLE;
DBMS_OUTPUT.PUT_LINE('Analyzing tables MCK_GLTD_11...');
--ANALYZE TABLE mck_gltd_11 COMPUTE STATISTICS FOR TABLE FOR INDEXES FOR ALL INDEXED COLUMNS;
END;
xxmck.mck_write_log_msg.log(gv_prog_parent,'Exiting from LOAD_GLTD_TABLES.populate_gltd_tabs11','prg',gv_prog_src);
xxmck.mck_write_log_msg.log_tail(gv_prog_parent,'Exiting from LOAD_GLTD_TABLES.populate_gltd_tabs11','prg',gv_prog_src);
xxmck.mck_write_log_msg.set_decision_param(v_status,gv_prog_src);
-- update MCK_LOG_CONT_EXIT_CHK set cont_exit= v_status, source ='TASK1';
commit;
EXCEPTION
WHEN others THEN
RAISE;
-- Log Entry
v_status := 'err';
xxmck.mck_write_log_msg.set_decision_param(v_status,gv_prog_src);
--update MCK_LOG_CONT_EXIT_CHK set cont_exit='err',source ='TASK3';
xxmck.mck_write_log_msg.err_log(p_parent_prog =>gv_prog_parent
,p_log_desc => SQLERRM
,p_prog_src => gv_prog_src
,p_msg_type => 'prg'
xxmck.mck_write_log_msg.log_tail(p_parent_prog =>gv_prog_parent
,p_log_desc => SQLERRM
,p_prog_src => gv_prog_src
,p_msg_type => 'err'
--commit;
END populate_gltd_tabs11;
Thanks,
Aditya
Similar Messages
-
If we use DML statement in function then that function can be used inside s
if we use DML statement in function then that function can be used inside select query or any DML query?
select f from t2;I think you meant to query t1.
It works if the function is an autonomous transaction:
create or replace function f return number
is
PRAGMA AUTONOMOUS_TRANSACTION;
begin
update t1 set c=2;
commit;
return 1;
end;
select f from t1But as Billy said why would you want to do DML this way. And this is not the way autonomous procedures should be used either.
An an answer to an interview question though nothing wrong with it. -
Is there possibility to add dimension value into hierarchy using dml or spl
1 Is there possibility to add dimension value into hierarchy using dml or spl?
If such possibility exists how to do that.
2 Is it possible to sort dimension values inside one branch of the hierarchy?What version of OLAP are you using and how did you create your AW (e.g., AWM)?
Assuming that you're used either AWM or the Java API for AWs in 10g, there isn't an OLAP DML for adding a dimension member to a dimension (and have all the meta data kept in sync); you must load dimension members using AWM the Java API for AWs.
So, make your changes in the the dimension table and process that table.
For sorting, you can add a sort attribute to the dimension. Add the sort attribute to the model, indicate that it's used for sorting, add the sort attribute to your dimension table and maintain the dimension. -
Is there a way to list the attributes that are applied to a particular level using DML?
This program will produce a formatted listing of all dimensions, hierarchies, attributes, and levels, and show whether or not the attribute is defined within a given level.
Define a program named SHOW_ATTRIB_LEVELS with this program code:
"Program: Show_Attrib_Levels
"Purpose: Display level/attribute associations
"Author: Mark Thompson - Vlamis Software Solutions - July, 2008
vrb _dim text
vrb _hier text
vrb _lvl text
vrb _attr text
vrb _dimcolwid int
vrb _hiercolwid int
vrb _lvlcolwid int
vrb _attrcolwid int
trap on haderror
pushlevel 'SHOW_ATTRIB_LEVELS'
push all_dimensions all_attributes all_levels all_hierarchies
limit all_dimensions to all
limit all_hierarchies to all
_dimcolwid = largest(numchars(all_dimensions))-10
_hiercolwid = largest(numchars(all_hierarchies))-10-_dimcolwid
_lvlcolwid = largest(numchars(all_levels))-6-_dimcolwid
_attrcolwid = largest(numchars(all_attributes))-10-_dimcolwid
row under '-' < w _dimcolwid 'DIMENSION' -
w _hiercolwid 'HIERARCHY' -
w _attrcolwid 'ATTRIBUTE' -
w _lvlcolwid 'LEVELS' -
w 7 'InHier?'>
sort all_dimensions a convert(all_dimensions,text)
for all_dimensions
do
_dim = extchars(all_dimensions 1 findchars(all_dimensions,'.DIMENSION')-1)
limit all_attributes to dim_attributes
limit all_levels to dim_levels
limit all_levels remove findchars(all_levels,'AW$NONE') ne 0
limit all_hierarchies to dim_hierarchies
limit all_hierarchies remove findchars(all_hierarchies,'AW$NONE') ne 0
for all_hierarchies
do
_hier = extchars(all_hierarchies findchars(all_hierarchies '.')+1)
_hier = extchars(_hier 1 numchars(_hier)-10)
for all_attributes
do
_attr = extchars(all_attributes findchars(all_attributes '.')+1)
_attr = extchars(_attr 1 numchars(_attr)-10)
for all_levels
do
_lvl = extchars(all_levels findchars(all_levels '.')+1)
_lvl = extchars(_lvl 1 numchars(_lvl)-6)
row w _dimcolwid _dim -
w _hiercolwid _hier -
w _attrcolwid _attr -
w _lvlcolwid _lvl -
w 7 r across all_levels: nafill(convert(attr_visible,text) '-')
doend
blank
doend
doend
doend
haderror:
poplevel 'SHOW_ATTRIB_LEVELS' -
How to update a column value by comparing old value by using DML Handler...
Hi Can anyone post the DML Handler code for updating a column value by comparing the old value.
Thanks,
RayHi,
Here is an example of a DML handler.
BEGIN
DBMS_APPLY_ADM.SET_DML_HANDLER(
object_name => 'scott.emp',
object_type => 'TABLE',
operation_name => 'UPDATE',
error_handler => false,
user_procedure => 'strmadmin.update_column',
apply_database_link => NULL,
apply_name => 'MY_APPLY');
END;
This DML handler which will send any LCR matching the specified conditions to the strmadmin.update_column for customised processing.
You can write the strmadmin.update_column procedure so that it extracts the old values from the LCR. You can then use the old values from the LCR to identify the row in the table. Once you identify the row, you can update it as you want.
I haven't really tried to do any customised processing using DML handlers, but this should work.
Hope this is of help.
Sujoy -
Hello All:
My question is, Which is more efficient to use in Plsql:
IF v_DestFile IS NULL THEN
v_DestFile := in_DestFile ;
END IF;
OR
v_DestFile := NVL(v_DestFile , in_DestFile);
Using the second one requires a call to a function..
What are your thoughts.
Thanks
LeonardThe following test run on Windows XP with an Athlon 3400 shows that NVL function take more time to execute. However to see the difference you have to run this code many many times (if you run this this code 1 million of times within a SQL query or within PL/SQL, you will likely get other performance problems ...):
SQL> set timing on
SQL>
SQL> select * from v$version;
BANNER
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
Elapsed: 00:00:00.00
SQL>
SQL> declare
2 vdf varchar2(10) := null;
3 vidf varchar2(10) := 'ok';
4 begin
5 for i in 1..100000000
6 loop
7 if vdf is null then
8 vdf := vidf;
9 end if;
10 end loop;
11 end;
12 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:05.57
SQL> show errors
No errors.
SQL>
SQL>
SQL> declare
2 vdf varchar2(10) := null;
3 vidf varchar2(10) := 'ok';
4 begin
5 for i in 1..100000000
6 loop
7 vdf := nvl(vdf, vidf);
8 end loop;
9 end;
10 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:21.71
SQL> show errors
No errors.
SQL>
SQL>
SQL> declare
2 vdf varchar2(10) := 'ok';
3 vidf varchar2(10) := 'ok';
4 begin
5 for i in 1..100000000
6 loop
7 if vdf is null then
8 vdf := vidf;
9 end if;
10 end loop;
11 end;
12 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:05.61
SQL> show errors
No errors.
SQL>
SQL>
SQL> declare
2 vdf varchar2(10) := 'ok';
3 vidf varchar2(10) := 'ok';
4 begin
5 for i in 1..100000000
6 loop
7 vdf := nvl(vdf, vidf);
8 end loop;
9 end;
10 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:21.76
SQL> show errors
No errors.
SQL> exit
[pre]
Message was edited by:
Pierre Forstmann
Message was edited by:
Pierre Forstmann -
We have a cube which store order data. It has 8 dimensions which are customer, item, geography, sales rep, sales channel, organization, time and Order number. Ideally the order number dimension uniquely identify all the measures but since we have many analytics reports where the combinations of the attributes are used in x and y axis, we have defined them as dimensions.
Now we need to select a portion of the data (limiting using the dimensions) and fine the regression coefficient and standard error between the volume and price using the REGRESS command.
when we run the regress command for the variables for volume and price we get error that out of temp space. But when we run that on a cube with 1-2 dimensions we get some output.
Is it possible to transform the cube information to another variable with only order dimension and run the regress command in a DML program? If somebody has done something similar can you share the code/logic? Otherwise can someone point to the DML commands which could be of use for this scenario?
regardsPlease let us know if this post has been resolved or if you still need resolution.
Thank you. -
How to parse XML and store the data in tables using sql or plsql?
I want to parse the xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xmlListWrapper>
<size>2</size>
<AppTypeID>10</AppTypeID>
</xmlListWrapper>
and store in a table
|pk|apptypeid|
1 10You can extract data from your XML along these lines...
SQL> ed
Wrote file afiedt.buf
1 with t as (select xmltype('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2 <xmlListWrapper>
3 <size>2</size>
4 <AppTypeID>10</AppTypeID>
5 <AppTypeID>20</AppTypeID>
6 </xmlListWrapper>') as xml from dual)
7 --
8 -- end of example data
9 --
10 select x.*
11 from t
12 ,xmltable('/xmlListWrapper/AppTypeID'
13 passing t.xml
14 columns pk for ordinality
15 ,apptypeid number path '.'
16* ) x
SQL> /
PK APPTYPEID
1 10
2 20
SQL>
Inserting it to a table is obviously achieved using an INSERT ... SELECT ... where the SELECT is extracting the data from the XML. -
Hi,
I have one procedure which calls a function. My requirement is if that function didnt return value in 1 minute then stop the exection of that function and call next statement.
Begin
(1).........
(2).......
(3) get_func_val:= function(1,2);
(4)......
(5)....
end;
My requirement is, if (3) doesnt return value in 1 minute, stop the execution of (3) and start executing (4).
Regards,
ParagParagNarkhede wrote:
My requirement is, if (3) doesnt return value in 1 minute, stop the execution of (3) and start executing (4).
PL/SQL does not support this as a language feature. It does not support a threading or fibre process model.
Parallel processing can be done via DBMS_PARALLEL_EXECUTE - but this is still not like the threading models on C/C++, C#, Java, etc.
One a parallel process is started, the main process cannot interrupt it (there are no suspend or terminate thread type interfaces to call). So the main PL/SQL process can itself timeout waiting for the parallel process (e.g. DBMS_JOB or DBMS_SCHEDULER background process). But it cannot timeout and halt the background process.
As the PL/SQL model is process based and not thread based, the parallel process does not share the main process's memory and data (or inherit a copy of it like a fork() child process would).
As for IPC interfaces. Standard concurrent access to a SQL table, serving as shared memory, can be used. Messages can also be send via the DBMS_PIPE and Advance Message Queue interfaces.
There are numerous reasons for the way PL/SQL approaches the concept of threading/parallel processing. Prime amongst these is that this is a multi-user and multi-process server environment - able to service a multiple threaded clients. Pushing the client thread concept into this environment does not make much sense.
As for your problem. Why does step 4 need to wait for step 3, if step 4 can be executed anyway when step 3 is timed out (i.e. step 3 fails)?
If step 4 can continue without step 3 completing, then step 4 does not have a dependency on step 3. In which case the following process model can easily be used in PL/SQL:
main process()
exec step 1
exec step 2
start step 3 as a background process
exec step 4
wait for step 3 to complete if not already completed
end
Perhaps if you explain what step 3 is, what it is tasked doing, and why it can be timed out, forum members can provide concrete solutions and suggestions. -
Hello everbody,
I am trying to use the SendMailJPKG.
Everything runs fine when I call the Procedure like this:
v_ErrorStatus := SendMailJPkg.SendMail(
SMTPServerName => v_SMTPServerName,
Sender => v_Sender,
Recipient => p_Recipient,
CcRecipient => v_CcRecipient,
BccRecipient => v_BccRecipient,
Subject => v_Subject,
Body => v_Body,
ErrorMessage => v_ErrorMessage,
Attachments => SendMailJPkg.ATTACHMENTS_LIST('/transfer/75309.pdf','/transfer/73971.pdf','/transfer/73977.pdf')
But when I replace the last line with:
Attachments => SendMailJPkg.ATTACHMENTS_LIST(v_list)
I get a numeric or value error.
I've tested all types for variable v_list including Vachar2, table of varchar2(4000) or SendMailJPkg.ATTACHMENTS_LIST itself
but got no success.
I have also tested a Varchar2 which contains -exactly- the same string as in my first approach (including all quotes).
Can anybody help me?
Thanks in advance,
RolandHEllo i need help in this problem too, if anybody has another package's version i 'll aprecciate if you send me the code
thanks -
Multiple attachment using SendMailJPKG from PLSQL
Hi,
I am able to send single attachment using SendMailJPKG.sendmail routine by providing the parameter as
sendmailjpkg.attachments_list('/test/mail.pdf')
Is it possible to send multiple attachments if so what is the syntax for the same.
Kindly help.
RegardsHEllo i need help in this problem too, if anybody has another package's version i 'll aprecciate if you send me the code
thanks -
Is it possible to use XDK java + plsql 9i for an 8i DB ?
Hello,
I would like to know whether there are some problems to use
the XDK for java + pl/sql 9.2.0.1 with an oracle DB 8.1.7.3 ?
If there are some problems, please let me know what kind of problems I will meet.
Regards
FAThere is no problem. I use it on 8.1.6
-
Transaction control without using dml automatic processing
hello everyone
question:
How can you make a statement like
update mytable set <whatever> where id = <primary key>
a transaction (committing it to database and rolling back if any part of the statement fails)
The tabular form is able to detect lost updates.
How would i be able to implement the same functionality in code (e.g. for updating a primary key without using a view)Hi,
the first step of the job should contain program SAPF120 and second step should be program RSBDCSUB.
Thanks for sharing your solution if you have another solution. -
How to use DML in triggers?
Hi Everyone,
I have converted a report from Oracle Reports to BI Publisher. It has shifted the trigger code in DB and made the Trigger entries in DATA Template. When Return FALSE from Trigger it gives error other wise report runs cleanly. Which show trigger is executed.
But when I put some DML command like Insert or update it does not give any error during execution but no row is inserted or updated.
I am in trouble need help immediately.
IqbalThanks for your help. I had commit in my triggers but for test I created a new test report and defined one beforeReport and one group filter triggers. Group filter is working but trigger does not. Here is the code for triggers:
CREATE OR REPLACE PACKAGE BODY newtest AS
function BeforeReport return boolean is
begin
IF p_deptid=10 THEN
p_whereclause:='AND Departments.department_id=10';
ELSIF p_deptid=20 THEN
p_whereclause:='AND Departments.department_id=20';
ELSIF p_deptid=30 THEN
p_whereclause:='AND Departments.department_id=30';
ELSIF p_deptid=50 THEN
p_whereclause:='AND Departments.department_id=50';
ELSIF p_deptid=40 THEN
p_whereclause:='AND Departments.department_id=40';
ELSE
p_whereclause:=null;
END IF;
return (TRUE);
end;
function g_department_idgroupfilter(department_id in number) return boolean is
begin
IF department_id=40 THEN
return (FALSE);
ELSE
return (TRUE);
END IF;
end;
Functions to refer Oracle report placeholders
END newtest ;
I have defined parameters in package specifications and in template with same name and data type. Its very simple but I dont know why its not firing. Can you tell me technical reason. -
What CD self-study to use to do PLSQL certification?
D20465 Oracle9i: Develop PL/SQL Program Units Self-Study CD Course
or
D20966 Oracle9i: Program with PL/SQL Self-Study CD Course
What someone can recommend me?
thanks
m.Hi,
You should use D20966 Oracle9i: Program with PL/SQL Self-Study CD Course. It is the combination of D20465 with another course. See here for details.
"This course is a combination of the Oracle 9i: PL/SQL Fundamentals Self-Study CD Course (Part 1) and the 9i: Develop PL/SQL Program Units Self-Study CD Course (Part 2)"
It is also the one recommended by Oracle for taking the Program with PL/SQL 1Z0-147 exam.
Mike
Maybe you are looking for
-
Can I boot from an external drive with a "Virtual CD"
I just purchased a Hitachi LifeStudio external hard drive for use as my Time Machine backup. When I plugged it in to my MacBook running 10.6.4, I realized that it had one of those "Virtual CDs" that contained the manufacturers crapware, similar to We
-
How can i create a link in a WorkItem body? When the user clicks on the link, he should be taken to a SAP transaction, say FPL9 or any SAP transaction for that matter.
-
Hi Guys, I'm having some issues updating the device packages for my RME 4.3.1 install. I've downloaded and tried to update the 'Cat3560.zip' package via the GUI, but the job fails with the above error. I pulled up the PSU.log and found the following:
-
Hi, I can see it in iBooks under the purchased section, but when I Tap on the book, it just brings up the book description and reviews. It's labeled as downloaded. Where do I go to read it? Thanks!
-
Hi Skype is cancelling my account from 09/08/2013 without authority from me. I don't want it cancelled who gave the authority to do so?! Account name redacted to protect privacy.