How to count values by using cursor
HI,
I want to check column is empty or filled. and i should use cursor not indipendent SQL query. I written my programe like this. but count(cursor.columnname) not taken how can i do this. please help me.
declare
cursor c_rec is select *from ppc_input_file;
begin
FOR c_rec IN c1 LOOP
dbms_output.put_line('@@@@' || c_rec.device_name);
IF COUNT(c_rec.ppc_method) THEN
dbms_output.put_line('hihihh');
ELSE
dbms_output.put_line('nononono');
END IF;
END LOOP;
venkat.
Hi,
Please go through the pl/sql docs carefully before you start writing codes.
Please follow the link and read first.
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261.pdf
declare
cursor c1 is select * from ppc_input_file;
This was wrongly written as cursor c_rec is select *from ppc_input_file;.
begin
FOR c_rec IN c1 LOOP
dbms_output.put_line('@@@@' || c_rec.device_name);
The following bold portion is unnecessary. If the count is zero the cursor for loop will not run. I am not sure of your requirement.
--IF COUNT(c_rec.ppc_method) THEN
--dbms_output.put_line('hihihh');
--ELSE
--dbms_output.put_line('nononono');
--END IF;
END LOOP;
end;
regards,
Dipankar.
Similar Messages
-
How to restrict values displayed using a select-options
Can someone please tell me how to restrict values displayed using a select-options.
Example- in my table I have 100 entries. However when the user will click on the required field- I want to be display only 25 options based on a given value of another field in the table.
Thanks,
Mahesh.get the screen value for the selectd field using the fm
DYNP_VALUES_READ.
for that value filter the internal table values and pass the table to f4 help of the field.
below code will help u
write the f4 help for the field.
At Selection Screen on value request *
F4 help for Corporate
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_CORP.
Get Corporates for selected division
PERFORM GET_CORP.
PERFORM F4HELP_CORP.
*& Form GET_CORP
Get the corporates for the selected division
There are no interface parameters to be passed to this routine
FORM GET_CORP .
Table for conglomerate
DATA:
LT_CONG LIKE STANDARD TABLE OF FS_CORP,
Fields of current screen
LFS_DYNPREAD TYPE DYNPREAD,
Table for current Screen fields
LT_DYNPREAD LIKE STANDARD TABLE OF LFS_DYNPREAD.
LFS_DYNPREAD-FIELDNAME = 'P_DIV'.
APPEND LFS_DYNPREAD TO LT_DYNPREAD.
Get selection screen value for division
CALL FUNCTION 'DYNP_VALUES_READ'
EXPORTING
DYNAME = SY-REPID
DYNUMB = SY-DYNNR
TABLES
DYNPFIELDS = LT_DYNPREAD
EXCEPTIONS
INVALID_ABAPWORKAREA = 1
INVALID_DYNPROFIELD = 2
INVALID_DYNPRONAME = 3
INVALID_DYNPRONUMMER = 4
INVALID_REQUEST = 5
NO_FIELDDESCRIPTION = 6
INVALID_PARAMETER = 7
UNDEFIND_ERROR = 8
DOUBLE_CONVERSION = 9
STEPL_NOT_FOUND = 10
OTHERS = 11.
IF SY-SUBRC EQ 0.
READ TABLE LT_DYNPREAD INTO LFS_DYNPREAD INDEX 1.
IF SY-SUBRC EQ 0.
P_DIV = LFS_DYNPREAD-FIELDVALUE.
ENDIF. " IF SY-SUBRC EQ 0
ENDIF. " IF SY-SUBRC EQ 0
REFRESH T_CORP.
Get the conglomerate for the selected division
SELECT KUNNR " Conglomerate
FROM KNVH
INTO TABLE LT_CONG
WHERE HITYP EQ C_HITYP
AND VKORG EQ C_VKORG
AND VTWEG EQ C_VTWEG
AND SPART EQ P_DIV
AND DATAB LE SY-DATUM
AND DATBI GE SY-DATUM
AND HKUNNR EQ SPACE.
IF SY-SUBRC EQ 0.
SORT LT_CONG BY KUNNR.
DELETE ADJACENT DUPLICATES FROM LT_CONG
COMPARING KUNNR.
Get the corporates for the selected conglomerates
SELECT KUNNR " Customer Number
FROM KNVH
INTO TABLE T_CORP
FOR ALL ENTRIES IN LT_CONG
WHERE HITYP EQ C_HITYP
AND VKORG EQ C_VKORG
AND VTWEG EQ C_VTWEG
AND SPART EQ P_DIV
AND DATAB LE SY-DATUM
AND DATBI GE SY-DATUM
AND HKUNNR EQ LT_CONG-KUNNR.
IF SY-SUBRC NE 0.
CLEAR: SSCRFIELDS.
MESSAGE I531(0U) WITH TEXT-005.
STOP.
ENDIF. " IF SY-SUBRC NE 0
ELSE.
CLEAR: SSCRFIELDS.
MESSAGE I531(0U) WITH TEXT-004.
STOP.
ENDIF. " IF SY-SUBRC EQ 0
ENDFORM. " GET_CORP
*& Form F4HELP_CORP
F4 help for corporate
There are no interface parameters to be passed to this routine
FORM F4HELP_CORP .
F4 help for corporate
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
RETFIELD = 'KUNNR'
DYNPPROG = 'Z_EXCESS_USAGE'
DYNPNR = '1000'
DYNPROFIELD = 'P_CORP'
VALUE_ORG = 'S'
TABLES
VALUE_TAB = T_CORP
EXCEPTIONS
PARAMETER_ERROR = 1
NO_VALUES_FOUND = 2
OTHERS = 3.
IF SY-SUBRC EQ 0.
Do nothing
ENDIF. " IF SY-SUBRC EQ 0
ENDFORM. " F4HELP_CORP -
How to create store procedure using cursor, and looping condition with exce
Hi,
I am new in pl/sql development , please help me for follwoing
1. I have select query by joining few tables which returns lets say 100 records.
2. I want to insert records into another table(lets say table name is tbl_sale).
3. If first record is inserted into tbl_sale,and for next record if value is same as first then update into tbl_sale else
insert new row
4. I want to achieve this using store procedure.
Please help me how to do looping,how to use cursor and all other necessary thing to achieve this.DECLARE
b NUMBER;
BEGIN
UPDATE tbl_sale
SET a = b
WHERE a = 1;
IF SQL%ROWCOUNT = 0
THEN
INSERT INTO tbl_sale
(a
VALUES (b
END IF;
END;note : handle exceptions where ever needed
Regards,
friend
Edited by: most wanted!!!! on Mar 18, 2013 12:06 AM -
How to count values being outputted ?
I have a loop running through a DB and the program outputs values such as below to the screen, where the first character is varied it can be any value (eg ABC WON, or XYZ LOST) , and the output can also be of varying lengths.
How could the program count up the number of wins etc for each one e.g. output D Won 1, A Lost 2, A Won 1, A Drawn 1 etc
D WON
A LOST
C WON
A LOST
A DRAWN
B DRAWN
B WON
D LOST
C WON
B LOST
A WON
D LOST
I tried using an array but could not get it to work, ideas would be v. appreciated,
thanks
(sorry for the caps but thats output of the program ;) )Create a class Team which contains Name, Wins, Losses.
Use a Map to store the instances of Team, the Key being the team name, the value being the Team instance.
Whenever you want to update the teams win/loss record, ask for the team by name from the map.
If it returns null, create and add a new team.
If it returns a Team, simply update the Team instance. -
How to count values in a query ?
Hi experts,
We have a query, which is having only characteristics. There are no key figures.
There is date field. In this date field the value may be or may not be there.
My requirement is if the date field has value then it should be counted record wise and the total count
should be displayed in the bottom of the query output. If value is not there then that record should not be
counted.
How can we do this ?
Regards,
Nishuv.Dear Nishuv,
You can create a calculated keyfigure for getting count, in that create a formula variable on characterstic with replacement as processing type.
and please clarify on what level you wanted to count, like Sales Docuement level or Item level.
For Example :
If you wanted to find no.of sales orders which are returned so you have to count on document level. this would be the replacement characterstic.
Please find the below PDf you will understand better
https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/009819ab-c96e-2910-bbb2-c85f7bdec04a
Thanks
Sreekanth -
How to Count the Materials used in the Service Orders
Hi Experts,
I have created a replacement variable to get the count of the materials in the report.
Here I have some service orders where material is not consumed. It is called no part call.
When I run the report. It give count for all the materials and aswell as the field where we have "not assigned" (no part/no material).
I want only the count for Material not for "not assigned".
Can any expert help me achieve this please.
ThanksBrilliant,
Full Points assigned
Thanks -
Urgent : JDBC How to Count Values in result set.
Hi all,
How can i find the size of ResultSet i.e. The number of records returned by a select statement.
Thanks in advance.
Abhishekint nb = 0;
while (rs.next())
nb++; -
How to update multiple rows using cursor.
hi all,
i want to update rows fetched by a cursor. it don't update the rows.
and gives error:
ORA-01002 fetch out of sequence
here is the trigger.
Declare
alert_id ALERT := Find_Alert('on');
alert_button NUMBER;
var number :=10;
v_al char(3);
v_al_da date;
s_date date;
al_on number;
to_time number;
cursor rem is
select re_about, alarm, alert_date
from remind
where alarm='ON' AND alert_date = :control.showdate
for update;
begin
for rem_record IN rem LOOP
Set_Alert_Property(alert_id, ALERT_MESSAGE_TEXT, rem_record.re_about);
al_on := show_alert('ON');
IF alert_button = ALERT_BUTTON1 THEN
update remind
set alarm = 'OFF'
--where re_about = rem_record.re_about
where current of rem;
ELSE
NULL;
END IF;
COMMIT;
END LOOP;
end;
thanks
Muhammad Nadeem
Mardanthanks dear,
i tried the following code outside the loop
but the same problem.
here is the code:
Declare
alert_id ALERT := Find_Alert('on');
alert_button NUMBER;
var number :=10;
v_al char(3);
v_al_da date;
s_date date;
al_on number;
to_time number;
cursor rem is
select re_about, alarm, alert_date
from remind
where alarm='ON' AND alert_date = :control.showdate
for update;
begin
for rem_record IN rem LOOP
Set_Alert_Property(alert_id, ALERT_MESSAGE_TEXT, rem_record.re_about);
al_on := show_alert('ON');
IF alert_button = ALERT_BUTTON1 THEN
update remind
set alarm = 'OFF'
where current of rem;
ELSE
NULL;
END IF;
END LOOP;
if :SYSTEM.FORM_STATUS = 'changed' then
COMMIT;
end if;
end;
thanks
Muhammad Nadeem -
How to pass value by using SQL*PLUS
Dear all,
I have a file (e.g. test.sql) and run in SQL*PLUS. The code like the following:
set serveroutput on
variable v_a number;
variable v_b number;
variable v_x number;
:v_x := 12345;
execute packagename.procedure(:v_x, :v_a, :v_b);
print v_a;
print v_b;
Why it does not work??
Thanks for any advice.
Regrads.Test it:
set ver off;
set serveroutput on
variable v_a number;
variable v_b number;
variable v_x number;
accept v_a prompt 'Input value for v_a: '
accept v_b prompt 'Input value for v_b: '
accept v_x prompt 'Input value for v_x: '
begin
:v_a := &v_a;
:v_b := &v_b;
:v_x := &v_x;
end;
print v_a;
print v_b;
print v_x; -
hi
how i can draw line using cursor in xy graph
Solved!
Go to Solution.Hi bijal,
Not sure what you are planning to do. But you could start with:
Creating a XY graph.
Right click on the XY graph >> Visible Items>> Cursor Legend.
Right click on the cursor legend >> Create Cursor >> Free. Up to this step, you should able to create the cursor.
To obtain the data from the cursor, go to your block diagram >> right click on the XY graph terminal at the block diagram >> Create >> Property Node >> Active Cursor. This should create the property node for your XY graph. To change a selected property to write, right click on the active cursor >> Change to Read and it should be like below:
Just input 0 to access the first cursor
Expend it to access an additional properties >> on the second property, click on it >> Cursor >> Cursor Position >> Cursor X.
Expend the properties until you see as below:
It Cursor.PosX and Cursor.PosY isn't changed to write, do change it to write by right clicking on Cursor.PosX >> Change to Write. Do the same for Cursor.PosY
Up to point 6, you should be able to obtain data from the XY graph cursor.
Use those values to plot into the XY graph. I believe you'll need to find a way to plot XY graph by building an array of clusters.
Hope it helps
Warmest regards,
Lennard.C
Learning new things everyday... -
How to pick max value from a column of a table using cursor and iteration
Hello Everybody
I have a table loan_detail
and a column in it loan_amount
now i want to pick values from this table using cursor and then by using iteration i want to pick max value from it using that cursor
here is my table
LOAN_AMOUNT
100
200
300
400
500
5600
700i was able to do it using simple loop concepts but when i was trying to do this by using cursor i was not able to do it .
Regards
PeeyushSQL> SELECT MAX(sal) Highest_Sal,MIN(sal) Lowest_Sal FROM emp;
HIGHEST_SAL LOWEST_SAL
5000 800
SQL> set serverout on
SQL> DECLARE
2 TYPE tmp_tbl IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
3 sal_tbl tmp_tbl;
4 CURSOR emp_sal IS
5 SELECT sal FROM emp;
6 counter INTEGER := 1;
7 BEGIN
8 FOR i IN emp_sal LOOP
9 sal_tbl(i.sal) := counter;
10 counter := counter + 1;
11 END LOOP;
12 DBMS_OUTPUT.put_line('Lowest SAL:' || sal_tbl.FIRST);
13 DBMS_OUTPUT.put_line('Highest SAL:' || sal_tbl.LAST);
14 END;
15 /
Lowest SAL:800
Highest SAL:5000
PL/SQL procedure successfully completed.
SQL> Even smaller
SQL> DECLARE
2 TYPE tmp_tbl IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
3 sal_tbl tmp_tbl;
4 CURSOR emp_sal IS
5 SELECT sal FROM emp;
6 counter INTEGER := 1;
7 BEGIN
8 FOR i IN emp_sal LOOP
9 sal_tbl(i.sal) := 1;
10 END LOOP;
11 DBMS_OUTPUT.put_line('Lowest SAL:' || sal_tbl.FIRST);
12 DBMS_OUTPUT.put_line('Highest SAL:' || sal_tbl.LAST);
13 END;
14 /
Lowest SAL:800
Highest SAL:5000
PL/SQL procedure successfully completed.
SQL> Edited by: Saubhik on Jan 5, 2011 4:41 PM -
How to retrieve the max value from a cursor in procedure
Hi,
In a procedure, I defined a cursor:
cursor c_emp is select empno, ename, salary from emp where ename like 'J%';
but in the body part, I need to retrieve the max(salary) from the cursor.
could you please tell me how I can get the max value from the cursor in the procedure.
Thanks,
PaulHere is one sample but you should just get the max directly. Using bulk processing should be a last resort.
DECLARE
CURSOR c1 IS (SELECT * FROM emp where sal is not null);
TYPE typ_tbl IS TABLE OF c1%rowtype;
v typ_tbl;
max_sal number;
BEGIN
OPEN c1;
max_sal := -9999999999999;
LOOP --Loop added
FETCH c1 BULK COLLECT INTO v LIMIT 3; -- process 3 records at a time
-- process the records
DBMS_OUTPUT.PUT_LINE('Processing ' || v.COUNT || ' records.');
FOR i IN v.first..v.last LOOP
if v(i).sal > max_sal then
max_sal := v(i).sal;
end if;
DBMS_OUTPUT.PUT_LINE(v(i).empno);
END LOOP;
EXIT WHEN c1%NOTFOUND;
END LOOP;
DBMS_OUTPUT.PUT_LINE('Max salary was: ' || max_sal);
END;
Processing 3 records.
7369
7499
7521
Processing 3 records.
7566
7654
7698
Processing 3 records.
7782
7788
7839
Processing 3 records.
7844
7876
7900
Processing 2 records.
7902
7934
Max salary was: 5000 -
How to return a resultset in a stored procedure without using Cursor
Dear all,
I need to return a resultset in a stored procedure.
I know I can return a Cursor.
But because there are many complicate logics I need to carry out,
so I can finish all the logic in a SINGLE SQL select statement, so I think it can't
use Cursor as return value.
Does anybody know other approaches? Please help.
Thanks!Some basic techniques that one can use in SQL. These are merely to illustrate (simplistically) different approaches.
> field3 = select count(*) from table2,table1 where table2.id = table1.id
This can be done via an analytical function (refer to the SQL Reference) or very simply, as an in-line select as follows:
SQL> select
2 o.object_name,
3 (select count(*) from user_objects u where u.object_type = o.object_type) as "ONE OF",
4 o.object_type
5 from user_objects o
6 where o.object_name = 'LISTFILES';
OBJECT_NAME ONE OF OBJECT_TYPE
LISTFILES 8 PROCEDURE
So LISTFILE is "one of 8" procedures. I would however rather so this via an analytic function as these are a lot more flexible. Note the WITH clause that allows "modularisation" of SQL - kind of like creating "sub-SQL results" in a single SQL statement:
SQL> with DATASET1 as(
2 select
3 object_name,
4 count(distinct object_name) over (partition by object_type) as TOTAL_TYPES,
5 object_type
6 from user_objects
7 ),
8 DATASET2 as(
9 select
10 name,
11 text as SOURCE_LINE,
12 line as LINE_NO,
13 count(line) over (partition by name) as TOTAL_LINES
14 from user_source
15 )
16 select
17 object_name,
18 '1 of '||total_types||' '||object_type as "TYPE",
19 source_line as "1st LINE",
20 total_lines as "TOTAL LINES"
21 from DATASET1 ds1,
22 DATASET2 ds2
23 where ds1.object_name = ds2.name
24 and ds1.object_name = 'LISTFILES'
25* and ds2.line_no = 1
SQL> /
OBJECT_NAME TYPE 1st LINE TOTAL LINES
LISTFILES 1 of 8 PROCEDURE procedure ListFiles( cDirectory in varchar2 ) 3
SQL>
SQL is quite powerful and analytical functions allows all kinds of aggregation processing per row, accessing the leading or lagging rows' data, etc.
You need to play around with this to get to grips with it and how to apply it. -
How to get counter value from Historian
Hi Experts,
We have got a scenario to keep the number (counter) to see how many time a value of tag have been changed.
For Example:
If the values change from 1 to 0 and 0 to 1 for 25 times in a minute. We would like to get this number (25) from Historian (Wonderware).
Currently we are not using any Pco to fetch the value from Hisotrian since we are able to fetch the tag values from Historian database through SQLConnection.
I would like to know if we introduce Pco, will that help us to get this counter value.
We are working on MII 15.0 version.
Any help of this very much appreciated.
Thanks
ShajiHi Shaji,
PCo OPC DA does not support PCoQuery TagAggregateMode as it only has access to Current Values of OPC Tags, because OPC DA only provides Current Value access.
I know it is possible to execute SQL queries against the Wonderware Historian to retrieve counts aggregates, but don't have the details handy. Recommend that you deploy the InSQLPCo Data Server in MII and try using the PCoQuery TagAggregateMode method to retrieve the Counts aggregate first.
Regards, Steve -
How to get counter values from pci 6221 card?
Hii
I am using PCI 6221 card .. In that i am using the ctr o .. In my application i am using Linear encoder to measure the Lift movement.. so from software how to access the counter values i.e how much mm it moves...Measure Angular Position.vi in the LabVIEW examples will be a good starting point. Adapt it to Linear Encoder by clicking on the selector below DAQmx Create Channel.vi.
You can also create a corresponding DAQmx Global Channel (or task) in MAX and then use it in your code.
Feel free to post back if you need further help.
Message Edité par JB le 10-31-2008 02:15 PM
Maybe you are looking for
-
Issues with iTunes Match on iPhone
I am having some frustrating issues with iTunes Match and my iPhone 4 iOS 5. 1) When using cellular data (3G), the songs simply do not play from the music app. It works fine when connected to wifi. Under settings, cellular data has been enabled for u
-
My ipod touch 4th generation will not connect to Itunes.
I registered it on a different computer and then was able to connect after that. Now it won't connect to Itunes, but my old Ipod still connects I did the suggestions and also redownloaded Itunes. Any suggestions?
-
Why isn't the Submit button submitting responses?
I created an evaluation form using Forms Central and distributed it. 4/5 respondents filled it out with no problems. The last person filled it out twice and lost her responses once through an error on her end and the second time she doesn't know why
-
How to change the path for Home and Work in SQL Developer
Hi, I am new to Oracle SQL Developer. Everytime when I open a file, it will default to the install directory. It is hurtingmy hand because I have to click back to the folder where I put my sql statements. Is there any way to set the Home or Work butt
-
Family guy problems!!
Well, I tried to convert a Family guy episode in videora but the sound just came up bad. When I passed it in iTunes sometimes I could hear it and sometimes not. What's the problem?