Actual Cursor-Pixel for selection inaccurately placed?
Hello,
I've tried going through a few pages on Google search results and here at the Apple community section, but I have not seen anyone with this question.
Below is as a picture I took with my iPhone really close to my non-HD monitor. I apologize for it being blurry. The point is that the actual pixel the OS X cursor uses for selection seems to be wrong, at least on my Late 2012 Mac Mini running 10.10.1. (This "problem" also existed in Mavericks, as well.) When I click on the desktop and drag down -> right, it seems ok. When I click and drag either up or down -> left, it shows it being off. This odd placement for the selecting pixel is also demonstrated by moving the cursor to the right side of the screen; here, I can see enough of the cursor left on the screen that I see the slop up and down from left "line" of the cursor.
Maybe it has always been that way, but having used (read: suffered) Windows for so long, I'm used to the cursor being more in the actual point. The cursor for OS X seems to be offset from even the black point within the white border.
Any clarity provided into this would be extremely appreciated.
Thanks!
P.s. I have no idea how the image got inverted from being taken on my phone then Airdropped to the mini.
I don't see the option for editing that post. It should have said "slope up and down" in the last sentence of the second paragraph -- NOT "slop up and down."
Similar Messages
-
Cursor - Suggestions for Dynamic select statements
Hey,
Am trying to define a cursor like this -
cursor c1 is
select table_name from dba_tables INTERSECT select table_name from dba_tables@SOME_DBLINKMy need is to pass this dblink as IN parameter to the procedure and use it in the select statement for cursor. How can I do this?
Any suggestion is highly appreciated. Thanks!Well that was meant to be my point. If you had two, you wouldn't (I hope) call the second one "c2" - you would be forced to think about what it represented, and name it "c_order_history" or something. Sticking "1" on the end does not make an extensible naming convention for cursors any more than it does for variables, procedures, tables or anything else, and so the "1" in "c1" is redundant because there will never be a c2.
-
Using two cursors, one for updating salary values in the emp table
Using COPIES of the employee and department tables provided by Oracle or using similar taples that provide employee, salary, job and dept in one table and dept number and department name in another table, write the following program. Use the dept table to step through sequentially and bring up the records with the same department from the employee table. Using an IF statement calcuate a new salary based on the job (you decide on the criteria). Update each record on the employee file (this is why you should use copies) with the new salary. In addition, calculate the total salary for each department and create a new table with the department number, the department name and the salary.
I'm able to update the salary values, but I'm not sure how to insert those updated values into an empty table the way this problem is asking me to.
Here's my script so far: any help would be greatly appreciated: )
declare
v_deptno emp.deptno%type;
v_job emp.job%type;
v_sal emp.sal%type;
v_dname dept.dname%type;
v_deptsal totalsal.deptsal%type;
cursor salup_c is
select job,sal
from emp,dept
where emp.deptno = dept.deptno
for update of sal;
cursor totdeptsal_c is
select dname,sal
from emp,dept
where emp.deptno = dept.deptno;
Begin
open salup_c;
loop
fetch salup_c into v_job,v_sal;
exit when salup_c%notfound;
if v_job = 'CLERK' then
v_sal := v_sal + 10;
else
if v_job = 'ANALYST' then
v_sal := v_sal + 20;
else
if v_job = 'MANAGER' then
v_sal := v_sal + 30;
else
if v_job = 'PRESIDENT' then
v_sal := v_sal + 40;
else v_sal := v_sal + 50;
end if;
end if;
end if;
end if;
update emp
set sal = v_sal
where current of salup_c;
open totdeptsal_c;
v_deptsal := 0;
loop
fetch totdeptsal_c into v_dname, v_deptsal;
exit when totdeptsal_c%notfound;
v_deptsal := v_deptsal + v_sal;
insert into totalsal
values(v_deptno,v_dname,v_deptsal);
end loop;
close totdeptsal_c;
end loop;
close salup_c;
end;
/The script is actually inserting some values into the new table but look at what I'm getting
Here it is: i only want the dept number ,the dept name, and total salary for each department.
SQL> @ sndprob;
PL/SQL procedure successfully completed.
SQL> select * from totalsal;
DEPTNO DNAME DEPTSAL
RESEARCH 1620
SALES 2410
SALES 2060
RESEARCH 3785
SALES 2060
SALES 3660
ACCOUNTING 3260
RESEARCH 3810
ACCOUNTING 5810
SALES 2310
RESEARCH 1910
DEPTNO DNAME DEPTSAL
SALES 1760
RESEARCH 3810
ACCOUNTING 2110
RESEARCH 2460
SALES 3300
SALES 2900
RESEARCH 4625
SALES 2900
SALES 4500
ACCOUNTING 4100
RESEARCH 4650
DEPTNO DNAME DEPTSAL
ACCOUNTING 6650
SALES 3150
RESEARCH 2750
SALES 2600
RESEARCH 4650
ACCOUNTING 2950
RESEARCH 2110
SALES 2950
SALES 2600
RESEARCH 4275
SALES 2550
DEPTNO DNAME DEPTSAL
SALES 4150
ACCOUNTING 3750
RESEARCH 4300
ACCOUNTING 6300
SALES 2800
RESEARCH 2400
SALES 2250
RESEARCH 4300
ACCOUNTING 2600
RESEARCH 3815
SALES 4655
DEPTNO DNAME DEPTSAL
SALES 4305
RESEARCH 6010
SALES 4255
SALES 5855
ACCOUNTING 5455
RESEARCH 6005
ACCOUNTING 8005
SALES 4505
RESEARCH 4105
SALES 3955
RESEARCH 6005
DEPTNO DNAME DEPTSAL
ACCOUNTING 4305
RESEARCH 2110
SALES 2950
SALES 2600
RESEARCH 4305
SALES 2600
SALES 4150
ACCOUNTING 3750
RESEARCH 4300
ACCOUNTING 6300
SALES 2800
DEPTNO DNAME DEPTSAL
RESEARCH 2400
SALES 2250
RESEARCH 4300
ACCOUNTING 2600
RESEARCH 3690
SALES 4530
SALES 4180
RESEARCH 5885
SALES 4180
SALES 5760
ACCOUNTING 5330
DEPTNO DNAME DEPTSAL
RESEARCH 5880
ACCOUNTING 7880
SALES 4380
RESEARCH 3980
SALES 3830
RESEARCH 5880
ACCOUNTING 4180
RESEARCH 3290
SALES 4130
SALES 3780
RESEARCH 5485
DEPTNO DNAME DEPTSAL
SALES 3780
SALES 5360
ACCOUNTING 4960
RESEARCH 5480
ACCOUNTING 7480
SALES 3980
RESEARCH 3580
SALES 3430
RESEARCH 5480
ACCOUNTING 3780
RESEARCH 3830
DEPTNO DNAME DEPTSAL
SALES 4670
SALES 4320
RESEARCH 6025
SALES 4320
SALES 5900
ACCOUNTING 5500
RESEARCH 6040
ACCOUNTING 8020
SALES 4520
RESEARCH 4120
SALES 3970
DEPTNO DNAME DEPTSAL
RESEARCH 6020
ACCOUNTING 4320
RESEARCH 5850
SALES 6690
SALES 6340
RESEARCH 8045
SALES 6340
SALES 7920
ACCOUNTING 7520
RESEARCH 8060
ACCOUNTING 10080
DEPTNO DNAME DEPTSAL
SALES 6540
RESEARCH 6140
SALES 5990
RESEARCH 8040
ACCOUNTING 6340
RESEARCH 2360
SALES 3200
SALES 2850
RESEARCH 4555
SALES 2850
SALES 4430
DEPTNO DNAME DEPTSAL
ACCOUNTING 4030
RESEARCH 4570
ACCOUNTING 6590
SALES 3100
RESEARCH 2650
SALES 2500
RESEARCH 4550
ACCOUNTING 2850
RESEARCH 1920
SALES 2760
SALES 2410
DEPTNO DNAME DEPTSAL
RESEARCH 4115
SALES 2410
SALES 3990
ACCOUNTING 3590
RESEARCH 4130
ACCOUNTING 6150
SALES 2660
RESEARCH 2220
SALES 2060
RESEARCH 4110
ACCOUNTING 2410
DEPTNO DNAME DEPTSAL
RESEARCH 1770
SALES 2610
SALES 2260
RESEARCH 3965
SALES 2260
SALES 3840
ACCOUNTING 3440
RESEARCH 3980
ACCOUNTING 6000
SALES 2510
RESEARCH 2070
DEPTNO DNAME DEPTSAL
SALES 1920
RESEARCH 3960
ACCOUNTING 2260
RESEARCH 3830
SALES 4670
SALES 4320
RESEARCH 6025
SALES 4320
SALES 5900
ACCOUNTING 5500
RESEARCH 6040
DEPTNO DNAME DEPTSAL
ACCOUNTING 8060
SALES 4570
RESEARCH 4130
SALES 3980
RESEARCH 6040
ACCOUNTING 4320
RESEARCH 2120
SALES 2960
SALES 2610
RESEARCH 4315
SALES 2610
DEPTNO DNAME DEPTSAL
SALES 4190
ACCOUNTING 3790
RESEARCH 4330
ACCOUNTING 6350
SALES 2860
RESEARCH 2420
SALES 2270
RESEARCH 4330
ACCOUNTING 2620
196 rows selected. -
OPEN out_cur FOR SELECT exception handling help
Here is the stored procedure for reading a data based on the input, if no data then return null ref cursor and proper error message.
I am not sure, i am handling proper exception handling ? Please help me to complete this item.
Thanks.
PROCEDURE testing
module IN VARCHAR2,
module_id IN VARCHAR2,
out_cur OUT SYS_REFCURSOR,
out_error_no OUT NUMBER
BEGIN
out_error_no := 0;
CASE
WHEN module = 'a' AND module_id = 'b' THEN
BEGIN
OPEN out_cur FOR
SELECT id,
mime_type,
file_length,
file_name ,
uploadeddate,
created_user ,
status_name
FROM l_table_cnt
WHERE id = module_id;
EXCEPTION
WHEN OTHERS THEN
OPEN out_cur_file_cursor FOR
SELECT
NULL id,
NULL mime_type,
NULL file_length,
NULL file_name,
NULL uploadeddate,
NULL created_user,
NULL status_name
FROM dual
WHERE 1= 0;
out_error_no := 2;
RAISE_APPLICATION_ERROR(-20024,'No Document ');
END;Venkadesh wrote:
The correct way is to just open the ref cursor and pass it back and then the receiving code that is going to use that cursor handles whether there is any code in it or not. can you please explain with simple exampleIs it really that difficult?
Ok...
Here's the procedure to return a ref cursor...
SQL> ed
Wrote file afiedt.buf
1 create or replace procedure get_rc(p_deptno in number, p_rc out sys_refcursor) is
2 begin
3 open p_rc for 'select * from emp where deptno = :1' using p_deptno;
4* end;
SQL> /
Procedure created.Now we have some application that wants to consume a ref cursor... in this case the application is SQL*Plus, but it could be Java or .NET etc.
It declares it's local reference to the ref cursor...
SQL> var r refcursor;then calls the procedure to get a ref cursor reference assigned...
SQL> exec get_rc(10, :r);
PL/SQL procedure successfully completed.Now, the application itself determines if there is any data when it comes to actually perform the fetches on it...
SQL> print r;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7782 CLARK MANAGER 7839 09-JUN-1981 00:00:00 2450 10
7839 KING PRESIDENT 17-NOV-1981 00:00:00 5000 10
7934 MILLER CLERK 7782 23-JAN-1982 00:00:00 1300 10in the above case it had data, so it displayed it.
So what if there isn't any data...
SQL> exec get_rc(90, :r);
PL/SQL procedure successfully completed.
SQL> print r;
no rows selected
SQL>SQL*Plus (the application that calls the procedure) is the one that has determined that there was not data when it came to fetch it (using the print statement in this case). And when it found there was no data it handled it itself (in this case printing the message "no rows returned").
The procedure doesn't have to do any overhead of determining if there is data going to be returned or not, because it's not it's responsibility and completely unnecessary. The calling application can easily determine if there is data or not when it starts to try and fetch it. -
Help with if statement in cursor and for loop to get output
I have the following cursor and and want to use if else statement to get the output. The cursor is working fine. What i need help with is how to use and if else statement to only get the folderrsn that have not been updated in the last 30 days. If you look at the talbe below my select statement is showing folderrs 291631 was updated only 4 days ago and folderrsn 322160 was also updated 4 days ago.
I do not want these two to appear in my result set. So i need to use if else so that my result only shows all folderrsn that havenot been updated in the last 30 days.
Here is my cursor:
/*Cursor for Email procedure. It is working Shows userid and the string
You need to update these folders*/
DECLARE
a_user varchar2(200) := null;
v_assigneduser varchar2(20);
v_folderrsn varchar2(200);
v_emailaddress varchar2(60);
v_subject varchar2(200);
Cursor c IS
SELECT assigneduser, vu.emailaddress, f.folderrsn, trunc(f.indate) AS "IN DATE",
MAX (trunc(fpa.attemptdate)) AS "LAST UPDATE",
trunc(sysdate) - MAX (trunc(fpa.attemptdate)) AS "DAYS PAST"
--MAX (TRUNC (fpa.attemptdate)) - TRUNC (f.indate) AS "NUMBER OF DAYS"
FROM folder f, folderprocess fp, validuser vu, folderprocessattempt fpa
WHERE f.foldertype = 'HJ'
AND f.statuscode NOT IN (20, 40)
AND f.folderrsn = fp.folderrsn
AND fp.processrsn = fpa.processrsn
AND vu.userid = fp.assigneduser
AND vu.statuscode = 1
GROUP BY assigneduser, vu.emailaddress, f.folderrsn, f.indate
ORDER BY fp.assigneduser;
BEGIN
FOR c1 IN c LOOP
IF (c1.assigneduser = v_assigneduser) THEN
dbms_output.put_line(' ' || c1.folderrsn);
else
dbms_output.put(c1.assigneduser ||': ' || 'Overdue Folders:You need to update these folders: Folderrsn: '||c1.folderrsn);
END IF;
a_user := c1.assigneduser;
v_assigneduser := c1.assigneduser;
v_folderrsn := c1.folderrsn;
v_emailaddress := c1.emailaddress;
v_subject := 'Subject: Project for';
END LOOP;
END;
The reason I have included the folowing table is that I want you to see the output from the select statement. that way you can help me do the if statement in the above cursor so that the result will look like this:
emailaddress
Subject: 'Project for ' || V_email || 'not updated in the last 30 days'
v_folderrsn
v_folderrsn
etc
[email protected]......
Subject: 'Project for: ' Jim...'not updated in the last 30 days'
284087
292709
[email protected].....
Subject: 'Project for: ' Kim...'not updated in the last 30 days'
185083
190121
190132
190133
190159
190237
284109
286647
294631
322922
[email protected]....
Subject: 'Project for: Joe...'not updated in the last 30 days'
183332
183336
[email protected]......
Subject: 'Project for: Sam...'not updated in the last 30 days'
183876
183877
183879
183880
183881
183882
183883
183884
183886
183887
183888
This table is to shwo you the select statement output. I want to eliminnate the two days that that are less than 30 days since the last update in the last column.
Assigneduser....Email.........Folderrsn...........indate.............maxattemptdate...days past since last update
JIM......... jim@ aol.com.... 284087............. 9/28/2006.......10/5/2006...........690
JIM......... jim@ aol.com.... 292709............. 3/20/2007.......3/28/2007............516
KIM......... kim@ aol.com.... 185083............. 8/31/2004.......2/9/2006............. 928
KIM...........kim@ aol.com.... 190121............. 2/9/2006.........2/9/2006.............928
KIM...........kim@ aol.com.... 190132............. 2/9/2006.........2/9/2006.............928
KIM...........kim@ aol.com.... 190133............. 2/9/2006.........2/9/2006.............928
KIM...........kim@ aol.com.... 190159............. 2/13/2006.......2/14/2006............923
KIM...........kim@ aol.com.... 190237............. 2/23/2006.......2/23/2006............914
KIM...........kim@ aol.com.... 284109............. 9/28/2006.......9/28/2006............697
KIM...........kim@ aol.com.... 286647............. 11/7/2006.......12/5/2006............629
KIM...........kim@ aol.com.... 294631............. 4/2/2007.........3/4/2008.............174
KIM...........kim@ aol.com.... 322922............. 7/29/2008.......7/29/2008............27
JOE...........joe@ aol.com.... 183332............. 1/28/2004.......4/23/2004............1585
JOE...........joe@ aol.com.... 183336............. 1/28/2004.......3/9/2004.............1630
SAM...........sam@ aol.com....183876.............3/5/2004.........3/8/2004.............1631
SAM...........sam@ aol.com....183877.............3/5/2004.........3/8/2004.............1631
SAM...........sam@ aol.com....183879.............3/5/2004.........3/8/2004.............1631
SAM...........sam@ aol.com....183880.............3/5/2004.........3/8/2004.............1631
SAM...........sam@ aol.com....183881.............3/5/2004.........3/8/2004.............1631
SAM...........sam@ aol.com....183882.............3/5/2004.........3/8/2004.............1631
SAM...........sam@ aol.com....183883.............3/5/2004.........3/8/2004.............1631
SAM...........sam@ aol.com....183884.............3/5/2004.........3/8/2004............ 1631
SAM...........sam@ aol.com....183886.............3/5/2004.........3/8/2004............ 1631
SAM...........sam@ aol.com....183887.............3/5/2004.........3/8/2004............ 1631
SAM...........sam@ aol.com....183888.............3/5/2004.........3/8/2004............ 1631
PAT...........pat@ aol.com.....291630.............2/23/2007.......7/8/2008............ 48
PAT...........pat@ aol.com.....313990.............2/27/2008.......7/28/2008............28
NED...........ned@ aol.com.....190681.............4/4/2006........8/10/2006............746
NED...........ned@ aol.com......95467.............6/14/2006.......11/6/2006............658
NED...........ned@ aol.com......286688.............11/8/2006.......10/3/2007............327
NED...........ned@ aol.com.....291631.............2/23/2007.......8/21/2008............4
NED...........ned@ aol.com.....292111.............3/7/2007.........2/26/2008............181
NED...........ned@ aol.com.....292410.............3/15/2007.......7/22/2008............34
NED...........ned@ aol.com.....299410.............6/27/2007.......2/27/2008............180
NED...........ned@ aol.com.....303790.............9/19/2007.......9/19/2007............341
NED...........ned@ aol.com.....304268.............9/24/2007.......3/3/2008............ 175
NED...........ned@ aol.com.....308228.............12/6/2007.......12/6/2007............263
NED...........ned@ aol.com.....316689.............3/19/2008.......3/19/2008............159
NED...........ned@ aol.com.....316789.............3/20/2008.......3/20/2008............158
NED...........ned@ aol.com.....317528.............3/25/2008.......3/25/2008............153
NED...........ned@ aol.com.....321476.............6/4/2008.........6/17/2008............69
NED...........ned@ aol.com.....322160.............7/3/2008.........8/21/2008............4
MOE...........moe@ aol.com.....184169.............4/5/2004.......12/5/2006............629
[email protected]/27/2004.......3/8/2004............1631
How do I incorporate a if else statement in the above cursor so the two days less than 30 days since last update are not returned. I do not want to send email if the project have been updated within the last 30 days.
Edited by: user4653174 on Aug 25, 2008 2:40 PManalytical functions: http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/functions2a.htm#81409
CASE
http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96624/02_funds.htm#36899
http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96624/04_struc.htm#5997
Incorporating either of these into your query should assist you in returning the desired results. -
Using Cursor and FOR LOOP to INSERT the data into table
Hi all,
I have SELECT statement that returns 3 rows:
PROCESSNAME
PROTDATE
IMM
2013-12-18
Metrology
2013-11-18
CT
2013-12-04
SELECT processName, MAX(NVL(protStartDate, protCreateDate)) AS protDate
FROM TABLE(SEM_MATCH("{
?ipc rdf:type s:Protocol .
?ipc s:protocolNumber ?protNum .
?ipc s:protocolCreateDate ?protCreateDate .
OPTIONAL {?ipc s:protocolSchedStartDate ?protStartDate }
?ipra rdf:type s:ProcessAggregate .
?ipra s:hasProtocol ?iprot .
?iprot s:protocolNumber ?protNum .
?ipra s:processAggregateProcess ?processName.
}",sem_models("PROTS", "LINEARS"),NULL, SEM_ALIASES(SEM_ALIAS("","http://VISION/Data/SEMANTIC#"),SEM_ALIAS("s","http://VISION/DataSource/SEMANTIC#")),NULL))
Group by processName
Now I need to INSERT these values into the table along with the other values.
these other values come from different table.
INSERT INTO MODEL_CLASS_COUNTS (MODEL_NAME, CLASS_NAME, INS_COUNT, COUNT_DATETIME, PROCESS_NAME, PROT_DATE)
VALUES
("$MODEL",
"${i}",
(SELECT COUNT (DISTINCT S) FROM TABLE(SEM_MATCH(
"{?s rdf:type :${i} . }",SEM_Models("$MODEL"),NULL, SEM_ALIASES(SEM_ALIAS("","http://VISION/DataSource/SEMANTIC#")),NULL))),
SYSTIMESTAMP, %%here need to insert PROCESSNAME, PROTDATE%%
t was giving me error:
PL/SQL: ORA-22905: cannot access rows from a non-nested table item
so i enclosed sparql query into single quotes.
The code is as follows:
declare
type c_type is REF CURSOR;
cur c_type;
v_process varchar2(200);
v_pdate varchar2(200);
begin
open cur for
' SELECT processName, MAX(NVL(protStartDate, protCreateDate)) AS protDate <-- it's complaining about this being too long identifier, i think...
FROM TABLE
(SEM_MATCH (
?ipc rdf:type s:Protocol .
?ipc s:protocolNumber ?protNum .
?ipc s:protocolCreateDate ?protCreateDate .
OPTIONAL {?ipc s:protocolSchedStartDate ?protStartDate }
?ipra rdf:type s:ProcessAggregate .
?ipra s:hasProtocol ?iprot .
?iprot s:protocolNumber ?protNum .
?ipra s:processAggregateProcess ?processName.
}",SEM_Models("XCOMPASS", "XPROCESS"),NULL,
SEM_ALIASES(SEM_ALIAS("","http://VISION/Data/SEMANTIC#"),
SEM_ALIAS("s", "http://VISION/DataSource/SEMANTIC#")),NULL))
Group by processName';
loop
fetch cur into v_process, v_pdate;
exit when cur%NOTFOUND;
--here I need to insert v_process , v_pdate into my table along with other values...
dbms_output.put_line('values for process and prod_date are: ' || v_process || v_pdate );
end loop;
close cur;
end;
exit;
Now, I get an error:
ORA-00972: identifier is too long
Does anyone know way around this?Hi,
I tested something similar with insert into select and it worked fine :
insert into t_countries(ID,CITY ,POPULATION, DESCRIPTION, located, insdate )
SELECT 1 id, city, o , city||' is a nice city' description, max(nvl(locatedAt,'unknown')) as located,
SYSTIMESTAMP
FROM TABLE(SEM_MATCH(
'{GRAPH :gCH {<http://www.semwebtech.org/mondial/10/countries/CH/> :hasCity ?cityID .
?cityID :name ?city .
OPTIONAL{?cityID :locatedAt ?locatedAt .}
?cityID :population ?o .
SEM_Models('VIRT_MODEL_MONDIAL'),
SEM_Rulebases(null),
SEM_ALIASES(SEM_ALIAS('','http://www.semwebtech.org/mondial/10/meta#'),
SEM_ALIAS('prv','http://www.semwebtech.org/mondial/10/countries/CH/provinces/')
null))
group by city,o
order by city;
Or with execute immediate :
declare
v_country varchar2(200) :='http://www.semwebtech.org/mondial/10/countries/F/';
v_text varchar2(2000);
begin
v_text := 'insert into t_countries(ID,CITY ,POPULATION, DESCRIPTION, located, insdate )
SELECT 1 id, city, o , city||'' is a nice city'' description, max(nvl(locatedAt,''unknown'')) as located,
SYSTIMESTAMP
FROM TABLE(SEM_MATCH(
''{<'||v_country||'> :hasCity ?cityID .
?cityID :name ?city .
OPTIONAL{?cityID :locatedAt ?locatedAt .}
?cityID :population ?o .
SEM_Models(''VIRT_MODEL_MONDIAL''),
SEM_Rulebases(null),
SEM_ALIASES(SEM_ALIAS('''',''http://www.semwebtech.org/mondial/10/meta#'') ),
null))
group by city,o
order by city';
dbms_output.put_line(v_text);
delete from t_countries;
execute immediate v_text ;
commit;
end;
Marc -
Why use cursor and for loop?
Hi All
So in general why would we use a cursor and a for loop to do update in a stored procedure?
Why wouldnt we just use a single update statement ?
is there compelling reason for using a cursor and a for loop: I am reading some code from a co-worker that the business logic for the select (set need to be updated) is complex but the update logic is simple (just set a flag to (0 or 1 or 2 or 3 or 4).
But eventually the select come down to a key (row_id) so I re-write it using just a single sql statement.
The size of the main table is about 2.6 to 3million rows
Any thoughts on that??
The code below I just do a google for cursor for update example in case for something to play with
-Thanks for all your input
create table f (a number, b varchar2(10));
insert into f values (5,'five');
insert into f values (6,'six');
insert into f values (7,'seven');
insert into f values (8,'eight');
insert into f values (9,'nine');
commit;
create or replace procedure wco as
cursor c_f is
select a,b from f where length(b) = 5 for update;
v_a f.a%type;
v_b f.b%type;
begin
open c_f;
loop
fetch c_f into v_a, v_b;
exit when c_f%notfound;
update f set a=v_a*v_a where current of c_f;
end loop;
close c_f;
end;
exec wco;
select * from f;
drop table f;
drop procedure wco;
Joining multiple tables
create table numbers_en (
id_num number primary key,
txt_num varchar2(10)
insert into numbers_en values (1, 'one' );
insert into numbers_en values (2, 'two' );
insert into numbers_en values (3, 'three');
insert into numbers_en values (4, 'four' );
insert into numbers_en values (5, 'five' );
insert into numbers_en values (6, 'six' );
create table lang (
id_lang char(2) primary key,
txt_lang varchar2(10)
insert into lang values ('de', 'german');
insert into lang values ('fr', 'french');
insert into lang values ('it', 'italian');
create table translations (
id_num references numbers_en,
id_lang references lang,
txt_trans varchar2(10) not null
insert into translations values (1, 'de', 'eins' );
insert into translations values (1, 'fr', 'un' );
insert into translations values (2, 'it', 'duo' );
insert into translations values (3, 'de', 'drei' );
insert into translations values (3, 'it', 'tre' );
insert into translations values (4, 'it', 'quattro');
insert into translations values (6, 'de', 'sechs' );
insert into translations values (6, 'fr', 'six' );
declare
cursor cur is
select id_num,
txt_num,
id_lang,
txt_lang,
txt_trans
from numbers_en join translations using(id_num)
left join lang using(id_lang)
for update of translations.txt_trans;
rec cur%rowtype;
begin
for rec in cur loop
dbms_output.put (
to_char (rec.id_num , '999') || ' - ' ||
rpad (rec.txt_num , 10 ) || ' - ' ||
rpad(nvl(rec.txt_trans, ' '), 10 ) || ' - ' ||
rec.id_lang || ' - ' ||
rpad (rec.txt_lang , 10 )
if mod(rec.id_num,2) = 0 then
update translations set txt_trans = upper(txt_trans)
where current of cur;
dbms_output.put_line(' updated');
else
dbms_output.new_line;
end if;
end loop;
end;
/Edited by: xwo0owx on Apr 25, 2011 11:23 AMAdding my sixpence...
PL/SQL is not that different from a SQL perspective than any other SQL client language like Java or C# or C/C++. PL/SQL simply integrates the 2 languages a heck of a lot better and far more transparent than the others. But make no mistake in that PL/SQL is also a "client" language from a SQL perspective. The (internal) calls PL/SQL make to the SQL engine, are the same (driver) calls made to the SQL engine when using Java and C and the others.
So why a cursor and loops in PL/SQL? For the same reason you have cursors and loops in all these other SQL client languages. There are the occasion that you need to pull data from the SQL engine into the local language to perform some very funky and complex processing that is not possible using the SQL language.
The danger is using client cursor loop processing as the norm - always pulling rows into the client language and crunching it there. This is not very performant. And pretty much impossible to scale. Developers in this case views the SQL language as a mere I/O interface for reading and writing rows. As they would use the standard file I/O read() and write() interface calls.
Nothing could be further from the truth. SQL is a very advance and sophisticated data processing language. And it will always be faster than having to pull rows to a client language and process them there. However, SQL is not Turing complete. It is not the procedural type language that most other languages we use, are. For that reason there are things that we cannot do in SQL. And that should be the only reason for using the client language, like PL/SQL or the others, to perform row crunching using a client cursor loop. -
The query below will return values in the form of
bu seq eligible
22 2345 Y
22 2345 N
22 1288 N
22 1458 Y
22 1458 N
22 1234 Y
22 1333 N
What I am trying to accomplish is to loop through the records returned.
for each seq if there is a 'N' in the eligible column return no record for that seq
eg seq 2345 has 'Y' and 'N' thus no record should be returned.
seq 1234 has only a 'Y' then return the record
seq 1333 has 'N' so return no record.
How would I accomplish this with a ref Cursor and pass the values to the front end application.
Procedure InvalidNOs(io_CURSOR OUT T_CURSOR)
IS
v_CURSOR T_CURSOR;
BEGIN
OPEN v_CURSOR FOR
' select bu, seq, eligible ' ||
' from (select bu, seq, po, tunit, tdollar,eligible,max(eligible) over () re ' ||
' from (select bu, seq, po, tunit, tdollar,eligible ' ||
' from ( ' ||
' select bu, seq, po, tunit, tdollar, eligible, sum(qty) qty, sum(price*qty) dollars ' ||
' from ' ||
' ( select /*+ use_nl(t,h,d,s) */ ' ||
' h.business_unit_id bu, h.edi_sequence_id seq, d.edi_det_sequ_id dseq, ' ||
' s.edi_size_sequ_id sseq, h.po_number po, h.total_unit tUnit, h.total_amount tDollar, ' ||
' s.quantity qty, s.unit_price price,' ||
' (select (case when count(*) = 0 then ''Y'' else ''N'' end) ' ||
' from sewn.NT_edii_po_det_error ' ||
' where edi_det_sequ_id = d.edi_det_sequ_id ' ||
' ) eligible ' ||
' from sewn.nt_edii_purchase_size s, sewn.nt_edii_purchase_det d, ' ||
' sewn.nt_edii_purchase_hdr h, sewn.nt_edii_param_temp t ' ||
' where h.business_unit_id = t.business_unit_id ' ||
' and h.edi_sequence_id = t.edi_sequence_id ' ||
' and h.business_unit_id = d.business_unit_id ' ||
' and h.edi_sequence_id = d.edi_sequence_id ' ||
' and d.business_unit_id = s.business_unit_id ' ||
' and d.edi_sequence_id = s.edi_sequence_id ' ||
' and d.edi_det_sequ_id = s.edi_det_sequ_id ' ||
' ) group by bu, seq, po, tunit, tdollar, eligible ' ||
' ) ' ||
' group by bu, seq, po, tunit, tdollar, eligible)) ';
io_CURSOR := v_CURSOR;
END InvalidNOs;One remark why you should not use the assignment between ref cursor
variables.
(I remembered I saw already such thing in your code).
Technically you can do it but it does not make sense and it can confuse your results.
In the opposite to usual variables, when your assignment copies value
from one variable to another, cursor variables are pointers to the memory.
Because of this when you assign one cursor variable to another you just
duplicate memory pointers. You don't copy result sets. What you do for
one pointer is that you do for another and vice versa. They are the same.
I think the below example is self-explained:
SQL> /* usual variables */
SQL> declare
2 a number;
3 b number;
4 begin
5 a := 1;
6 b := a;
7 a := a + 1;
8 dbms_output.put_line('a = ' || a);
9 dbms_output.put_line('b = ' || b);
10 end;
11 /
a = 2
b = 1
PL/SQL procedure successfully completed.
SQL> /* cursor variables */
SQL> declare
2 a sys_refcursor;
3 b sys_refcursor;
4 begin
5 open a for select empno from emp;
6 b := a;
7 close b;
8
9 /* next action is impossible - cursor already closed */
10 /* a and b are the same ! */
11 close a;
12 end;
13 /
declare
ERROR at line 1:
ORA-01001: invalid cursor
ORA-06512: at line 11
SQL> declare
2 a sys_refcursor;
3 b sys_refcursor;
4 vempno emp.empno%type;
5
6 begin
7 open a for select empno from emp;
8 b := a;
9
10 /* Fetch first row from a */
11 fetch a into vempno;
12 dbms_output.put_line(vempno);
13
14 /* Fetch from b gives us SECOND row, not first -
15 a and b are the SAME */
16
17 fetch b into vempno;
18 dbms_output.put_line(vempno);
19
20
21 end;
22 /
7369
7499
PL/SQL procedure successfully completed.Rgds.
Message was edited by:
dnikiforov -
How to add cursor and for loop
PROCEDURE "TEST" is
bala number;
ins1 number;
ins2 number;
BEGIN
select sum(bal) into bala from (select sum(acp.acp_totbal) bal,acp_instruid from cs_strmap_t map,cs_instru_strips strip,cs_acpos_bkp acp
where c_int_instruid=c_srm_prncplinsid
and c_srm_prncplinsid=acp_instruid
and acp_acntnum!='SG030001'
group by acp_instruid
union
select sum(acp.acp_totbal) bal,acp_instruid from cs_strmap_t map,cs_instru_strips strip,cs_acpos_bkp acp
where c_int_instruid=c_srm_prncplinsid
and acp_acntnum!='SG030001'
and acp_instruid=c_srm_prntinsid
group by acp_instruid)view1;
dbms_output.put_line(bala);
select acp_instruid into ins1 from cs_strmap_t map,cs_instru_strips strip,cs_acpos_bkp acp
where c_int_instruid=c_srm_prncplinsid
and c_srm_prncplinsid=acp_instruid
and acp_acntnum='SG030001';
dbms_output.put_line('principal'||ins1);
select acp_instruid into ins2 from cs_strmap_t map,cs_instru_strips strip,cs_acpos_bkp acp
where c_int_instruid=c_srm_prncplinsid
and acp_acntnum='SG030001'
and acp_instruid=c_srm_prntinsid;
dbms_output.put_line('parent'||ins2);
update cs_acpos_bkp
set acp_totbal=-bala
where acp_instruid=ins2
and acp_acntnum='SG030001';
END;
i have written this code,i need to use cursor and for loops to get more than one rows and update also.
if there are more than 1 rows in cs_strmap_t,then the procedure throws an error stating that it cannot take 2 rows.
Edited by: 850836 on Apr 7, 2011 11:43 PMPROCEDURE "TEST" is
bala number;
ins1 number;
ins2 number;
CURSOR cur_1 IS
select sum(bal) bala from (select sum(acp.acp_totbal) bal,acp_instruid from cs_strmap_t map,cs_instru_strips strip,cs_acpos_bkp acp
where c_int_instruid=c_srm_prncplinsid
and c_srm_prncplinsid=acp_instruid
and acp_acntnum='SG030001'
group by acp_instruid
union
select sum(acp.acp_totbal) bal,acp_instruid from cs_strmap_t map,cs_instru_strips strip,cs_acpos_bkp acp
where c_int_instruid=c_srm_prncplinsid
and acp_acntnum='SG030001'
and acp_instruid=c_srm_prntinsid
group by acp_instruid)view1;
BEGIN
select acp_instruid into ins1 from cs_strmap_t map,cs_instru_strips strip,cs_acpos_bkp acp
where c_int_instruid=c_srm_prncplinsid
and c_srm_prncplinsid=acp_instruid
and acp_acntnum='SG030001';
dbms_output.put_line('principal'||ins1);
select acp_instruid into ins2 from cs_strmap_t map,cs_instru_strips strip,cs_acpos_bkp acp
where c_int_instruid=c_srm_prncplinsid
and acp_acntnum='SG030001'
and acp_instruid=c_srm_prntinsid;
dbms_output.put_line('parent'||ins2);
for var_for in cur_1
loop
update cs_acpos_bkp
set acp_totbal=var_for.bala
where acp_instruid=ins2
and acp_acntnum='SG030001'
and abs(acp_totbal)>abs(bala);
dbms_output.put_line(bala);
end loop;
END;
i wrote the following procedure,but the balance is not getting updated.
Getting this errors when there are more than 1 row in cs_strmap_t table
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: line 22
ORA-06512: at line 2 -
How to view the document in actual size (pixel perfect) in CC 10?
Hi there,
currently I'm working on a Mac with InDesign CC (10.0.0.07) and I use it for ui, so I need to view my document in the actual size (pixel perfect). In CS 6 I was able to double click on the zoom tool and my document showed up in like 74% or so and it was pixel perfect. This is what is really important when you use InDesign for screen layouts. And now with the new CC update I'm not able to do this anymore.
Has anyone a suggestion how to fix this, or has had the same experience? This is really essential for designing websites.
thanks,
Stefan@Stefan – this behavior has changed from CC v9.2 to v10.0.
To get what you want you need a ExtendScript (JavaScript) once written by John Hawkinson. That code snippet will change preference settings not exposed to the user, the Custom Monitor Ppi, to 72 ppi and enable their usage.
app.generalPreferences.customMonitorPpi = 72;
app.generalPreferences.useCustomMonitorResolution = true;
Before running the script, it would be best to check, how the actual values are with the following snippet:
alert(
"Custom Monitor PPI currently is set to: "
+app.generalPreferences.customMonitorPpi
+"\t\t"
+"Usage is set to: "
+app.generalPreferences.useCustomMonitorResolution
To change this behavior back to default, use the following line of code:
app.generalPreferences.useCustomMonitorResolution = false;
Uwe -
Error in actual template allocation for Business Process
Gurus,
I am facing a strange problem in actual template allocation for business process (T-code: CPAS). When I am doing a test run, the system gives the result with a message "Processing completed with no errors", However when I have unchecked the test run and ran the allocation, system shows me the result, however no posting takes place. The message I am getting is:
"Data not updated due to errors". The details of this error message are:
No information was found
Message no. GU444
Diagnosis
The system could not find the necessary information.
I am absolutely clueless and have no idea where things have gone wrong. I have maintained the activity and cost center properly. The template I am using is also ok.
Request your help on this. Any suggestion would be highly appreciated.
Thanks in advance!
Snigdho.Hi ,
With such kind of error " "Data not updated due to errors". " its very difficult so determine the exact cause of the issue .
Did your selection parameters in CPAS has a tick on detailed list . Please tick the detailed list icon and run KPAS again and let me know if you are getting more detailed error from SAP.
Regards
Sarada -
How to restrict data for selection
Hi, folk,
I've faced with the following issue.
I have set of items. There are, for example, income items and expense items.
Items are distinguished by value of attribute.
According to business process, planning for income and expense items is quite different. Due to this reason I've created two planning folders to process ones.
Item was placed into header of planning format.
Before planning I should select item. More over, for income planning I should select item from income subset.
So, how to based on value of attribute I can restrict items for selection in the planning folder.Easier impossible,
Rather than using a variable of type attribute I would use an variable of type exit.
The exit returns the full list of item in income or expense. (This depends on another variable, that could be a simple digit base or based on some other infoobject).
The variable should be assigned to your level and also available in the planning folder for selection.
The user will see the full list values and select the one he nedes to plan.
I hope it's clear.
Cheers,
Alberto -
Use of cursors insted of select statements
could any one please explain what is the advantage of using cursors instead of simple select statements
thanks
sibyA benefit to using an explicit cursor rather than a select statement, is for the NO_DATA_FOUND exception. Its kind of like a free IF statment. IF no data is found, then stop.
if you write a select statement, and no data is returned, you SHOULD code for the NO_DATA_FOUND exception. Often people say, "i'll ALWAYS get a row returned". but you should always cover your code "just in case". so you must code an exception...
declare
v_var varchar2(1);
procedure do_something(p_parm varchar2) is
begin
null;
end do_something;
procedure log_error is
begin
null;
end log_error;
begin <<main>>
do_something('x');
begin <<selectblock>>
select dummy
into v_var
from dual
where dummy = 'a';
do_something(v_var);
exception
when no_data_found then
log_error;
end selectblock;
do_something (v_var||'abc');
end main;
if you use an explicit cursor instead, you don't need to code for the NO_DATA_FOUND. If an explicit cursor opens and finds no rows, there are simply no rows. of course, you don't need a loop if you expect only 1 row returned under normal circumstances.
BTW, don' forget that SQL%ROWCOUNT and your_cursor%ROWCOUNT are not initialized. There is a null, until a row is successfully fetched. therefore if no rows are returned at all, %ROWCOUNT is NULL.
declare
v_var varchar2(1);
cursor my_cur is
select dummy
from dual
where dummy = 'a';
procedure do_something(p_parm varchar2) is
begin
null;
end do_something;
procedure log_error is
begin
null;
end log_error;
begin << main>>
for cur_rec in my_cur loop
dbms_output.put_line('inside');
begin <<loop_block>>
if nvl(my_cur%rowcount,0) > 1 then
do_something(cur_rec.dummy);
else
log_error;
end if;
end loop_block;
end loop;
end main;
/ -
Cursor with for update clause problem
Hi all,
We are having this problem with Oracle 8.1.7 where in we have a cursor with for update clause. The PL/SQL script used to work fine with Oracle 8.0.5 but is causing problems with Oracle 8.1.7. What the script is ending up doing in 8.1.7 is that it updates only one record instead of updating close to 60000 which it used to do in Oracle 8.0.5
The script just hangs after updating one record. We have replicated the same problem.
Has anyone seen this error before and attained resolution?
ThanksHello ,
I have found the same / very close to the same problem. I tried the code below in Oracle 10.2.0.1 and got the following error after the first loop.
ORA-01002: fetch out of sequence
ORA-06512: at "DEMO_TEST_RESEARCH_PKG", line 18
ORA-06512: at line 7
After trying to debug it , i thought i would try it in Oracle 9.0.2.0.7.0 , and to my suprise it worked fine.
Am i missing something ? Thanks in advance , ...
I have included the code i was running ...
PROCEDURE WhereCurrentOf(Param1 IN NUMBER) IS
v_title_eng ISSUES.TITLE_ENG%TYPE;
v_issue_id ISSUES.ISSUE_ID%TYPE;
CURSOR issues_cur
IS
SELECT issue_id,title_eng
FROM issues
WHERE title_eng IS NULL
FOR UPDATE OF title_eng;
BEGIN
FOR i IN issues_cur
LOOP
FETCH issues_cur INTO v_issue_id,v_title_eng;
EXIT WHEN issues_cur%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(v_issue_id||' This was the english title before : '||v_title_eng);
v_title_eng := 'This is my title';
UPDATE issues
SET title_eng = v_title_eng
WHERE CURRENT OF issues_cur;
DBMS_OUTPUT.PUT_LINE(v_issue_id||' This is the english title after : '||v_title_eng);
END LOOP;
END WhereCurrentOf; -
What makes a field eligible for selecting data in a subreport?
Hello,
I have posted the following question to [StackOverflow|http://stackoverflow.com/questions/4366702/what-makes-a-field-eligible-for-selecting-data-in-a-subreport], but it has so far generated no replies. I decided to cross-post it here to see if I could get a better result.
The TL;DR of it is that I have a field which I should be able to link in my Subreport, but it does not appear, and I was wondering what I need to do to make it appear.
I have a Crystal Report I'm trying to recreate from scratch after an update from VS2008 to VS2010 caused it to implode horribly.
I've gotten most of the way through, but I'm at a stage where I'm linking a field in the Main Report to a corresponding field in the Subreport.
I have set up a bunch of Database fields in the Subreport, I've added the table I want, TableA, I've linked it up as everything was linked in the original report, with TableA at the head of the linking chain, so that all the rows I want can be derived from the result of that first query ( Actually, all of the links from the original Report were red in the Database Fields linking dialog, whereas mine are a bit rainbow-y. All the links in TableA are red, though... _ )
In the "Subreport Links" dialog, I have an integer which I know is being pulled from the database correctly. I've added it in the "Fields to link to" listbox, and selected the newly-created parameter in the "Subreport parameter to use" combobox. I've ticked the "Select data in subreport based on field" checkbox.
The database field I want to link to then does not appear in the second combobox.
Another integer field in TableA shows up fine in the "Select data..." combobox (and is linked to another field being passed in), so I don't know why these two integer fields, which are equally important, and exist on the same level, on the same table, are being treated differently by the report designed.
Any ideas what I'm doing wrong?Here is what I'd do:
1) Download CR 2008 eval designer from here:
http://www.sap.com/solutions/sapbusinessobjects/sme/freetrials/index.epx
2) Try the linking in CR 2008 designer
3) If it does not work there, ask why not in the [CR design|SAP Crystal Reports, version for Visual Studio; forum.
4) If you get the linking working in the CR 200 designer, try to run the report in your VS2010 app (after ensuring the report woks as expected in CR 2008).
5) If (4) above works out for you, please let me know as this may be an issue with CRVS2010.
Ludek
Follow us on Twitter http://twitter.com/SAPCRNetSup
Got Enhancement ideas? Try the [SAP Idea Place|https://ideas.sap.com/community/products_and_solutions/crystalreports]
Maybe you are looking for
-
Today I received a confidential email from "AppleSeed Software Customer Seeding". The message, which was entitled "Mac OS X Lion Invitation", invited me to participate in an OS X Lion seeding project. In order to respond, I am instructed to visit a c
-
Using Crystal Report to create reports from ABAP
Hello, We are currently using Jetform as the designer for our outputs like Invoice, Order confirmation, etc..... We would like to switch to Crystal instead, but don't really know where to start from. - We already have crystal on our B/W instance - Th
-
Insert Current Date into text Field
Hi I was wondering if anyone knows how to insert the current date into a text field using ASP.NET C# page. When the page loads. Or better still insert current date into my database when the page is updated. using the insert Server behavier. I would b
-
Creating Inbound IDoc - IDOC_INBOUND_SINGLE Help needed
Hi all, I am using IDOC_INBOUND_SINGLE to create inbound IDoc. Its creating the IDoc and processing successfully. But this FM only returns IDoc number and not the processing errors if there are any. Any way to get processing errors also? Your help wo
-
Wheres the delete key on my macbook?
hi there, i've just been trying to use shortcuts more often because they make life a **** of alot easier, but where is the delete key on my keyboard? i can see it on my step dads iMac keyboard but there isn't one on my macbook keyboard. is there a ke