Autonomous Transactions usage in PL/SQL anonymous block coding
Hi,
I am trying to incorporate Autonomous Transaction for our work. I am using the tables provided below,
CREATE TABLE T1
F1 INTEGER,
F2 INTEGER
CREATE TABLE T2
F1 INTEGER,
F2 INTEGER
insert into t1(f1, f2)
values(20, 0)
insert into t2(f1, f2)
values(10, 0)
Now, when I use the code snippet given below, it is working as expected.
create or replace procedure p1 as
PRAGMA AUTONOMOUS_TRANSACTION;
begin
update t2
set f2 = 25
where f1 = 10;
commit;
end;
declare
PRAGMA AUTONOMOUS_TRANSACTION;
a integer;
begin
update t1
set f2 = 15
where f1 = 20;
p1();
rollback;
end;
Here, updation in t2 table is commited and t1 is rolled back, it is working as
expected. I would like to achieve the same functionality through PL/SQL
anonymous block coding, to do this, I use the following code snippet,
declare
PRAGMA AUTONOMOUS_TRANSACTION;
a integer;
begin
update t1
set f2 = 15
where f1 = 20;
begin
update t2
set f2 = 35
where f1 = 10;
commit;
end;
rollback;
end;
Here, data in both the tables are commited, how do I change it to work as I
mentioned above like committing t2 alone, please help, thank you.
Regards,
Deva
Can you explain what you're trying to accomplish from a business perspective? This doesn't look like a particularly appropriate way to use autonomous transactions, so you may be causing yourself problems down the line.
That said, padders's solution does appear to work for me
SCOTT @ nx102 Local> CREATE TABLE T1
2 (
3 F1 INTEGER,
4 F2 INTEGER
5 )
6 /
Table created.
Elapsed: 00:00:01.03
SCOTT @ nx102 Local>
SCOTT @ nx102 Local>
SCOTT @ nx102 Local> CREATE TABLE T2
2 (
3 F1 INTEGER,
4 F2 INTEGER
5 )
6 /
Table created.
Elapsed: 00:00:00.00
SCOTT @ nx102 Local>
SCOTT @ nx102 Local> insert into t1(f1, f2)
2 values(20, 0)
3 /
1 row created.
Elapsed: 00:00:00.01
SCOTT @ nx102 Local>
SCOTT @ nx102 Local> insert into t2(f1, f2)
2 values(10, 0)
3 /
1 row created.
Elapsed: 00:00:00.01
SCOTT @ nx102 Local> commit;
Commit complete.
Elapsed: 00:00:00.01
SCOTT @ nx102 Local> DECLARE
2 a INTEGER;
3
4 PROCEDURE update_t2
5 IS
6 PRAGMA AUTONOMOUS_TRANSACTION;
7 BEGIN
8 UPDATE t2
9 SET f2 = 35
10 WHERE f1 = 10;
11
12 COMMIT;
13 END update_t2;
14 BEGIN
15 UPDATE t1
16 SET f2 = 15
17 WHERE f1 = 20;
18
19 update_t2;
20
21 ROLLBACK;
22 END;
23 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.04Have you done something else that would cause a deadlock?
Justin
Similar Messages
-
How come the item value does not come thru via PL/SQL anonymous block?
Hi,
It's a Form with 3 tables -
1) ClinicianProfileTb (with about 40 columns, insert/update via DML),
2) PeopleTb (with about 7 columns, insert/update via PL/SQL anonymous block) and
3) ClinicianPracticeTb (with about 10 columns, insert/update via PL/SQL anonymous block) for after-submit-processes.
So I have several After-Submit-Processes. For some reason, it appears that PeopleId which is supposed to come thru via the 2nd After-Submit-Process (ie: Insert/Update PeopleTb) does not do the way it's supposed to. And when I press "Create" button at the bottom, I got the following error msg:
ORA-01400: cannot insert NULL into ("TEST_0712"."CLINICIANPRACTICETB"."PEOPLEID")
I tried the "debug" mode (via edit page link), but to no avail. (I'm newbie, trying to learn and deliver at the same time :)).
I uploaded the app to apex.oracle.com, if someone could kindly take a look and let me know what goes wrong, it'd be greatly appreciated.
workspace: test_0712
app: 43408 - TEST
user: demo
pswd: demoPswd
Page#21 -> look at the After-Submit-Processes -> in "Insert/Update PeopleTb" it appears that PeopeId does not come thru; thus it cannot be updated to ClinicianProfileTb.PeopleId (allows null) -> and thus cannot be inserted into ClincianPracticeTb.PeopleId (which does NOT allow null). Basically my logic is that in order to create ANY row in ClinicianPracticeTb, BOTH PracticeId AND PeopleId must be present.
Acutally I should have used the PeopeTb as DML (as the driving table) to enforce that PeopleId must be present in order to insert ClinicianProfileTb and ClinicianPracticeTb, but it'd be lots of codes to write to insert/update in ClinicianProfileTb (40 columns).
In addition, does ApEx consider EVERY SINGLE after-submit-process are in ONE transaction for commit/rollback? It appears that it treats all PL/SQL anonymous blocks are in ONE transaction, while Automatic Row Processing (DML) is commited/rolled back on its own?
Thanks much,
HelenAll blocks that do not commit in one of the ways I detailed (and which do not explicitly commit using a commit statement) are part of the transaction started with > the first DML statement issued in any of the page processes and continuing until a commit is issued.Say, there are the following processes in the After-Submit-Processes:
1. Process1 -> Automatic Row Processing (DML)
2. Process2 -> PL/SQL anonymous block
3. Process3 -> PL/SQL anonymous block
Based on what you describe, in the event that if there is no explicit "commit" issued in any of these processes, then an implicit "commit" will be issued at the end of Process3?
Thanks, Scott.
Doreen -
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. -
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 ?
-
Using Create table command in a Pl/Sql Anonymous Block
Hi,
I need to create a table dynamically based on the table_name and column_names that a user wants. When I use a Pl/sql Anonymous block to do this, it complains. Any suggestions ?
Thanks,
MarisaPersonally this sounds like a bad design to me. I would say under most "normal" circumstances, you should not be creating tables on the fly. Especially one where a user has control over what columns,datatypes to use. Let a developer or dba take care of that.
-
Help!! how to call pl/sql anonymous block from java?
I know that jdbc can call a pl/sql package or procedure,but if i
want to call a pl/sql anonymous block, how can i do it? no procedure
name or package name will be offered.
Can u give me a sample code? thanks very muchthanks ,but do u make sure that it can work? i have tried to do like this ,but i can not get it. Or please give me a detail code, thanks very much
-
Need help displaying item based on pl/sql anonymous block
This is probably something really simple but I'm stuck.....
On purchase order, I want to show related parent project name and ID. What is the best way to do it? I have created a region based on pl/sql anonymous block, and that works, but the data is above where I want it. I want the project name and ID to show up in the region w/ all the other fields.
I have created an item in the region that has other form fields, item is based on pl/sql anonymous block, w/ same code as above region, and the item doesn't find the data. What's the difference? Is it because the item doesn't save state? In order to choose for the item to be based on pl/sql anon block, APEX made me choose Display as Text (based on PLSQL, does not save state).
Please see this picture:
http://farm3.static.flickr.com/2391/2658673285_04f157a3fa_o.png
thanks!
~Darbythis is weird.. Now it is working. I didn't change anything! What the heck?
http://farm3.static.flickr.com/2010/2659557520_73e54b67ea_o.png -
Refresh pl/sql anonymous block via dynamic action?
Greetings again to the community!
Something I must be misunderstanding.
I want to dynamically (ajax) update a select list depending on a page item. Now when you research for operations like this, you get some examples - but which mostly are older and... contain a lot of coding. So I am wondering if this is to be achieved in a simple way using dynamic action.
I have created a testcase here where the html for a select list ist created in a pl/sql anonymous block like that:
begin
for i in (select EMPNO, ENAME from EMP
where DEPTNO = :P50_DEP_NO or
:P50_DEP_NO is null)
loop
htp.p('<option value="' || i.EMPNO || '">' || i.ENAME || '</option>');
end loop;
end;Region header and footer contain the tags for <select id="selEmps"> ... </select>.
When you press [Btn Update Sel], a dynamic action is triggered, that submits :P50_DEP_NO, then refreshes the region with the pl/sql code, so that, after you have enteres another value in :P50_DEP_NO, the select list then shows the employees of that department. Thats the plan, but
Its not working! Can anyone tell me, what I have overlooked here, please?
Thank you and good night for now,
tobiHi Marko,
thanks for your hint. I have already tought about that, but im not sure if this is the solution of this particular situation, because the list really should be generated html-code for formating reasons with jQuery UI and further processing. But I have not worked so much with cascading LOVs, so I really should look into it further.
If I dont find a solution there, I'll get back here.
Thanks and so long,
tobi -
Multi Row update using pl/sql anonymous block process
Does anyone have an example of multi row update using a pl/sql anonymous block process?
The reason I can not use the apex mru process is that the table in questions has a five field key.
My attempts have failed with a bad number.
Thanks,
GaryHi Gary,
can y<ou pls send the definition of thet table and the UPDATE sql.
It is a littel difficult like this.
We need more info.
BR,
Lutz
=;-) -
PL/SQL Anonymous Block - Trying to Call Function within Cursor
Hello -
I need to create an anonymous block that contains a cursor and a function. I want to call the function from within the cursor, and the function will basically take an ID as its IN parameter, and will return a comma separated list of values.
However, when I try to do this I get the error " function 'GET_PAYMENT_DATES' may not be used in SQL".
Does anyone know of a workaround? I'm trying to avoid having to store this function.
Thanks,
ChristineExploring Keith's suggestion of using the function code inline in your SQL:
test@ORA10G>
test@ORA10G> --
test@ORA10G> drop table t;
Table dropped.
test@ORA10G> drop table monetary_trans;
Table dropped.
test@ORA10G>
test@ORA10G> create table monetary_trans as
2 select 1 household_id, trunc(sysdate)-10 received_date from dual union all
3 select 1, trunc(sysdate)-9 from dual union all
4 select 1, trunc(sysdate)-8 from dual union all
5 select 2, trunc(sysdate)-7 from dual union all
6 select 2, trunc(sysdate)-6 from dual;
Table created.
test@ORA10G>
test@ORA10G> create table t as
2 select rownum x, rownum*10 y from dual connect by level <= 4;
Table created.
test@ORA10G>
test@ORA10G> --
test@ORA10G> select * from monetary_trans;
HOUSEHOLD_ID RECEIVED_
1 28-DEC-08
1 29-DEC-08
1 30-DEC-08
2 31-DEC-08
2 01-JAN-09
test@ORA10G> select * from t;
X Y
1 10
2 20
3 30
4 40
test@ORA10G>
test@ORA10G> --
test@ORA10G> -- the function code could be rewritten as follows
test@ORA10G> --
test@ORA10G> select household_id,
2 ltrim(sys_connect_by_path(rd,','),',') payment_dates
3 from
4 (
5 select household_id,
6 to_char(received_date,'mm/dd/yy') as rd,
7 row_number() over (partition by household_id order by 1) rn,
8 count(*) over (partition by household_id) cnt
9 from monetary_trans
10 -- and the constraints here in the where clause
11 )
12 where level = cnt
13 start with rn = 1
14 connect by prior household_id = household_id
15 and prior rn = rn - 1
16 and household_id = 1 -- <== this is the input parameter value
17 ;
HOUSEHOLD_ID PAYMENT_DATES
1 12/28/08,12/29/08,12/30/08
test@ORA10G>
test@ORA10G> --
test@ORA10G> -- and can be used as an inline view when joined with other tables
test@ORA10G> --
test@ORA10G> select t.y,
2 fn.payment_dates
3 from t,
4 (select household_id,
5 ltrim(sys_connect_by_path(rd,','),',') payment_dates
6 from (select household_id,
7 to_char(received_date,'mm/dd/yy') as rd,
8 row_number() over (partition by household_id order by 1) rn,
9 count(*) over (partition by household_id) cnt
10 from monetary_trans)
11 where level = cnt
12 start with rn = 1
13 connect by prior household_id = household_id
14 and prior rn = rn - 1
15 ) fn
16 where t.x = fn.household_id
17 ;
Y PAYMENT_DATES
10 12/28/08,12/29/08,12/30/08
20 12/31/08,01/01/09
test@ORA10G>
test@ORA10G>HTH
isotope -
Raise error in PL/SQL anonymous block
I have this situation:
1. When a button on a page is clicked, 5 mails have to be send to 5 employees.
2. I created a sent mail process that fetches the 5 employees and their e-mail address out of the employee table and sends a mail for each employee.
So far so good. This works fine. But now it is possible that the e-mail field in the employee table isn't filled out all the time. So I want to check this before the mails are send and if one of the employees has no valid e-mail address, clicking the mail button has to notifie the user of the fact that one or more of the employees don't have a valid e-mail address (and don't send any of the mails). I'd also like to inform the user which employe(s) has no valid e-mail address.
How can I accomplish this? I was thinking of making the mail process conditional (only if all mail addresses are there) and make another process linked to the mail buttont, that does the checking and gives back the appropriate message (in the process message area on the form).
But is there a way to make the PL/SQL process to return the error message to the form? In that case I could do all the validating in the mail process and make te process return the process error message if not all e-mail addresses are correct.Good morning,
Look at this thread.
[raise_application_error|http://forums.oracle.com/forums/thread.jspa?threadID=837631]
Don.
You can reward this reply by marking it as either Helpful or Correct :) -
Pl/sql anonymous block and procedure ??
Hi I want to ask a question about my sql query and procedure.
I wrote a like this.. it's şanguage is my native language but my question is not related language. I wrote this query like procedure. So procedure's code same this. But this query retrieve right result but procedure is not retrieve right result. What is cause of this situation. is fault definiton of procedure or what ?
quey is this
-- d?sardan girilen y?l birim ve sn?f baz al?narak basar?l? ö?rencilerin getirilmesi
SELECT da.acilan_ders_no, da.ders_kodu,oa.ogrenci_no, da.ders_adi,dk.harf_kodu
FROM ders_aktif da,ders_tanim dt,ogrenci_akademik oa,ders_kayit dk
WHERE da.acildigi_yil='2009' and
oa.ders_baslama_yil='2009'and
oa.birim like '1521%'and
(da.acildigi_donem='1'or
da.acildigi_donem='2')and
da.ders_kodu like '1521%'and
(dt.normal_yariyili='1' or
dt.normal_yariyili='2')and
dt.ders_kodu=da.ders_kodu and
da.acilan_ders_no=dk.acilan_ders_no and
(dk.harf_kodu!='FF' and
dk.harf_kodu!='DZ' and
dk.harf_kodu!='YZ') and
oa.ogrenci_no=dk.ogrenci_no
order by oa.ogrenci_no desc
;procedure is this
create or replace
PROCEDURE SINIF_BAZINDA_BASARI(yil in number, birimno in number)IS
acilan_ders_no number;
ders_kodu VARCHAR2(12);
ogrenci_no VARCHAR2(12);
ders_adi VARCHAR2(50);
harf_kodu VARCHAR2(4);
CURSOR c_basari IS
SELECT da.acilan_ders_no, da.ders_kodu,oa.ogrenci_no, da.ders_adi,dk.harf_kodu
into acilan_ders_no,ders_kodu,ogrenci_no,ders_adi,harf_kodu
FROM ders_aktif da,ders_tanim dt,ogrenci_akademik oa,ders_kayit dk
WHERE da.acildigi_yil=yil and
oa.ders_baslama_yil=yil and
oa.birim like birimno ||'%' and
(da.acildigi_donem='1'or
da.acildigi_donem='2')and
da.ders_kodu like birimno ||'%' and
(dt.normal_yariyili='1' or
dt.normal_yariyili='2')and
dt.ders_kodu=da.ders_kodu and
da.acilan_ders_no=dk.acilan_ders_no and
(dk.harf_kodu!='FF' and
dk.harf_kodu!='DZ' and
dk.harf_kodu!='YZ') and
oa.ogrenci_no=dk.ogrenci_no
order by oa.ogrenci_no ASC
BEGIN
FOR I IN c_basari LOOP
dbms_output.put_line('ACILAN DERS NO'||I.acilan_ders_no||' DERS KODU '|| I.DERS_KODU||'OGRENCI NO '||I.OGRENCI_NO||' DERS ADI '||I.DERS_ADI||' HARF KODU '||I.HARF_KODU);
end loop;
END ;78091 152111003 152120091063 INTRODUCTION TO COMPUTER ENGINEERING I YT
78831 152111006 152120091063 PHYSICS I LAB BA
78090 152111002 152120091063 INTRODUCTION TO COMPUTERS DD
79000 152111009 152120091062 EXPOSITORY WRITING CC
78091 152111003 152120091062 INTRODUCTION TO COMPUTER ENGINEERING I YT
78090 152111002 152120091062 INTRODUCTION TO COMPUTERS DC
78831 152111006 152120091062 PHYSICS I LAB BA
81888 152111008 152120091062 CHEMISTRY LAB. CB
78089 152111001 152120091062 CALCULUS I CB procedure retrieve
78091 152111003 152120091063 INTRODUCTION TO COMPUTER ENGINEERING I YT
78831 152111006 152120091063 PHYSICS I LAB BA
78090 152111002 152120091063 INTRODUCTION TO COMPUTERS DD
79000 152111009 152120091062 EXPOSITORY WRITING CC
78091 152111003 152120091062 INTRODUCTION TO COMPUTER ENGINEERING I YT
78090 152111002 152120091062 INTRODUCTION TO COMPUTERS DC
78831 152111006 152120091062 PHYSICS I LAB BA
81888 152111008 152120091062 CHEMISTRY LAB. CB
78089 152111001 152120091062 CALCULUS I CB
78089 152111001 152120091062 CALCULUS I CB
78830 152111005 152120091062 PHYSICS I DC
78832 152111007 152120091062 CHEMISTRY CC
78830 152111005 152120091050 PHYSICS I BA
78091 152111003 152120091050 INTRODUCTION TO COMPUTER ENGINEERING I YT
78090 152111002 152120091050 INTRODUCTION TO COMPUTERS AA
78089 152111001 152120091050 CALCULUS I BB
78094 152111010 152120091050 INTRODUCTION TO PROGRAMMING BA
79000 152111009 152120091050 EXPOSITORY WRITING CC
81888 152111008 152120091050 CHEMISTRY LAB. CB
78832 152111007 152120081050 CHEMISTRY CB
78831 152111006 152120081050 PHYSICS I LAB BB
78090 152111002 152120081043 INTRODUCTION TO COMPUTERS CC
81888 152111008 152120081043 CHEMISTRY LAB. CB
78091 152111003 152120081043 INTRODUCTION TO COMPUTER ENGINEERING I YT
79000 152111009 152120081043 EXPOSITORY WRITING BB
78831 152111006 152120081043 PHYSICS I LAB BB
78832 152111007 152120081043 CHEMISTRY DD
78090 152111002 152120071038 INTRODUCTION TO COMPUTERS BA
79000 152111009 152120071038 EXPOSITORY WRITING CC
78094 152111010 152120071038 INTRODUCTION TO PROGRAMMING DC
78089 Edited by: esra aktas on 17.May.2011 10:34 -
PL/SQL anonymous block delete procedure
Dear All,
the below procedure works only if I use the value inside :P29_FAMILY_CALL_OUT, seems that the procedure doesn't get the value of :P29_FAMILY_CALL_OUT variables, why?
many thanks in advance
regards
Carmelo Pace
declare
l_season_markup_id number;
begin
select season_markup_id into l_season_markup_id from season_markup where CALL_OUT = :P29_FAMILY_CALL_OUT;
DELETE FROM season_markup where season_markup_id = l_season_markup_id;
end;Eric:
Do you know if it is a named exception in PL/SQL? If so I could replace a lot of my code that does:
PROCEDURE P
doesnt_work EXCEPTION
BEGIN
do_something;
IF <condition> THEN
RAISE doesnt_work
ELSE
do_more_stuff;
END IF;
EXCEPTION
WHEN doesnt_work THEN
RAISE_APPLICATION_ERROR (20001, 'Doesn''t Work encountered');
END;with
PROCEDURE P
BEGIN
do_something;
do_more_stuff;
EXCEPTION
WHEN doesnt_work THEN
RAISE_APPLICATION_ERROR (20001, 'Doesn''t Work encountered');
END;John -
Function defined in anonymous block?
Quick question. I'd like to define a temporary function in a PL/SQL anonymous block. I'm thinking that I've seen an example of that done before, but I can't seem to find the example. Here's the source. Given a table name, I want to return a comma-delimited list of the columns in the table. As a stored function, this works like a charm:
CREATE OR REPLACE
FUNCTION columnlist_csv (in_tablename VARCHAR2) RETURN VARCHAR2 IS
v_columnlist VARCHAR2(4000);
v_num_columns NUMBER(4,0);
CURSOR c1(c1_tablename VARCHAR2) IS
SELECT column_name, column_id FROM user_tab_columns
WHERE table_name = c1_tablename ORDER BY column_id;
BEGIN
SELECT count(*) INTO v_num_columns FROM user_tab_columns WHERE table_name=in_tablename;
FOR c1row IN c1(in_tablename) LOOP
v_columnlist := v_columnlist||c1row.column_name;
IF c1row.column_id < v_num_columns THEN
v_columnlist := v_columnlist||', ';
END IF;
END LOOP;
RETURN v_columnlist;
END;
SELECT columnlist_csv(upper('&tablename')) FROM dual;
But, rather than having the function be a stored function, I'd prefer to define a temporary function on the fly in the script, like below. However, this doesn't work as an anonymous block. I believe I simply have the syntax wrong, and I'm hoping someone like lend a second pair of eyes...
DECLARE
FUNCTION columnlist_csv (in_tablename VARCHAR2) RETURN VARCHAR2 IS
v_columnlist VARCHAR2(4000);
v_num_columns NUMBER(4,0);
CURSOR c1(c1_tablename VARCHAR2) IS
SELECT column_name, column_id FROM user_tab_columns
WHERE table_name = c1_tablename ORDER BY column_id;
BEGIN
SELECT count(*) INTO v_num_columns FROM user_tab_columns WHERE table_name=in_tablename;
FOR c1row IN c1(in_tablename) LOOP
v_columnlist := v_columnlist||c1row.column_name;
IF c1row.column_id < v_num_columns THEN
v_columnlist := v_columnlist||', ';
END IF;
END LOOP;
RETURN v_columnlist;
END;
SELECT columnlist_csv(upper('&tablename')) FROM dual;
Can anyone advise?
Regards,
DaveI want to return a comma-delimited list of the columns in the tableIf this is the goal, you could use a simple SELECT statement, SQL> desc test111;
Name Null? Type
TRX_NUMBER VARCHAR2(20)
TRX_AMOUNT NUMBER(12,2)
SQL> select decode(column_id,1,'',',') || lower(column_name) col_name
2 from user_tab_columns
3 where table_name = upper('&table_name')
4 order by column_id
5 /
Enter value for table_name: test111
old 3: where table_name = upper('&table_name')
new 3: where table_name = upper('test111')
COL_NAME
trx_number
,trx_amountThx,
SriDHAR -
Changing Oracle Passwords through HTML DB anonymous blocks
I am attempting to use DAD as my authentication method. The site will only be accessible through an SSL connection, so I'm not too worried about security. Plus it is a small target audience. I don't want to mess with LDAP because of the unnecessary complexity of adding it just for a single application. One of the requirements is changing passwords through the application. I always get an ORA-01935 (missing user or role name). Any ideas?
Just a note, I get this from an after submit process that executes the following pl/sql anonymous block:
begin
execute immediate 'alter user :P9_USERNAME identified by :P9_PASSWORD1';
exception
when others then
raise_application_error(-20911, 'Could not change password for user: ' || :P9_USERNAME || ' ' || SQLERRM);
end;
Maybe you are looking for
-
After intalling some updates for Final cut, I m asked to put my first and last names and serial number which unfortunatelt i do not have. how do i go about this?
-
My Apple TV is connected to a TV that supports up to 480p (75Hz). It is set at the resolution: 640 by 480 at 60Hz. It still does not work. The TV says Not Support.
-
How to buy a unlocked iPhone5 on the website?
I can't found the link online!
-
Plz: Replication 9i Job Network Problem Hang
Hi ,This problem is posted on this forum by other users but all of them remained unresponsed! I hope somebody will help me now: I have a hang problem in 9i We are using bidirectional Replication (Materialized View Replication) and when mview refresh
-
Time Series Format of Operating System Statistics - "Please Ignore"
Hi List, On the AWR report we see the "Operating System Statistics" section.. since generating multiple AWR reports is daunting and takes a lot of time and I'm only interested on particular columns of dba_hist_osstat (where that particular section of