Column name of a cursor
How can I get the column name of a cursor?
I want to catch the column name of a cursor dynamically.
declare
cursor xx is select * from yy;
begin
for i in xx
loop
my requirement is as below
message(xx.columnName(i));
end loop;
end;
Similar Messages
-
Can we use Column Names in Parameter Cursor
Hi
can we use Column Names in Parameter Cursor??
DECLARE
CURSOR Emp_Cur (P_Deptno NUMBER)
IS
SELECT Empno, Ename
FROM Emp
WHERE Deptno = P_Deptno;
BEGIN
FOR Emp IN Emp_Cur(10)
LOOP
DBMS_OUTPUT.PUT_LINE('The Employee Number is: '||emp.Empno);
DBMS_OUTPUT.PUT_LINE('The Employee Name is: '||emp.Ename);
END LOOP;
FOR Emp IN Emp_Cur(20)
LOOP
DBMS_OUTPUT.PUT_LINE('The Employee Number is: '||emp.Empno);
DBMS_OUTPUT.PUT_LINE('The Employee Name is: '||emp.Ename);
END LOOP;
END;
In the above Program, I send Deptnumber. If i send Column names like Empno, Ename. What can i do??
If Declare Samething Through Parameter Cursor, it doesn't accept VARCHAR2(Size)For parameters you don't use size, just the type (DATE, NUMBER, VARCHAR2, CLOB, ...)
DECLARE
CURSOR Emp_Cur (P_Ename VARCHAR2)
IS
SELECT Empno, Ename
FROM Emp
WHERE Ename = P_Ename;
BEGIN
FOR Emp IN Emp_Cur('SCOTT')
LOOP
DBMS_OUTPUT.PUT_LINE('The Employee Number is: '||emp.Empno);
DBMS_OUTPUT.PUT_LINE('The Employee Name is: '||emp.Ename);
END LOOP;
END; -
Dynamic Column name in a Cursor
Hello there,
How can I access data in cursor's field with dynamic fields names, more illustration follows:
My table has columns named as C1,C2,C3 so on
defined a cursor cursor_name on that table,
I need to access the fields by a loop like this:
OPEN cursor_name;
Fetch cursor_name into rec;
for i in 1 .. 10 loop
if rec.ci = 1Then
end if;
end loop
close cursor_name;
where rec,ci represents the name of the cursor fields, so that I loop over them,
how can I implement such an idea,
thanks in advance
regardsThanks Bily, and user10715047,
actually the reason behind the need of such an approach, is as following:
assume that I have table of set of logical conditions, " LOGICAL CONDITIONS" has three columns: ID, Condition_name and the logical_condition, example:
1, c1, x = 1
5, c2, y = 2
10, c3, p = 3 where ID is just a sequence to identify the records from each other "primary key"
assume that I need to provide the possible combination of the result of applying each of the conditions, for example :
if c1 = 1 ,c2= 0 and c3= 1 then my result must be 1 ' This according some predefined rulesso that I created table which contains all the possible logical conditions, ( as the max number of logical conditions are known)
defined as follows : combination( combination_ID, c1, c2, c3, c4, ....cmax, result)
sample record:
combination_ID, c1, c2, c3, .. c max, result
100, 1, 0, 1, ....., 1, 1in the PL/SQL procedure, I would get all the needed combination, into a cursor, then to optimized the code, I need to access the fields ( which is the Ci) in a loop
for i in 1..3 loop
if cursor_rec.ci = 1 then
Action
end if;
end loop;the dynamic name I meant in my first post was this : cursor_rec.ci ,
so that I can access the cursor's fields without the need to name them one by one, as there could be long sequence of conditions to be checked.
hope that I made the idea clearer, Any suggestions, please !
anyway I will give the DBMS_SQL cursors a shot , try if I can use to implement the purpose,
as I know similar dynamical variable names, is available in Java,
Regards, -
Hi,
I am using OCCI to interact with DB through code, which means I am writing a vc++ file to interact with Data Base and execute the Stored Procedure which I am calling from the C++ Code. And also displaying the output of the Stored Procedures to the Front End. I am succeeded in this, but now I should be able to display the Column names of the output to Front End. Can any one help me on this.
Example:
Sno | Sname
------- |-------------
1 ABC
2 DEF
I am getting (1,ABC) and (2,DEF) as the output of the Stored Procedure but I need the Column names also to display. How to get them.
Thanks in Advance..:)Look at Re: exporting csv via pl/sql - select statement?
It has an example how to extract the column name from a cursor. You have to check, whether you can use DBMS_SQL.DESCRIBE_COLUMNS
Your procedure might need another out parameter, that returns the column names , e.g. as comma separated list or as varray. -
How to obtain the updated column name in a trigger?
Hello everyone,
I need to know for audit propose the updated column name in a After Update Trigger on a Table.
The table have more than 20 columns, and i think that do more than 20 conditions asking for the difference between the :new value and the :old value is not the best way.
Thanks for the help!
LCJHi,
Thanks to all for the replays.
I didn't know that i can pass the column name to the UPDATING. This is only possible on 10g??
Any way, i pass the column name and works fine, but i have another issue because of that.
I obtain the column name from a cursor that query user_tab_columns view, when i try to obtain the value of the :old or :new, i can't because i don't know how to obtain the value of the value.
This example show better:
DECLARE
vOldValue Varchar2(50);
Cursor cur_Column_Names Is
Select COLUMN_NAME
From User_Tab_Columns
Where TABLE_NAME = 'table_name';
BEGIN
For var_cursor In cur_Column_Names Loop
If Updating(var_cursor.COLUMN_NAME) Then
vOldValue := '?'; -- How obtain the value of the :old. + >var_cursor.COLUMN_NAME??
End If;
End Loop;
END;Thanks to all for the help.
LCJ -
Determining column name at runtime
I have created a function that accepts a number of parameters, passes these values into a cursor which retrieves the appropriate values from the database and then I do my processing based on what the database returns. The specific problem here is that I need to look at each column in the table individually, but I don't want to hard-code the column name in my cursor. The cursor I tried to use for this purpose is below for your reference. It appears that I get the correct value returned from the query I aliased as B. If I run the statement below with the B.column_name hard-coded as q1000 (one of the actual column names), I get no rows returned which is the answer I'm looking for. However, it doesn't appear to be using the returned q1000 from query B and substituting that for B.column_name, so I get 1 row returned. I also looked at using Dynamic SQL and either I'm doing it wrong, or it isn't the correct solution to my problem. Any help would be appreciated. :)
CURSOR current_diary_cur IS
SELECT d.dmonth, d.dday
FROM p2_diary d, form_log f, (SELECT column_name
FROM all_tab_columns
WHERE table_name = 'P2_DIARY'
AND column_name = p_diary_field) B
WHERE d.form_seq = f.form_seq
AND f.subj_seq = p_subj_seq
AND f.visit_num = p_cur_vnum
AND d.dmonth = p_dmonth
AND d.dday = p_dday
AND B.column_name IS NOT NULL;One of my co-workers said something that made me realize a mistake I made in the post below. I am actually trying to do this in a Forms library and not Procedure Builder. We are using Forms version 6.0.8.11.3. Am I not able to use Dynamic SQL in this version of Forms?
Thanks for your reply. I tried to use the example you gave me and ran into compiler problems. So, I tried another example from Oracle8i Application Developer's Guide - Fundamentals Release 2 (8.1.6) documentation on Dynamic SQL - the function is listed below. When I tried to compile it, the compiler error I got was Encountered the symbol "STMT_STR" when expecting one of the following: select. This error occurs at the line where you open the cursor. This is the same message when I tried your code also. Am I doing something wrong, is my system not set up to handle this or is there some other problem I'm having? I'm trying to do this through Proc Builder and not at the command line...does this make a difference? Help!
FUNCTION my_func
return number
is
TYPE EmpCurTyp IS REF CURSOR;
cur EmpCurTyp;
stmt_str VARCHAR2(200);
name VARCHAR2(20);
salary NUMBER;
BEGIN
stmt_str := 'SELECT ename, sal FROM emp
WHERE job = :1';
OPEN cur FOR stmt_str USING 'SALESMAN';
LOOP
FETCH cur INTO name, salary;
EXIT WHEN cur%NOTFOUND;
-- <process data>
END LOOP;
CLOSE cur;
END; -
Dynamically Pass the Column Name cursor. || Dynamic Column Name
Hi,
I need to dynamically pass the column name based on a Mapping table in a loop ( Right now i have hardcoded stuff )just like using Execute immediate.... Inside the procedure, I have commented as where i hit the problem.
Thanks for all of your time...
Thanks
Muthu
CREATE OR REPLACE PROCEDURE xml_testing_clob AS
doc xmldom.DOMDocument;
main_node xmldom.DOMNode;
root_node xmldom.DOMNode;
user_node xmldom.DOMNode; item_node xmldom.DOMNode;
root_elmt xmldom.DOMElement;
item_elmt xmldom.DOMElement;
item_text xmldom.DOMText;
item_test xmldom.DOMText;
nodelist xmldom.DOMNodeList;
sub_variable varchar2(4000);
x varchar2(200);
y varchar2(200);
sub_var varchar2(4000);
CURSOR get_users IS
SELECT FIRST_NAME,LAST_NAME,ROWNUM FROM USER_INFO_TBL WHERE WEIN_NUMBER = '1234' ;
CURSOR get_cdisc_name IS
select CTS_COL_NAME,CDISC_NAME from CTS2CDISC_DICTIONARY where CTS_TABLE_NAME = 'USER_INFO_TBL';
BEGIN
-- get document
doc := xmldom.newDOMDocument;
doc := xmldom.NewDomDocument;
xmldom.setVersion(doc, '1.0');
xmldom.setStandalone(doc, 'no');
xmldom.setCharSet(doc, 'ISO-8859-1');
-- create root element main_node := xmldom.makeNode(doc);
root_elmt := xmldom.createElement(doc,'AdminData');
root_node := xmldom.appendChild(main_node,xmldom.makeNode(root_elmt));
FOR get_users_rec IN get_users LOOP
item_elmt := xmldom.createElement(doc,'User');
xmldom.setAttribute(item_elmt,'OID' , get_users_rec.rownum);
user_node := xmldom.appendChild(root_node,xmldom.makeNode(item_elmt));
FOR cv_get_cdisc_name IN get_cdisc_name LOOP
EXIT WHEN get_cdisc_name%NOTFOUND;
sub_var := cv_get_cdisc_name.cts_col_name;
sub_variable := 'get_users_rec.';
sub_variable := 'get_users_rec.'||cv_get_cdisc_name.cts_col_name;
x := sub_variable;
dbms_output.put_line(x); -------------- Here i just see the literal string
y := get_users_rec.FIRST_NAME;
dbms_output.put_line(y); -------------- Here i just see actual value ( data )
item_elmt := xmldom.createElement(doc,cv_get_cdisc_name.cdisc_name);
item_node := xmldom.appendChild(user_node,xmldom.makeNode(item_elmt));
item_text := xmldom.createTextNode(doc,x ); ---- This is the place i am hitting with an error .
If i use variable X then i am able to see only the literal
string in the output. BUT if i put cursor name.coulmname,
then the resumt (XML) is fine.I wanted acheive this
dynamically just like execute Immediate
item_node := xmldom.appendChild( item_node , xmldom.makeNode(item_text));
END LOOP;
END LOOP;
-- write document to file using default character set from database
xmldom.WRITETOCLOB(doc,);
xmldom.writeToFile(doc, 'c:\ash\testing_out.xml');
-- free resources
xmldom.freeDocument(doc);
END;
+++++++++++++++++++++++++++++++++++ XML OUTPUT +++++++++++++++++++++++++++++++++++++++++
<?xml version="1.0" ?>
- <AdminData>
- <User OID="1">
<FirstName>get_users_rec.FIRST_NAME</FirstName>
<LastName>get_users_rec.LAST_NAME</LastName> </User>
- <User OID="2">
<FirstName>get_users_rec.FIRST_NAME</FirstName>
<LastName>get_users_rec.LAST_NAME</LastName>
</User>
- <User OID="3">
<FirstName>get_users_rec.FIRST_NAME</FirstName>
<LastName>get_users_rec.LAST_NAME</LastName>
</User>
- <User OID="4">
<FirstName>get_users_rec.FIRST_NAME</FirstName>
<LastName>get_users_rec.LAST_NAME</LastName>
</User>
- <User OID="5">
<FirstName>get_users_rec.FIRST_NAME</FirstName>
<LastName>get_users_rec.LAST_NAME</LastName>
</User>
++++++++++++++++++++++++++++++++++++++++++++++++++++ MAPPING TABLE DETAILS +++++++++++++++++
CTS_COL_NAME CDISC_NAME CTS_TABLE_NAME XML_TAG -----------> Column Name
FIRST_NAME FirstName USER_INFO_TBL Element -----------> Records
LAST_NAME LastName USER_INFO_TBL Element -----------> RecordsMy scenario is little different, let me explain:
My columns will remain same but values changes (based on column formula) according to the selected prompt value
If I select 'Oct' from prompt then
Curr will contain data for 'Oct' only
Next1 will contain data for 'Nov' only
Next2 will contain data for 'Dec' only
Next3 will contain data for 'Jan' of next year only.
Later if I select 'Jul' from prompt then
Curr will contain data for 'Jul' only
Next1 will contain data for 'Aug' only
Next2 will contain data for 'Sep' only
Next3 will contain data for 'Oct' only.
I don't have different columns for each months but the columns are capable to reflect data for any month.
So, how can I reflect the column name as month name for which that contains data.
Regards,
S Anand -
Alias required in SELECT list of cursors to avoid duplicate column names
I got some error messages while compiling the following.
DECLARE
alert_id NUMBER;
CURSOR cur_search IS SELECT c.item_description,
d.name modelname,
SUM(b.quentaty),
SUM(b.balence)
FROM item_procurement_history_dtl a,
item_procurement_history b,
item_master c,
model_master d
WHERE a.item_code = b.item_code
AND a.lot_no = b.lot_no
AND a.item_code = c.item_code
AND b.modelcode = d.modelcode
AND (c.item_description LIKE '%'||:blk_stock_search_fields.item_name||'%' OR :blk_stock_search_fields.item_name IS NULL)
AND (d.name LIKE '%'||:blk_stock_search_fields.modelname||'%' OR :blk_stock_search_fields.modelname IS NULL)
AND (a.status = :blk_stock_search_fields.status OR :blk_stock_search_fields.status IS NULL)
GROUP BY c.item_description, d.name
ORDER BY c.item_description, d.name;
BEGIN
GO_BLOCK('blk_stock_search_fields');
CLEAR_BLOCK(NO_VALIDATE);
FOR i IN cur_search LOOP
:blk_stock_search_data.item_name := i.item_description;
:blk_stock_search_data.modelname := i.modelname;
:blk_stock_search_data.tot_qty := i.tot_qty;
:blk_stock_search_data.available_qty := i.available_qty;
NEXT_RECORD;
END LOOP;
FIRST_RECORD;
GO_ITEM('blk_stock_search_fields.pb_search');
END;
The error is as follows :-
Error 403 at line 23 column 2
Alias required in SELECT list of cursors to avoid duplicate column names.
What will be the solution for this error?
Thanx and Regards,
VikasVikas,
The problem is that you are referencing a column name in your LOOP that does not exist in your CURSOR. Therefore, Oracle has interpreted this to its BEST guess Exception. This can be resolved as follows:
DECLARE
alert_id NUMBER;
CURSOR cur_search IS
SELECT c.item_description,
d.name modelname,
/* You need to ALIAS the product of the SUM() so you can reference it by name.*/
SUM(b.quentaty) AS tot_qty,
/* Same issue here, you must ALIAS the SUM() of Balance in order to reference it by a name.*/
SUM(b.balence) as available_qty
FROM item_procurement_history_dtl a,
item_procurement_history b,
item_master c,
model_master d
WHERE a.item_code = b.item_code
AND a.lot_no = b.lot_no
AND a.item_code = c.item_code
AND b.modelcode = d.modelcode
AND (c.item_description LIKE '%'||:blk_stock_search_fields.item_name||'%' OR :blk_stock_search_fields.item_name IS NULL)
AND (d.name LIKE '%'||:blk_stock_search_fields.modelname||'%' OR :blk_stock_search_fields.modelname IS NULL)
AND (a.status = :blk_stock_search_fields.status OR :blk_stock_search_fields.status IS NULL)
GROUP BY c.item_description, d.name
ORDER BY c.item_description, d.name;
BEGIN
GO_BLOCK('blk_stock_search_fields');
CLEAR_BLOCK(NO_VALIDATE);
FOR i IN cur_search LOOP
:blk_stock_search_data.item_name := i.item_description;
:blk_stock_search_data.modelname := i.modelname;
:blk_stock_search_data.tot_qty := i.tot_qty;
:blk_stock_search_data.available_qty := i.available_qty;
NEXT_RECORD;
END LOOP;
FIRST_RECORD;
GO_ITEM('blk_stock_search_fields.pb_search');
END;Just an observation. Also, There are some misspellings in your cursor. Does this match your table?
Hope this helps.
Craig... -
Getting column names from cursor
Hi all
I have procedure which produces list of applied for jobs web page(using htp. package)
I got result in cursor, but have to provide dinamic sort, based on colimn pressed
procedure my_application_list
(pi_resume_num in varchar2 default null
,pi_sort_col in varchar2 default null
,pi_page_no in varchar2 default null
,pi_action in varchar2 default null
,pi_msg in varchar2 default null
is
CURSOR cur_job IS
SELECT jtl.JOB_TITLE
,jtl.COMPANY_NAME
,a.APPLY_DATE
,a.lang
,a.job_id
FROM job_tl jtl, applied_for_job a, gateway gt
WHERE a.job_seeker_id=app.job_Seeker
AND a.job_id=jtl.job_id
AND a.lang=jtl.lang
AND a.gateway=gt.gateway
AND jtl.lang=(SELECT substr(MIN(lt.order_list||jtl0.lang),2) lang
FROM job_tl jtl0
,language_tl lt
WHERE jtl0.job_id = a.job_id
AND jtl0.lang=lt.lang
AND lt.gui_lang=app.language)
ORDER BY pi_sort_col
rest of code
The columns displayed in web page are Job_title, Company_name and Applied_date
This page is displyed well, bu without column nmes at the top. I am trying to get column names from cursor in order to have ORDER BY <pi_sort_col>
can someone help how i can get those column names:Job_title, Company_name and Applied_date
User will be able to click on column and sort
Thank in advance .I appreciate any helpHi Francisco
Here is my code
CREATE OR REPLACE PACKAGE BODY cc_web_application_list
IS
TYPE COL_NAME_LIST IS TABLE OF VARCHAR2(100)
INDEX BY BINARY_INTEGER;
TYPE COL_ORDER_LIST IS TABLE OF VARCHAR2(30)
INDEX BY BINARY_INTEGER;
col_name_t col_name_list;
col_order_t col_order_list;
procedure my_application_list
(pi_resume_num in varchar2 default null
,pi_sort_col in varchar2 default null
,pi_page_no in varchar2 default null
,pi_action in varchar2 default null
,pi_msg in varchar2 default null
is
l_my_page_no PLS_INTEGER := TO_NUMBER(nvl(pi_page_no,1));
l_js_name gam_user.username%TYPE;
l_js_first_name gam_user.first_name%TYPE;
l_cnt PLS_INTEGER := 0;
l_scr_lines PLS_INTEGER := 0;
l_curline PLS_INTEGER;
l_jobs_applied PLS_INTEGER;
l_total_rec PLS_INTEGER;
l_total_pages PLS_INTEGER;
l_pos PLS_INTEGER;
l_first PLS_INTEGER :=0;
last PLS_INTEGER :=0;
l_lines PLS_INTEGER := 10;
col_name VARCHAR2(100) := col_name_t(3) ;
col_order VARCHAR2(30) := 'DESC';
str VARCHAR2(2000);
TYPE display_rec IS TABLE OF VARCHAR2(500) INDEX BY BINARY_INTEGER;
display display_rec;
TYPE page_table_type IS TABLE OF PLS_INTEGER INDEX BY BINARY_INTEGER;
page_number page_table_type;
CURSOR cur_job IS
SELECT jtl.JOB_TITLE job_title
,jtl.COMPANY_NAME company_name
,a.APPLY_DATE apply_date
,a.lang
,a.job_id
FROM job_tl jtl, applied_for_job a, gateway gt
WHERE a.job_seeker_id=app.job_Seeker
AND a.job_id=jtl.job_id
AND a.lang=jtl.lang
AND a.gateway=gt.gateway
ORDER BY a.apply_date;
This decode is a problem
decode(col_order,'ASC'
,decode(col_name
,col_name_t(1), jtl.job_title
,col_name_t(2), jtl.company_name
,col_name_t(3), TO_CHAR(a.apply_date, 'YYYYMMDDhh24miss')
,a.apply_date)
) ASC
,decode(col_order,'DESC'
,decode(col_name
,col_name_t(1), jtl.job_title
,col_name_t(2), jtl.company_name
,col_name_t(3), TO_CHAR(a.apply_date, 'YYYYMMDDhh24miss')
,a.apply_date)
) DESC
,a.apply_date
TYPE rec_one IS TABLE OF cur_job%ROWTYPE INDEX BY BINARY_INTEGER;
r rec_one;
BEGIN
BEGIN
SELECT username,first_name
INTO l_js_name,l_js_first_name
FROM gam_user
WHERE user_id = App.job_seeker;
EXCEPTION
WHEN OTHERS THEN NULL;
END;
Cc_Pkg_Elements.p_page_top_job_seeker(
'Personal Job List'
,REPLACE(Txt_Proc_My_Joblist.title_job_list
,'##first_name##',l_js_first_name),'N' ,TRUE ,'Pxx');
----- get numer of records returned by query
SELECT COUNT(1)
INTO l_total_rec
FROM job_tl jtl,applied_for_job a
,gateway gt
WHERE a.job_id = jtl.job_id
AND a.job_seeker_id = App.job_seeker
AND a.gateway = gt.gateway ;
------get number of pages
l_total_pages:=CEIL (l_total_rec/l_lines);
l_jobs_applied := 0;
col_name := pi_sort_col;
col_order := pi_sort_col;
--get first positions
l_first := (nvl(l_my_page_no,1) - 1) * l_lines + 1;
FOR rec IN cur_job LOOP
l_cnt := l_cnt + 1;
EXIT WHEN l_cnt > l_first + l_lines - 1;
IF l_cnt >= l_first THEN
l_scr_lines := l_scr_lines + 1;
r(l_scr_lines) := rec; --assign counter from loop to r index
IF rec.apply_date IS NOT NULL THEN
l_jobs_applied := l_jobs_applied + 1;
END IF;
END IF;
END LOOP;
htp.p('<FORM ACTION="'||App.gateway||'8.my_application_list" METHOD="post">');
htp.p('<table align="center">');
htp.p('<tr><td>');
IF r.COUNT = 0 THEN
Web_Pkg_Elements.doc_msg(Txt_Proc_My_Joblist.no_jobs);
END IF;
htp.p('</td></tr>');
htp.p('</table>');
--table_heading(col_name ,col_order );
htp.p('<table align=center>');
htp.p('<tr align="center"><td>');
FOR i IN 1..l_total_pages LOOP
page_number(i) := i;
IF page_number(i) = l_total_pages THEN
htp.p('');
||'');
Web_Pkg_Elements.doc_val_small(page_number(i)||'</A>');
ELSE
htp.p('');
|'||'');
Web_Pkg_Elements.doc_val_small(page_number(i)||' |'||'</A>');
END IF;
END LOOP;
htp.p('</td></tr>');
htp.p('</table>');
htp.p('<table align=center>');
FOR l_curline IN 1..l_scr_lines LOOP
display(1) := NVL(r(l_curline).job_title, '<br>');
display(2) := NVL(r(l_curline).company_name, '<br>');
display(3) := NVL(Cc_Pkg_Nls.date2char(r(l_curline).apply_date, App.date_format), '<br>');
IF MOD(l_curline, 2) = 0 THEN
Cc_Pkg_Elements.tr_even;
ELSE
Cc_Pkg_Elements.tr_odd;
END IF;
htp.p('<td>');
htp.p('');
Web_Pkg_Elements.doc_val(display(1)||'');
htp.p('</td>');
htp.p('<td>');
Web_Pkg_Elements.doc_val(display(2));
htp.p('</td>');
htp.p(' <td>');
Web_Pkg_Elements.doc_val(display(3));
htp.p(' </td>');
htp.p('</tr>');
END LOOP;
htp.p('</TABLE>');
htp.p('<TABLE width="88%" BORDER="0" CELLPADDING="0" CELLSPACING="0"
align="center">');
htp.p('<tr valign=bottom>');
htp.p('<TD colspan=2 align=right>');
IF l_my_page_no > 1 THEN
htp.p('<P>'||'<IMG SRC="'||App.image||'prev.gif" ALT="'
||Txt_Proc_My_Joblist.prev
||'"' ||' HEIGHT=20 BORDER=0 ALIGN=bottom '
||'hspace=2>');
END IF;
IF l_my_page_no < CEIL (l_total_rec/l_lines) THEN
htp.p(' <a href="'||
web_pkg_elements.link$$(App.gateway||'8.my_application_list?'
||'pi_sort_col='||Web_Pkg_Elements.replace_in_url(pi_sort_col)
||'&pi_msg=&pi_page_no='||TO_CHAR(l_my_page_no + 1)
||">'||'<IMG SRC="'||App.image||'next.gif" ALT="'
||Txt_Proc_My_Joblist.NEXT
||'"' ||' HEIGHT=20 BORDER=0 ALIGN=bottom '
||'hspace=2></a>');
END IF;
htp.p('</TD>');
htp.p('</TR>');
htp.p(' </TABLE>');
htp.formHidden('pi_sort_col', pi_sort_col);
htp.formHidden('pi_page_no', pi_page_no);
htp.p('</FORM>');
END my_application_list;
END ; --cc_pkg_application_list -
PL/SQL column names in cursor variable
Hi,
I try to put all column names of a table in a cursor variable?? without the values, just the column names.
Can somebody help me, because I really don't know how to do this.
Thanks,
MoniHi Jes,
my table looks like this: T1
columnNames: id | col1 | col2 | col3 | col4 | col5
Values: a | b | c| d| e| f
the number of the columns depend on a how many rows in another table (T2) are entered. If a new row is entered in T2, I have to add a column in table T1.
and then I have to look what is the new row, compare it with all my existing columnnames in T1 and add the right one.
my vector should look like this:
c1:
id
col1
col2
col3
col4
col5
I hope you know what I mean, it is not very easy to describe!
Thanks for helping me!
Moni -
Can I use bind variable instaed of writing static COLUMN Name
Hi , I am having a table containing id and column names, the data is stored against that id in other tables. Now I wish to update data into another table so that it goes into apppropriate column without using decode function.
I am trying to do this:
EXECUTE IMMEDIATE 'update TEST set :1 = :2
where PROJECT_ID= :3 and UNIQUE_ID= :4' using P_DEST_COLUMN, P_TEXT_VALUE, P_PROJ_ID, P_TASK_UID;
the values P_DEST_COLUMN, P_TEXT_VALUE, P_PROJ_ID, P_TASK_UID are populated using a cursor in PL/SQl
Is this statement valid? If not can you tell me how to do it as I am getting some error I am unable to comprehend.
thanks
RishabhColumn names cannot be substituted at run-time as bind variables. If you need to specify the column name at run-time, you'd need to construct a new string and execute that string dynamically, i.e.
EXECUTE IMMEDIATE 'UPDATE test SET ' || p_dest_column || ' = :1 ' || ...From a data model standpoint, storing column names as data elements in another table is generally a rather poor idea. It's likely to make ad-hoc reporting nearly impossible and to cause a lot more parsing than would otherwise be required.
Justin -
Need help on getting the column names of Tabletype
I have a table Mapping with the following values: This Mapping table contains the table names (in Tabname) and the column names(colname) of various tables and values(ValuesTobeFilled) for the columns.
I have to insert into the tables present in the Tabname field with the values present in the ValuesTobeFilled in the columns present in the Colname field.
Note: The Mapping table need not contain all the columns of the base table. The columns that are not present can be filled with null. And this mapping table is not fixed i.e. rows can be inserted/deleted frequently.
Sample values in mapping table:
Tabname Colname ValuesTobeFilled
sample_items Eno Corresponding Expression to get the values from XML input
sample_items Ename Corresponding Expression to get the values from XML input
XXX YYY Corresponding Expression to get the values from XML input
Before filling in the actual tables, I have to store the entire data temporarily and I have used a tabletype declared as follows:
TYPE T_sample_items IS TABLE OF sample_items%ROWTYPE INDEX BY BINARY_INTEGER;
l_sample_items T_sample_items;
Where the table sample_items have the following columns:
• Eno
• Ename
• Eaddress
• Eemail
So, the tabletype should be filled as:
Eno Ename Eaddress EEmail
1 XXX - -
I have declared a cursor to select the values from mapping table and I need to fill in the ValuesTobeFilled values to the corresponding table.
CURSOR c_xpath (c_tname mapping.TABNAME%type)
IS
select * from mapping where tabname = c_tname;
CURSOR c_tables
IS
SELECT DISTINCT TABNAME FROM mapping;
FOR crsr IN c_tables
LOOP
p_tname := CRSR.TABNAME;
FOR csr IN c_xpath(p_tname)
LOOP
IF l_xml_doc.EXISTSNODE(CSR.XPATH_EXP) = 1
THEN
l_node_value := l_xml_doc.extract(CSR.XPATH_EXP).getStringVal(); -- This is the value to be stored in the corresponding column
ELSE
l_node_value := NULL;
END IF;
IF CSR.COLUMN_NAME = ‘eno’
THEN
l_sample_items(1).eno := l_node_value;
ELSIF CSR.COLUMN_NAME = ‘ename’
THEN
l_sample_items(1).name := l_node_value;
END IF;
END LOOP;
END LOOP;
And I need to eliminate hard coding while comparing the column names (in the following piece of code) as the Mapping table values are subject to insertion/deletion:
IF CSR.COLUMN_NAME = ‘eno’
THEN
l_sample_items(1).eno := l_node_value;
ELSIF CSR.COLUMN_NAME = ‘ename’
THEN
l_sample_items(1).ename := l_node_value;
END IF;
I need to insert the values directly into the tabletype without this hardcoding. Please suggest me ways to compare the mapping table values with the field (column) names of the tabletype. If it is not possible using tabletype, please suggest any other ways of fixing the problem.
Many thanks,
GopiI take it this isn't going to be a serious production system at the end of the day?
Storing metadata in tables for extraction and insertion of data is just wrong in so many ways. It smells heavily of Entity Attribute Value modelling, which is the most wrong way to use a relational database and is known to have major performance implications and be liable to bugs and issues. The idea that EAV modelling allows for 'generic' databases where new data items can be added flexibly later on without having to change code is usually justified with an excuse of "it means we don't have to update all our tables when we want a new column" which is easily countered with "if you're adding a single column a good relational design wouldn't require you to add it to more than one table anyway in most cases".
Just what exactly are you trying to do and why? There has to be a better way. -
How to use the column names generated from Dynamic SQL
Hi,
I have a problem with Dynamic SQL.
I have written an SQL which will dynamically generate the Select statement with from and where clause in it.
But that select statement when executed will get me hundreds of rows and i want to insert each row separately into one more table.
For that i have used a ref cursor to open and insert the table.
In the select list the column names will also be as follows: COLUMN1, COLUMN2, COLUMN3,....COLUMNn
Please find below the sample code:
TYPE ref_csr IS REF CURSOR;
insert_csr ref_csr;
v_select VARCHAR2 (4000) := NULL;
v_table VARCHAR2 (4000) := NULL;
v_where VARCHAR2 (4000) := NULL;
v_ins_tab VARCHAR2 (4000) := NULL;
v_insert VARCHAR2 (4000) := NULL;
v_ins_query VARCHAR2 (4000) := NULL;
OPEN insert_csr FOR CASE
WHEN v_where IS NOT NULL
THEN 'SELECT '
|| v_select
|| ' FROM '
|| v_table
|| v_where
|| ';'
ELSE 'SELECT ' || v_select || ' FROM ' || v_table || ';'
END;
LOOP
v_ins_query :=
'INSERT INTO '
|| v_ins_tab
|| '('
|| v_insert
|| ') VALUES ('
|| How to fetch the column names here
|| ');';
EXECUTE IMMEDIATE v_ins_query;
END LOOP;
Please help me out with the above problem.
Edited by: kumar0828 on Feb 7, 2013 10:40 PM
Edited by: kumar0828 on Feb 7, 2013 10:42 PM>
I Built the statement as required but i need the column list because the first column value of each row should be inserted into one more table.
So i was asking how to fetch the column list in a ref cursor so that value can be inserted in one more table.
>
Then add a RETURNING INTO clause to the query to have Oracle return the first column values into a collection.
See the PL/SQL Language doc
http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/returninginto_clause.htm#sthref2307 -
Re: Column Name as Parameter in Oracle Procedure
Hi,
I've successfully compiled the following procedure:
CREATE OR REPLACE PROCEDURE CREATE_MEASURES_IND_RPT(
pSTART_DT IN date
, pEND_DT IN date
, PGEO_DIMENSION_COLUMN IN VARCHAR2
AUTHID CURRENT_USER IS
BEGIN
DECLARE
START_DT Date := pSTART_DT;
END_DT Date := pEND_DT;
text_ip_adjusted varchar2(10000):='
select
replace(fiscal_yr,''/'') as fiscal_year,
NVL(f_quarter(is_date(disdate,''yyyymmdd'')),''Year'') AS TIME_PERIOD_TYPE,
NVL('||PGEO_DIMENSION_COLUMN||',''Province'') as geo_desc
from data_table A,
postal_code_table B
where POSTCODE = B.POSTALCODE
AND (is_date(disdate,''yyyymmdd'') >= :1 and is_date(disdate,''yyyymmdd'') < :2)
GROUP BY
replace(fiscal_yr,''/''),
ROLLUP(f_quarter(is_date(disdate,''yyyymmdd''))),
ROLLUP('||PGEO_DIMENSION_COLUMN||');
begin
EXECUTE IMMEDIATE text_ip_adjusted using START_DT,END_DT; COMMIT;
END;
END CREATE_MEASURES_IND_RPT;
/When I try and execute the procedure, I get the following error:
ORA-00936: missing expression
ORA-06512: at "CREATE_MEASURES_IND_RPT", line 36
ORA-06512: at line 1The data table has date strings which need to be converted to dates using an "IS_DATE" function I've created which is while you'll see the is_date function used. The procedure works fine when I don't include the PGEO_DIMENSION_COLUMN as a parameter so I suspect that I haven't reference the name of the column properly. Essentially, I need my procedure to be able to specify a Column Name in the Postal Code table to use as a group by field.
Any help would be appreciated.
Thanks,
EdHi,
spalato76 wrote:
Hi,
I've successfully compiled the following procedure:
CREATE OR REPLACE PROCEDURE CREATE_MEASURES_IND_RPT(
pSTART_DT IN date
, pEND_DT IN date
, PGEO_DIMENSION_COLUMN IN VARCHAR2
AUTHID CURRENT_USER IS
BEGIN
DECLARE
START_DT Date := pSTART_DT;
END_DT Date := pEND_DT;
text_ip_adjusted varchar2(10000):='
select
replace(fiscal_yr,''/'') as fiscal_year,
NVL(f_quarter(is_date(disdate,''yyyymmdd'')),''Year'') AS TIME_PERIOD_TYPE,
NVL('||PGEO_DIMENSION_COLUMN||',''Province'') as geo_desc
from data_table A,
postal_code_table B
where POSTCODE = B.POSTALCODE
AND (is_date(disdate,''yyyymmdd'') >= :1 and is_date(disdate,''yyyymmdd'') < :2)
GROUP BY
replace(fiscal_yr,''/''),
ROLLUP(f_quarter(is_date(disdate,''yyyymmdd''))),
ROLLUP('||PGEO_DIMENSION_COLUMN||');
begin
EXECUTE IMMEDIATE text_ip_adjusted using START_DT,END_DT; COMMIT;
END;
END CREATE_MEASURES_IND_RPT;
/When I try and execute the procedure, I get the following error:
ORA-00936: missing expression
ORA-06512: at "CREATE_MEASURES_IND_RPT", line 36
ORA-06512: at line 1The data table has date strings which need to be converted to dates using an "IS_DATE" function I've created which is while you'll see the is_date function used. The procedure works fine when I don't include the PGEO_DIMENSION_COLUMN as a parameter so I suspect that I haven't reference the name of the column properly. Essentially, I need my procedure to be able to specify a Column Name in the Postal Code table to use as a group by field.
Any help would be appreciated.
Thanks,
EdIt l;ooks like you're missing a single-quote at the very end of the expression being assigned to text_ip_adjusted.
... ROLLUP(' || PGEO_DIMENSION_COLUMN || ')';How will you handle the output from that dynamic query? Maybe you should be opening a cursor. -
Hi everyone, again landed up with a problem.
After trying a lot to do it myself, finally decided to post here..
I have created a form in form builder 6i, in which on clicking a button the data gets exported to excel sheet.
It is working fine with a single table. The problem now is that i am unable to do the same with 2 tables.
Because both the tables have same number of columns & column names.
Below are 2 tables with column names:
Table-1 (MONTHLY_PART_1)
Table-2 (MONTHLY_PART_2)
SL_NO
SL_NO
COMP
COMP
DUE_DATE
DUE_DATE
U-1
U-1
U-2
U-2
U-4
U-4
U-20
U-20
U-25
U-25
Since both the tables have same column names, I'm getting the following error :
Error 402 at line 103, column 4
alias required in SELECT list of cursor to avoid duplicate column names.
So How can i export the data to excel which has 2 tables with same number of columns & column names?
Should i paste the code? Should i post this query in 'SQL and PL/SQL' Forum?
Help me with this please.
Thank You.You'll have to *alias* your columns, not prefix it with the table names:
$[CHE_TEST@asterix1_impl] r
1 declare
2 cursor cData is
3 with data as (
4 select 1 id, 'test1' val1, 'a' val2 from dual
5 union all
6 select 1 id, '1test' val1, 'b' val2 from dual
7 union all
8 select 2 id, 'test2' val1, 'a' val2 from dual
9 union all
10 select 2 id, '2test' val1, 'b' val2 from dual
11 )
12 select a.id, b.id, a.val1, b.val1, a.val2, b.val2
13 from data a, data b
14 where a.id = b.id
15 and a.val2 = 'a'
16 and b.val2 = 'b';
17 begin
18 for rData in cData loop
19 null;
20 end loop;
21* end;
for rData in cData loop
ERROR at line 18:
ORA-06550: line 18, column 3:
PLS-00402: alias required in SELECT list of cursor to avoid duplicate column names
ORA-06550: line 18, column 3:
PL/SQL: Statement ignored
$[CHE_TEST@asterix1_impl] r
1 declare
2 cursor cData is
3 with data as (
4 select 1 id, 'test1' val1, 'a' val2 from dual
5 union all
6 select 1 id, '1test' val1, 'b' val2 from dual
7 union all
8 select 2 id, 'test2' val1, 'a' val2 from dual
9 union all
10 select 2 id, '2test' val1, 'b' val2 from dual
11 )
12 select a.id a_id, b.id b_id, a.val1 a_val1, b.val1 b_val1, a.val2 a_val2, b.val2 b_val2
13 from data a, data b
14 where a.id = b.id
15 and a.val2 = 'a'
16 and b.val2 = 'b';
17 begin
18 for rData in cData loop
19 null;
20 end loop;
21* end;
PL/SQL procedure successfully completed.
cheers
Maybe you are looking for
-
How to reset my macbook back to factory settings with no install disk
So I purchased a 2009 White 2.26GHZ macbook on ebay. It came with just the macbook and charger, no disc. And when I opened it to start it up, it was the "new user" screen asking for my Apple ID, create admin ID, wifi network setup, and such. When
-
I followed the directions provided by Apple personnel to help resolve this issue: http://support.apple.com/kb/TS5376. The resulting errors include; Runtime Error! Program C:\Program Files (x86)\iTunes\iTunes.exe R6034 An application has made an attem
-
I am now using a 500 GB Time Capsule ("TC") with my iMac and intend to buy a new TC (1 TB) to replace the existing one. How can I connect the old TC with the new one and use it as a network drive. Can I connect the 2 TCs using Ethernet or USB. I use
-
[SOLVED] Confused about Mobility Radeon HD 3200
I've always found hard to find good information about this card - some sources, even, contradict themselves. All what I know is that it is an integrated graphics card and that it features the RS780M chipset. These are some tips I've got from the syst
-
I would love to put a progress indicator on every slide that states the % of the total number of slides that have been visited. To do that I need a variable that states the number of slides visited (so not the number of THE slide that is being visite