Variable in the Cursor definition?
Shall we provide a variable in the cursor definition.? Like this,
CREATE OR REPLACE PROCEDURE PRC_PROCEURE1 (v_table in varchar2) IS
CURSOR C1 IS select COL1,COL2,COL3 from V_TABLE
where ......
order by 1 asc
Getting the error :table or view does not exists. Please help
You can only bind values into your queries, not object names, so NO, you can't use a variable as a table name like that.
The only way to do that would be to write dynamic SQL, but that should raise the question as to why you need dynamic table names? Do you not know the table name at design time? Why not?
Similar Messages
-
Getting error which passing a variable to the cursor
hi all,
i am passing pl/sql table value into the sql cursor
DECLARE
CURSOR cr(i_oList IN tList) IS
SELECT SOMETHING
FROM SOMETABLE
WHERE SOMECOL IN (SELECT COLUMN_VALUE FROM TABLE(CAST(i_oList AS tList));but i am getting following error :invalid variable declaration 'tList' must be type or subtype.
please help meHI,
i changed my code to
DECLARE
CURSOR cr(i_oList tList) IS
SELECT SOMETHING
FROM SOMETABLE
WHERE SOMECOL IN (SELECT COLUMN_VALUE FROM TABLE(tList));
still getting the same error as i mentioned before
"invalid variable declaration: object tlist must be type or subtype -
How to validate similar columns fetched by the cursor
Hi,
I have one table which has columns like COMP_PART_NUMBER_1 , COMP_PART_NUMBER_2 up to COMP_PART_NUMBER_50
Need to validate columns as shown below,I want to know how to make create dynamic script for the below validation so that there is no need to add same logic for 50 times.
IF rec_SCR_assy.COMP_PART_NUMBER_1 IS NOT NULL THEN
IF LENGTH(rec_SCR_assy.COMP_PART_NUMBER_1) > 8 THEN
v_error_description := NVL(v_error_description,'') || 'The Component 1 Part Number length should not be greater than 8| ';
ELSE
v_upd_script := ' COMP_PART_NUMBER_1 = ''' || rec_SCR_assy.COMP_PART_NUMBER_1 || '''';
END IF;
END IF;
I have tried to create pl sql block as :-
FOR vcnt IN 1..50
LOOP
VFIELD_COMP_PART := 'COMP_PART_NUMBER_' || VCNT;
v_exec_query:=' begin
IF rec_SCR_assy.'||VFIELD_COMP_PART ||' IS NOT NULL THEN
IF LENGTH(rec_SCR_assy.'||VFIELD_COMP_PART||') > 8 THEN
:v_error_description := NVL(:v_error_description,'''') || ''The Component 1 Part Number length should not be greater than 8| '';
ELSE
:v_upd_script := '' rec_SCR_assy.'||VFIELD_COMP_PART||' = '''''' ||rec_SCR_assy.'||VFIELD_COMP_PART ||'||'''''''';
end if;
END IF; end;';
execute immediate V_EXEC_QUERY using v_error_description,v_upd_script;
This code is giving an error as it is not possible to create a bind variable to the cursor in dynamic script.
Please help me to find the solution for it.Thanks in advance.Try like this ...
DECLARE
v_exec_query VARCHAR2 (4000);
BEGIN
FOR i IN (SELECT column_name
FROM all_tab_cols
WHERE table_name = 'EMP')
LOOP
v_exec_query :=
' begin
IF rec_SCR_assy.'
|| i.column_name
|| ' IS NOT NULL THEN
IF LENGTH(rec_SCR_assy.'
|| i.column_name
|| ') > 8 THEN
:v_error_description := NVL(:v_error_description,'''') || ''The Component 1 Part Number length should not be greater than 8| '';
ELSE
:v_upd_script := '' rec_SCR_assy.'
|| i.column_name
|| ' = '''''' ||rec_SCR_assy.'
|| i.column_name
|| '||'''''''';
end if;
END IF; end;';
DBMS_OUTPUT.put_line (v_exec_query);
END LOOP;
END;
--Output
BEGIN
IF rec_scr_assy.emp_info IS NOT NULL
THEN
IF LENGTH (rec_scr_assy.emp_info) > 8
THEN
:v_error_description :=
NVL (:v_error_description, '')
|| 'The Component 1 Part Number length should not be greater than 8| ';
ELSE
:v_upd_script :=
' rec_SCR_assy.EMP_INFO = ''' || rec_scr_assy.emp_info || '''';
END IF;
END IF;
END;
BEGIN
IF rec_scr_assy.deptno IS NOT NULL
THEN
IF LENGTH (rec_scr_assy.deptno) > 8
THEN
:v_error_description :=
NVL (:v_error_description, '')
|| 'The Component 1 Part Number length should not be greater than 8| ';
ELSE
:v_upd_script :=
' rec_SCR_assy.DEPTNO = ''' || rec_scr_assy.deptno || '''';
END IF;
END IF;
END;
BEGIN
IF rec_scr_assy.comm IS NOT NULL
THEN
IF LENGTH (rec_scr_assy.comm) > 8
THEN
:v_error_description :=
NVL (:v_error_description, '')
|| 'The Component 1 Part Number length should not be greater than 8| ';
ELSE
:v_upd_script :=
' rec_SCR_assy.COMM = ''' || rec_scr_assy.comm || '''';
END IF;
END IF;
END;
BEGIN
IF rec_scr_assy.sal IS NOT NULL
THEN
IF LENGTH (rec_scr_assy.sal) > 8
THEN
:v_error_description :=
NVL (:v_error_description, '')
|| 'The Component 1 Part Number length should not be greater than 8| ';
ELSE
:v_upd_script :=
' rec_SCR_assy.SAL = ''' || rec_scr_assy.sal || '''';
END IF;
END IF;
END;
BEGIN
IF rec_scr_assy.hiredate IS NOT NULL
THEN
IF LENGTH (rec_scr_assy.hiredate) > 8
THEN
:v_error_description :=
NVL (:v_error_description, '')
|| 'The Component 1 Part Number length should not be greater than 8| ';
ELSE
:v_upd_script :=
' rec_SCR_assy.HIREDATE = ''' || rec_scr_assy.hiredate || '''';
END IF;
END IF;
END;
BEGIN
IF rec_scr_assy.mgr IS NOT NULL
THEN
IF LENGTH (rec_scr_assy.mgr) > 8
THEN
:v_error_description :=
NVL (:v_error_description, '')
|| 'The Component 1 Part Number length should not be greater than 8| ';
ELSE
:v_upd_script :=
' rec_SCR_assy.MGR = ''' || rec_scr_assy.mgr || '''';
END IF;
END IF;
END;
BEGIN
IF rec_scr_assy.job IS NOT NULL
THEN
IF LENGTH (rec_scr_assy.job) > 8
THEN
:v_error_description :=
NVL (:v_error_description, '')
|| 'The Component 1 Part Number length should not be greater than 8| ';
ELSE
:v_upd_script :=
' rec_SCR_assy.JOB = ''' || rec_scr_assy.job || '''';
END IF;
END IF;
END;
BEGIN
IF rec_scr_assy.emp_no IS NOT NULL
THEN
IF LENGTH (rec_scr_assy.emp_no) > 8
THEN
:v_error_description :=
NVL (:v_error_description, '')
|| 'The Component 1 Part Number length should not be greater than 8| ';
ELSE
:v_upd_script :=
' rec_SCR_assy.EMP_NO = ''' || rec_scr_assy.emp_no || '''';
END IF;
END IF;
END;
BEGIN
IF rec_scr_assy.sys_nc00009$ IS NOT NULL
THEN
IF LENGTH (rec_scr_assy.sys_nc00009$) > 8
THEN
:v_error_description :=
NVL (:v_error_description, '')
|| 'The Component 1 Part Number length should not be greater than 8| ';
ELSE
:v_upd_script :=
' rec_SCR_assy.SYS_NC00009$ = '''
|| rec_scr_assy.sys_nc00009$
|| '''';
END IF;
END IF;
END;
BEGIN
IF rec_scr_assy.ename IS NOT NULL
THEN
IF LENGTH (rec_scr_assy.ename) > 8
THEN
:v_error_description :=
NVL (:v_error_description, '')
|| 'The Component 1 Part Number length should not be greater than 8| ';
ELSE
:v_upd_script :=
' rec_SCR_assy.ENAME = ''' || rec_scr_assy.ename || '''';
END IF;
END IF;
END;Regards,
Friend -
Query within the Cursor loop is very slow
Hi ,
I have a stored procedure which has Select/Insert operation which is looped within the cursor. The Select uses variables from the cursor, and inserts the data into the table.
My problem is the peformance. The stored procedure executes in 2 mins if I hard code the where clause values in the Select. Instead if I use the variables obtained from the cursor, the query takes so long (more than 20 mins) to insert the same no of records into the table.
Below is the snippet of my code
create procedure sample is
declare
v_acct_month number(2);
v_sp_name varchar2(30);
cursor v_cur is Select distinct Acct_Month,salesperson_name from period;
begin
open v_cur;
loop
fetch v_cur into v_acct_month, v_sp_name;
exit when v_cur%notfound;
Insert into T1
Select * from T2,T3.. Where T2.month=v_acct_month,t3.sp_name=v_sp_name;
end loop;
End;
The query is not using the optimizer when the variables are used.The optimizer is used when I hard code the values in the select.
Please give me suggestions to make this query faster..
Thanks,
Arun
Edited by: [email protected] on Mar 28, 2009 10:18 AMHi,
Whenever you write code, format it to show the scope of BEGIN, LOOP, IF statements, and so on.
Type these 6 characters
{code}
(small letters only, inside curly brackets) before and after the formatted code, to preserve spacing on this site.
You've discovered why the tecnique you're using is called "slow-by-slow" processing.
You don't need a cursor. You may not even need PL/SQL.
Just write an INSERT statement that reference the table from the cursor and the tables from your current INSERT statement.
Here's one way:
INSERT
INTO t1 (columns)
SELECT columns
FROM t2
, t3
WHERE ...
AND (t2.month, t3.sp_name) IN (
SELECT DISTINCT
acct_month
, salesperson_name
FROM period
);Depending on the details of your case, there may be a better way, such as a 3-way join. -
I'm working with BI Publisher 10g, building an rtf template that would display a table and a graph by iterating on one of the xml tags from the input file.
I got the table working using am xslt variable set when the xml tag associated value changes (DATAGROUPID).
<?for-each:(/DATA/SITE/SITE_DATA)?> <?sort:DATAGROUPID;'ascending';data-type='number'?>
<?xdoxslt:set_variable($_XDOCTX,'SITE',DATAGROUPID)?>
<?for-each:(/DATA//DIMS/LOCALES[LOCALE = 'en']/TEXT)?><?sort:DIMNAME;'ascending';data-type='text'?>
<?xdoxslt:set_variable($_XDOCTX,'DIMID',DIMID)?>
<?round(/DATA/SITE/SITE_DATA[DATAGROUPID = xdoxslt:get_variable($_XDOCTX,'SITE')]/YEAR[SURVEYYEAR = 2012]/DIM[DIMID = xdoxslt:get_variable($_XDOCTX,'DIMID')]/ITEM[ITEMID = 0]/PFAV)?>
<?end for-each?>
chart:
<Graph seriesEffect="SE_AUTO_GRADIENT" graphType="BAR_VERT_PERCENT" autoLayout="AL_AS_NEEDED">
<LegendArea visible="true" automaticPlacement="AP_NEVER" position="LAP_BOTTOM"/>
<SeriesItems>
<Series id="0" color="#FF0000"/>
<Series id="1" color="#FFFF00"/>
<Series id="2" color="#00FF00"/>
</SeriesItems>
<MarkerText visible="true" markerTextPlace="MTP_CENTER">
<GraphFont name="Arial" size="20" bold="true" italic="false" underline="false"/>
<Y1ViewFormat>
<ViewFormat decimalDigit="0" decimalSeparatorUsed="true" decimalDigitUsed="true"/>
</Y1ViewFormat>
</MarkerText>
<LegendText>
<GraphFont name="Arial" size="20" bold="false" italic="false" underline="false"/>
</LegendText>
<Y1TickLabel>
<GraphFont name="Arial" size="12" bold="false" italic="false" underline="false"/>
</Y1TickLabel>
<O1TickLabel wordWrapEnabled="false" tickLabelStaggered="false">
<GraphFont name="Arial" size="20" bold="true" italic="false" underline="false"/>
</O1TickLabel>
<LocalGridData colCount="{count(xdoxslt:group(/DATA/SITE/SITE_DATA/YEAR[SURVEYYEAR = 2012]/DIM, 'DIMID'))}" rowCount="3">
<RowLabels>
<Label>Unfavorable </Label>
<Label>Neutral</Label>
<Label>Favorable</Label>
</RowLabels>
<ColLabels>
<xsl:for-each select="/DATA/DIMS/LOCALES[LOCALE = 'en']/TEXT">
<xsl:sort select="DIMNAME"/>
<Label>
<xsl:value-of select="DIMNAME"/>
</Label>
</xsl:for-each>
</ColLabels>
<DataValues>
<RowData>
<xsl:for-each select="/DATA/DIMS/LOCALES[LOCALE = 'en']/TEXT">
<xsl:sort select="DIMNAME"/>
<Cell>
<xsl:variable name="DIMID" select="DIMID"/>
<xsl:value-of select="/DATA/SITE/SITE_DATA/YEAR[SURVEYYEAR = 2012]/DIM[DIMID = $DIMID]/ITEM[ITEMID = 0 and PUNFAV != 0]/PUNFAV"/>
</Cell>
</xsl:for-each>
</RowData>
<RowData>
<xsl:for-each select="/DATA/DIMS/LOCALES[LOCALE = 'en']/TEXT">
<xsl:sort select="DIMNAME"/>
<Cell>
<xsl:variable name="DIMID" select="DIMID"/>
<xsl:value-of select="/DATA/SITE/SITE_DATA/YEAR[SURVEYYEAR = 2012]/DIM[DIMID = $DIMID]/ITEM[ITEMID = 0 and PNEU != 0]/PNEU"/>
</Cell>
</xsl:for-each>
</RowData>
<RowData>
<xsl:for-each select="/DATA/DIMS/LOCALES[LOCALE = 'en']/TEXT">
<xsl:sort select="DIMNAME"/>
<Cell>
<xsl:variable name="DIMID" select="DIMID"/>
<xsl:value-of select="/DATA/SITE/SITE_DATA/YEAR[SURVEYYEAR = 2012]/DIM[DIMID = $DIMID]/ITEM[ITEMID = 0 and PFAV !=0]/PFAV"/>
</Cell>
</xsl:for-each>
</RowData>
</DataValues>
</LocalGridData>
</Graph>
<?end for-each?>
So, on the table this line gets the correct variable from the input file:
<?round(/DATA/SITE/SITE_DATA[DATAGROUPID = xdoxslt:get_variable($_XDOCTX,'SITE')]/YEAR[SURVEYYEAR = 2012]/DIM[DIMID = xdoxslt:get_variable($_XDOCTX,'DIMID')]/ITEM[ITEMID = 0]/PFAV)?>
How can I replicate that logic inside the table definition?
<xsl:value-of select="/DATA/SITE/SITE_DATA/YEAR[SURVEYYEAR = 2012]/DIM[DIMID = $DIMID]/ITEM[ITEMID = 0 and PFAV !=0]/PFAV"/>
Input data looks like this:
<DATA>
- <SITE>
- <SITE_DATA>
<DATAGROUPID>1032817</DATAGROUPID>
<DATAGROUPNAME>My Sales</DATAGROUPNAME>
- <YEAR>
<SURVEYYEAR>2012</SURVEYYEAR>
- <DIM>
<DIMID>1</DIMID>
- <ITEM>
<ITEMID>0</ITEMID>
<PFAV>88</PFAV>
<PNEU>13</PNEU>
<PUNFAV>0</PUNFAV>
- <ITEM>
<ITEMID>40</ITEMID>
<PFAV>100</PFAV>
<PNEU>0</PNEU>
<PUNFAV>0</PUNFAV>
</ITEM>
</DIM>
</YEAR>
</SITE_DATA>
- <SITE_DATA>
<DATAGROUPID>1032816</DATAGROUPID>
<DATAGROUPNAME>Your Sales</DATAGROUPNAME>
- <YEAR>
<SURVEYYEAR>2012</SURVEYYEAR>
- <DIM>
<DIMID>1</DIMID>
- <ITEM>
<ITEMID>0</ITEMID>
<PFAV>71</PFAV>
<PNEU>25</PNEU>
<PUNFAV>4</PUNFAV>
I can include a complete sample on request, I thought this would be enough to illustrate the issue.
I'll appreciate any help you can provide.I kept researching, I found some possible solution in this blog:
https://blogs.oracle.com/xmlpublisher/category/Oracle/Templates/RTF
so, I created a local SITE variable inside every cell to get the external SITE info:
<Cell>
<xsl:variable name="DIMID" select="DIMID"/>
<xsl:variable name="SITE" select="{xdoxslt:get_variable($_XDOCTX,'SITE')}"/>
<xsl:value-of select="/DATA/SITE/SITE_DATA[DATAGROUPID = $SITE]/YEAR[SURVEYYEAR = 2012]/DIM[DIMID = $DIMID]/ITEM[ITEMID = 0 and PUNFAV != 0]/PFAV"/>
</Cell>
but I get this error at run time:
oracle.xdo.parser.v2.XPathException: Error in expression: '{xdoxslt:get_variable($_XDOCTX,'SITE')}'.
at oracle.xdo.parser.v2.XSLProcessor.reportException(XSLProcessor.java:806)
at oracle.xdo.parser.v2.XSLProcessor.newXSLStylesheet(XSLProcessor.java:571)
... 14 more
What am I doing wrong? -
How to send a variable in the 'IN Clause' in a cursor?
Hi.
I am new to this forum.
My exact requirement is.. I need to select data with the help of a cursor and show it in the output. I have an input parameter which can be null or comma delimited value.
If I am passing this comma delimited value as a parameter to the cursor, its not giving me the right output.
Please help me.
Sample code that is failing is below:
CREATE OR REPLACE PROCEDURE show_output
IS
CURSOR ces_bpa_output_csr1(p_csv_filename varchar2)
IS
select customer_number,
customer_name,
transaction_number,
status_flag,
to_char(min(submit_date), 'MM/DD/YYYY HH24:MI:SS') min_submit_date,
to_char(max(submit_date), 'MM/DD/YYYY HH24:MI:SS') max_submit_date,
count(*) records
from CES_USAGE_DETAILS_TEMP
where filename IN p_csv_filename ---
group by customer_number,
customer_name,
transaction_number,
status_flag;
l_filename varchar2(100);
BEGIN
l_filename := '('||chr(39)||'CES_JAN_2008.txt'||chr(39)||','||chr(39)||'CES_FEB_2008.txt'||chr(39)||')'; ---- l_filename will contain ('CES_JAN_2008.txt','CES_FEB_2008.txt')
dbms_output.put_line(l_filename);
FOR ces_bpa_output_rec1 in ces_bpa_output_csr1(l_filename)
LOOP
dbms_output.put_line(ces_bpa_output_rec1.customer_number||' '||
ces_bpa_output_rec1.customer_name||' '||
ces_bpa_output_rec1.transaction_number||' '||
ces_bpa_output_rec1.status_flag||' '||
ces_bpa_output_rec1.min_submit_date||' '||
ces_bpa_output_rec1.max_submit_date||' '||
ces_bpa_output_rec1.records);
END LOOP;
END;Kindle check this ->
how to test a procedure that takes IN an array parameter?
Regards.
Satyaki De. -
How to make the cursor global if it has parameters that would be passed through calling environment
What I am trying to do is:
1. Pass two dates "p_start_date" and "p_end_date" to a procedure "calc_percnt". Based on these two dates the procedure creates a collection that has ticket info between the date range provided.
2. Iterate through this collection to find out the number of tickets that took less than 4 hrs (p_count_4), less than 8 hours (p_count_8), less than 12 hours(p_count_12) and less than 24 hours (24).
3. I want to move the logic of the above point 2 (also mentioned between dotted lines in the below mentioned code) to a function and call that function.
4. For the above point 3 I will have to create a function which will accept a collection variable something like this:
create or replace cal_perc (collection_var total_tckt_colcn) ....
I cannot do this because total_tckt_colcn needs to be declared
5. I cannot make the cursor and collection type as global by putting them in package specification because of the condition in cursor:
WHERE created_date >= p_start_date AND created_date < (p_end_date + interval '1' DAY)
it gives the error as "p_start_date" and "p_end_date" needs to be declared.
What is the best way to do this????
create or replace
PROCEDURE calc_percnt(
p_start_date IN N01.cc_ticket_info.LAST_CHANGED%type ,
p_end_date IN N01.cc_ticket_info.LAST_CHANGED%type ,
AS
v_start_date N01.cc_ticket_notes.LAST_UPDATED_STAMP%type;
v_end_date N01.cc_ticket_notes.LAST_UPDATED_STAMP%type;
CURSOR cur_total_tckt
IS
SELECT * from
WHERE created_date >= p_start_date AND created_date < (p_end_date + interval '1' DAY)
type total_tckt_colcn
IS
TABLE OF cur_total_tckt%rowtype;
total_tckt_col total_tckt_colcn;
total_coach_col total_tckt_colcn;
BEGIN
total_tckt_col := total_tckt_colcn ();
OPEN cur_total_tckt;
LOOP
FETCH cur_total_tckt bulk collect INTO total_tckt_col limit 100;
END LOOP;
EXIT
WHEN (cur_total_tckt%NOTFOUND);
END LOOP ;
CLOSE cur_total_tckt;
-- ---I want to move the following code in a function which finds the time required to close the ticket and increment the counter ------
FOR i IN total_tckt_col .first..total_tckt_col .last
LOOP
no_of_seconds := calc_time_diff(total_coach_col(i).created_date, total_coach_col(i).closed_date);
IF (no_of_seconds < 14400) THEN
p_count_4 := p_count_4 + 1;
p_count_8 := p_count_8 + 1;
p_count_12 := p_count_12 + 1;
p_count_24 := p_count_24 + 1;
ELSIF (no_of_seconds < 28800) THEN
p_count_8 := p_count_8 + 1;
p_count_12 := p_count_12 + 1;
p_count_24 := p_count_24 + 1;
ELSIF (no_of_seconds < 43200) THEN
p_count_12 := p_count_12 + 1;
p_count_24 := p_count_24 + 1;
ELSIF (no_of_seconds < 86400) THEN
p_count_24 := p_count_24 + 1;
END IF;
END LOOP;
END calc_percnt;I cannot add cursor definition to package because of the following condition:
WHERE created_date >= p_start_date AND created_date < (p_end_date + interval '1' DAY)
it gives me an error: "p_start_date" and "p_end_date" needs to be declared.
p_start_date and p_end_date are parameters that would be passed by the user.
Parameterized cursor to the rescue:
I have changed my cursor definition to:
create or replace
PACKAGE ES_REPORTS AS
CURSOR cur_total_tckt (p_start_date n01.cc_ticket_status_history.created_date%type, p_end_date n01.cc_ticket_status_history.created_date%type)
IS
SELECT t.ticket_id ticket_id , t.created_date created_date, t.created_by created_by, t.ticket_status ticket_status, t.last_changed last_changed, h.closed_date
FROM n01.cc_ticket_info t
inner join
(SELECT ticket_id , MAX(created_date) closed_date
FROM n01.cc_ticket_status_history
WHERE ticket_status = 'CLOSED' AND created_date >= p_start_date AND created_date < (p_end_date + interval '1' DAY)
GROUP BY ticket_id
) h
on (t.ticket_id = h.ticket_id)
WHERE (t. ticket_status = 'NOTIFIED' OR t.ticket_status = 'CLOSED') AND t.last_changed >= p_start_date AND t.last_changed < (p_end_date + interval '1' DAY);
END ES_REPORTS;
Not sure if it is good programing practice though? -
How to determine the cursor record count before the "open cursor"?
Is it possible to determine the record count of an explicit cursor without running a count()? Say, my cursor definition is something like this,
CURSOR cur_vehicle
IS
SELECT os.order_id, os.order_item, vs.part_id
vs.part_num,
vs.iso_num,
vs.model_yr
vs.dealer_cde,
vs.cust_cde,
px.plant_cd
FROM parts_source vs,
orders_source os,
plant_tbl_crossref px
wHERE os.order_id = vs.order_id
AND vs.part_id = os.part_id
AND vs.plant_cde = px.plant_cde
ORDER BY os.order_id;
I want to log the count of records returned by the above cursor prior to the first fetch, without running a count(1) for the query in cursor select.
I know adding " Count(1) over(order by null) " in the cursor SELECT will bring it. But that does not help me log the record count to some log file or table before opening the cursor for processing.
To conclude, my objective is to update the record count of cursor in some table before processingsarvan wrote:
Is it possible to determine the record count of an explicit cursor without running a count()?
..snipped..No. The only way to do it correctly is inside that select.
Each select is a consistent read. Which means that if this is done as 2 select statements, the 1st select can see a different version of the data than the 2nd select statement. does. So if you want a count and that to be consistent and on the same version of the data than the select, it has to be done as part of the select.
Also consider what a cursor is. It is not a result set of sorts that is created in memory upfront - with a convenient interface that tells you the size/number of rows of that result set.
A cursor is basically a program that reads database data as input and produce output. A fetch from a cursor is an instruction for this program to execute and output data.
There's no data set that is created by the cursor from which the count can be determined. The cursor program does have state variables - like +%RowCount+ that specifies how many rows the cursor has thus far output. And you need to run that cursor to the end (no more output) in order to determine the total number of rows output by the cursor. -
Dynamic cursor definition in PL/SQL
Is it possible to have dynamic cursor definition in PL/SQL. Like
using DBMS_SQL for dynamic SQL. If yes, how?Assuming I understand your question correctly, you can use a REF
CURSOR to which you associate a VARCHAR2 which is the query text:
DECLARE
TYPE t_cur IS REF CURSOR ; -- define t_cur as a type
c_cur t_cur ; -- define an actual variable of type t_cur
r_emp emp%ROWTYPE ; -- PL/SQL record to hold row
v_query VARCHAR2(2000) := 'SELECT * FROM emp' ; -- the query!
BEGIN
OPEN c_cur FOR v_query ; -- v_query could contain any valid query
FETCH c_cur INTO r_emp ; -- get first row from dataset
CLOSE c_cur ; -- remember to close the cursor! ;)
END ;
HTH -
Set the cursor busy steered by supanel vi
I let run a vi and there is a subpanel. Is there a way that I can set the cursor busy steered by the subpanel vi. I pass the reference of the mainvi over a global variable into subvi. Without success there is no error message but the busy cursor does not appear. Just setting the cursor in subvi creates a null window error. Is there a easy way to implement it. Or do I have to use user events in main vi called by suvi an then se it busy. Would be not so nice to understand it later.
kind regards retoI attach my test VI (LV 8.0). You can try it.
Attachments:
test sub.vi 17 KB
test.vi 22 KB
test global.vi 4 KB -
How to delete multiple variables from the variables list
Hello,
Iam using FrameMaker 9.0. Is there a way I can select multiple variables from the book and delete them together.
Thanks,
CP.NO in FM9. Take SQUIDDS TOOLBOX the free tool: 'Formats'
'Formats' is a very helpful tool for 'deleting' paragraph formats, character formats, cross reference formats, table formats, color definitions and variables.
You can delete unused one or all formats of selected. For paragraph and character you can also decide to 'add new one in catalog'.
-Georg -
How can I replace the cursor in the below query?
I have this below query which calls a stored procedure that takes only 1 item's attributes at a time. But because of performance problems we are
required to remove the cursor. How can I replace the below cursor logic with set operations or CTE? Please advice.
DECLARE db_cursor_ava CURSOR
FOR
SELECT t.[agent-id],
t.[start-date],
t.[end-date],
t.[monitor-days],
t.[monitor-start],
t.[monitor-end],
t.[timezone-offset]
FROM @tmpAgentPeriodTimeRange t
OPEN db_cursor_ava
FETCH NEXT FROM db_cursor_ava INTO @agentID_ava,
@stDateTime_ava,
@endDateTime_ava,
@monDays_ava,
@monSt_ava,
@monEnd_ava,
@offset_ava
WHILE @@FETCH_STATUS = 0
BEGIN
DELETE
FROM @tmpMonitorPeriod
DELETE
FROM @tmpFinalResult
SET @runID = 1
IF(@endDateTime_ava>DATEADD(MI,@offset_ava, GETUTCDATE()))
BEGIN
SET @endDateTime_ava=DATEADD(MI,@offset_ava, GETUTCDATE())
END
INSERT INTO @tmpMonitorPeriod
EXEC core.usp_GetMonitoringPeriod
@startDate = @stDateTime_ava,
@endDate = @endDateTime_ava,
@monitoringDays = @monDays_ava,
@monitoringStart = @monSt_ava,
@monitoringEnd = @monEnd_ava
SELECT @maxID = MAX(tm.id)
FROM @tmpMonitorPeriod tm
FETCH NEXT FROM db_cursor_ava INTO @agentID_ava,
@stDateTime_ava,
@endDateTime_ava,
@monDays_ava,
@monSt_ava,
@monEnd_ava,
@offset_ava
END
CLOSE db_cursor_ava
DEALLOCATE db_cursor_ava
mayooran99You've been down this path before - and the response is exactly the same.
how to replace cursor logic
And I'll suggest that you post the entire code - since you repeatedly delete 2 table variables but only populate one. The setting of @maxID also seems to have no purpose. And perhaps the issue here isn't the cursor but the general approach. Who knows
- but it appears you may have prematurely assumed that the cursor is the problem. -
Read only specific Columns into the cursor
Hey everybody,
I'm trying to make a cursor which takes only column 2 to n-2 (when n is the number of cloumns). The table size should be variable.
Is there any possibility to do that?
Like
CURSOR nodes IS SELECT * FROM nn_input WHERE column_id > 1 AND column_id < count(columns)-2;
Another possibility to solve the problem could be to read all cloumns in the cursor and then, in the for-loop, writing the 2nd to (n-2) value in table1 and the last two values in table2...
Anyone an idea? Thanks a lot!You need to use dynamic SQL and build up your query at run time. You could use something like the following to generate the list of columns...
CREATE TABLE test_columns
col1 number,
col2 number,
col3 number,
col4 number,
col5 number
SELECT LTRIM(MAX(SYS_CONNECT_BY_PATH(column_name,',')),',')
FROM user_tab_columns
START WITH column_id = &start_col_num
AND table_name = 'TEST_COLUMNS'
CONNECT BY column_id = PRIOR column_id +1
AND table_name = PRIOR table_name
AND level <= &end_col_num-&start_col_num+1;Using a start_col_num =2 and end_col_num=4 gives:
LTRIM(MAX(SYS_CONNECT_BY_PATH(COLUMN_NAME,',')),',')
COL2,COL3,COL4There are lots and lots of other options...
Greg -
Problem with variable in the woorkbook selection screen.
Hi All,
I have Problem with Variable in the selection screen. I have four variable in the report in this sequence
<b>Plant (optional), calendar month (mandatory), material (optional), Customer (mandatory). </b>
In Development system, I changed the query to fix the problem for a formula. saved and executed the query. In the selection screen appeared four variables and executed. after executing the query and I saved the work book also. I logged out of the Bex Analyzer. In the RSRT I generated the report by clicking the Generated Report push button. and again logged into the Bex analyzer and ran the work book, now in the selection screen, appeared three Variables only, I am missing the variable <b>Customer</b>.
The old report which is already in the Production system is working fine. What could be the mistake I did in the development system.
It is very urgent, I need to deliver this object as soon as possible.
Can I anybody help on the same.
Thanks in advance
NarendraYunus,
I did what you said. I removed the variable from characteristic restrictions, saved the query and executed the query, appeared three variables Plant, Calender month and material. executed and saved the work book. disconeted from Bex analyzer, in RSRT Generated Report and logged into Bex analyzer ran the work book for selection Plant, calender month and material and went into change query definition and added the variable for customer which was removed earlier and and ran the query for selections Plant, Calender monmth, Material and customer. saved the work book. disconnected from Bex analyzer and closed all excel sheets and work books. In RSRT Generated Report and again connected to Bex analyzer and ran the work book, now appeared only three variables again missed variable customer.
Yunus does any missed n the procedure what i did.
It is helped what Chris was answered.
Many Many Thaks for your time and replies.
Thaks in advance
Narendra -
How to position the cursor at the end of the text with EDIT_TEXT?
Hello, it wanted to ask to them if somebody could make work the module of function EDIT_TEXT so that it positions the cursor at the end of the text that is visualizing in the text editor. In the documentation it says that passing a ' X' to him in the field scrollend of the parameter Control is obtained that operation. Nevertheless, I did this and the cursor continues appearing at the beginning of the text that visualizes.
Somebody could help me please?
Regards,
Gabriel
PD: The code that I use is the following one:
FORM f_ingresar_comentarios.
DATA: l_action,
l_result LIKE itcer,
l_pedido LIKE thead-tdname,
li_coment_save LIKE i_comentarios OCCURS 0,
li_coment_aux LIKE i_comentarios OCCURS 0 WITH HEADER LINE,
l_lines TYPE i,
l_lines_save TYPE i,
l_lines_insert TYPE i,
l_index TYPE i,
l_index_aux TYPE i,
l_insert,
lwa_control LIKE itced.
CLEAR: l_action.
CLEAR i_comentarios.
REFRESH: i_comentarios,
li_coment_save,
li_coment_aux.
l_pedido = v_pedido.
Leemos el texto si es que existe
CALL FUNCTION 'READ_TEXT'
EXPORTING
client = sy-mandt
id = v_id_text
language = sy-langu
name = l_pedido
object = c_ekko
IMPORTING
header = wa_cabecera
TABLES
lines = i_comentarios "Lineas de texto leídas
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
IF sy-subrc <> 0.
Armamos la cabecera por primer comentario para el pedido
CLEAR wa_cabecera.
wa_cabecera-tdobject = c_ekko. "Objeto en tabla TTXID
wa_cabecera-tdname = v_pedido. "Nro de pedido
wa_cabecera-tdid = v_id_text. "ID en tabla TTXID
wa_cabecera-tdspras = sy-langu. "Lenguaje
wa_cabecera-tdlinesize = 70.
ENDIF.
Salva comentarios originales
li_coment_save[] = i_comentarios[].
lwa_control-scrollend = c_x. " c_x = 'X'
Abre el editor de texto
CALL FUNCTION 'EDIT_TEXT'
EXPORTING
header = wa_cabecera
save = space
control = lwa_control
IMPORTING
newheader = wa_cabecera
function = l_action
RESULT = l_result
TABLES
lines = i_comentarios
EXCEPTIONS
object = 1
id = 2
language = 3
name = 4
linesize = 5.
Si cambio los comentarios, actualiza comentarios
CASE l_action.
WHEN c_unchanged.
WHEN c_delete.
WHEN c_update OR
c_insert.
Obtiene cantidad de lineas de comentarios originales y modificados
DESCRIBE TABLE li_coment_save LINES l_lines_save.
DESCRIBE TABLE i_comentarios LINES l_lines.
Si se insertaron lineas...
IF l_lines > l_lines_save.
Calcula cantidad de lineas a insertar para luego calcular valor de
indice a partir del cual insertar los nuevos comentarios
l_lines_insert = l_lines - l_lines_save.
l_index = ( l_lines - l_lines_insert ) + 1.
Controla que al menos una de las lineas insertadas sea diferente de
blanco
l_index_aux = l_lines.
l_insert = c_n.
DO l_lines_insert TIMES.
READ TABLE i_comentarios INDEX l_index_aux.
IF sy-subrc = 0 AND
i_comentarios-tdline <> space.
l_insert = c_s.
EXIT.
ENDIF.
l_index_aux = l_index_aux - 1.
ENDDO.
IF l_insert = c_s.
Carga comentarios originales y agrega lineas insertadas
li_coment_aux[] = li_coment_save[].
APPEND LINES OF i_comentarios
FROM l_index
TO l_lines
TO li_coment_aux.
Setea variable para indicar actualizacion de comentarios.
v_comentario = 'S'.
Agrega usuario y fecha del comentario
CONCATENATE sy-uname
sy-datum
INTO li_coment_aux-tdline
SEPARATED BY space.
li_coment_aux-tdformat = '*'.
APPEND li_coment_aux.
Grabamos el texto
CALL FUNCTION 'SAVE_TEXT'
EXPORTING
client = sy-mandt
header = wa_cabecera
savemode_direct = c_x
IMPORTING
newheader = wa_cabecera
TABLES
lines = li_coment_aux
EXCEPTIONS
id = 1
language = 2
name = 3
object = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
ENDIF.
ENDCASE.
ENDFORM. " f_ingresar_comentarios
In addition, I made another program simpler that it uses the same functions and also have the same problem:
*& Report Y_GVA_TEXT *
REPORT y_gva_text .
DATA: wa_cabecera LIKE thead,
i_comentarios LIKE tline OCCURS 0 WITH HEADER LINE.
DATA: l_action,
v_comentario,
l_result LIKE itcer,
v_pedido LIKE thead-tdname VALUE '3',
l_pedido LIKE thead-tdname,
c_a05 LIKE thead-tdid VALUE 'A05',
c_ekko LIKE stxh-tdobject VALUE 'EKKO',
l_lines LIKE sy-tabix,
lwa_control LIKE itced.
CONSTANTS: c_x VALUE 'X',
update VALUE 'U', "Langtext verändert
insert VALUE 'I', "Langtext eingefügt
delete VALUE 'D', "Langtext gelöscht
modify VALUE 'M', "Kein Langtext, Inlinezeile veränd.
unchanged VALUE ' '.
CLEAR: l_action.
CLEAR i_comentarios.
REFRESH i_comentarios.
Leemos el texto si es que existe
CALL FUNCTION 'READ_TEXT'
EXPORTING
client = sy-mandt
id = c_a05
language = sy-langu
name = v_pedido
object = c_ekko
IMPORTING
header = wa_cabecera
TABLES
lines = i_comentarios "Lineas de texto leídas
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
Armamos las cabecera para mostrar los comentarios
CLEAR wa_cabecera.
wa_cabecera-tdobject = c_ekko. "Objeto en tabla TTXID
wa_cabecera-tdname = v_pedido. "Nro de pedido
wa_cabecera-tdid = c_a05. "ID en tabla TTXID
wa_cabecera-tdspras = sy-langu. "Lenguaje
wa_cabecera-tdlinesize = 70.
ENDIF.
lwa_control-noendlines = c_x.
lwa_control-scrollend = c_x.
Abre el editor de texto
CALL FUNCTION 'EDIT_TEXT'
EXPORTING
header = wa_cabecera
save = space
control = lwa_control
IMPORTING
newheader = wa_cabecera
function = l_action
RESULT = l_result
TABLES
lines = i_comentarios
EXCEPTIONS
object = 1
id = 2
language = 3
name = 4
linesize = 5.
Si cambio los comentarios, actualiza comentarios
CASE l_action.
WHEN unchanged.
WHEN delete.
WHEN update OR
insert.
Agrega usuario y fecha del comentario
CONCATENATE sy-uname
sy-datum
INTO i_comentarios-tdline
SEPARATED BY space.
i_comentarios-tdformat = '*'.
APPEND i_comentarios.
CALL FUNCTION 'SAVE_TEXT'
EXPORTING
header = wa_cabecera
IMPORTING
newheader = wa_cabecera
TABLES
lines = i_comentarios.
ENDCASE.Murugesh,
I believe that you have mis-read Gabriel's problem.
Gabriel,
The cursor is not positioning at the base of the editor as you have cited.
In order to get this functionality to work, you must set the LINE_EDITOR import paramter to 'X'.
data: hdr like THEAD.
data: l_itced like itced.
hdr-tdobject = 'VBBP'.
hdr-tdname = '4000029521000030'.
hdr-tdid = 'Z005'.
hdr-tdspras = 'E'.
hdr-TDLINESIZE = '100'.
hdr-TDTXTLINES = '3'.
l_itced-SCROLLEND = 'X'.
CALL FUNCTION 'EDIT_TEXT'
EXPORTING
DISPLAY = ' '
EDITOR_TITLE = ' '
HEADER = hdr
PAGE = ' '
WINDOW = ' '
SAVE = 'X'
LINE_EDITOR = 'X' " here !!!
CONTROL = l_itced
PROGRAM = ' '
LOCAL_CAT = ' '
IMPORTING
FUNCTION =
NEWHEADER =
RESULT =
TABLES
LINES = lines
EXCEPTIONS
ID = 1
LANGUAGE = 2
LINESIZE = 3
NAME = 4
OBJECT = 5
TEXTFORMAT = 6
COMMUNICATION = 7
OTHERS = 8
Don't forget those points !!
Maybe you are looking for
-
Using TEST mode in sender file channel to trigger jdbc receiver channel
Hi In order to call a jdbc receiver channel every 15 minutes I intended to use a file sender channel as a trigger where I set the Processing Mode to TEST. However, I would like to make multiple simultaneous different calls to the jdbc receiver channe
-
HELP! Can't see the System Preferences
I tried to launch the System Preference application and all I get is a white window, you can't see the actual icons. This also happens in the Preview as well as the Console application. I tried a clean reinstall of my OS but still doesn't work. I als
-
I used to be able to open a second tab to get to another web site without closing the first one...now I can see the second tab but when I click on it, nothing happens..
-
Hi, I want to Maintain MM ( GR Document ) number ranges for the fiscal year 2010 - 2011 . Can we do it ? Wats the procedure ? Regards Rajesh
-
How to run user enter value query and get result on Text item
Hi , I'm really newbie at JDeveloper and ADF , I want to run the query below , before with Forms i just adding :TEXT_NAME to get the entered users value , what I have to do now with ADF , really it's not clear question and I would appreciate any help