SQL logical support for pl/sql block
Hi allI have need of your suggestions and comments for the below question:
I have two tables: table A and table b.
Table has two columns as id and charges:
Counties of ID
-------------------------
99 10
13 999
9999 7
Table B has two columns Id and stopped:
Order of identification
_______________
99 1
2 999
3 9999
We need update of the order in the Table B such that Id with the highest number in table A stopped as 1 in the table B and it continue to increase enforcement for other Ids based on reducing the counts in table A. It will be like a job serving daily and search counts in table A and update the order in table B, according to her.
It seems simple, but I don't get it. Please help me on this by writing a PL/SQL block.
I'd really appreciate all your comments and your responses.
Concerning
Dev
Hello
Here's a way to do it:
MERGE INTO stat dst
USING (
SELECT s.id
, ROW_NUMBER () OVER ( ORDER BY SUM (m.counts)
DESC
NULLS LAST
) AS orders
FROM stat s
LEFT OUTER JOIN main m ON s.id = m.id
GROUP BY s.id
) src
ON (src.id = dst.id)
WHEN MATCHED THEN UPDATE
SET dst.orders = src.orders
;
As you can see, it is similar to the solution to your original problem.
In the original problem, id in the table (primary) source was unique; now, it is not, and we are interested in the SUM of all values of counts, so we can use GROUP BY and the SUM aggregate function. When used in the same query, aggregation (such as the SUM above) functions are calculated before analytical functions (for example, ROW_NUMBER), so the aggregate functions can be nested within analytical functions.
The big change is that now the subquery source produces a line for each stat line, or not this ID exists in the hand, and he ignores any ID at hand which does not exist in stat, using an outer join. "stat LEFT OUTER JOIN main" means that all ranks of stat will appear in the results, even if there is no game in hand, but the bottom lines will be in the results only if they have a match in the stat.
ROW_NUMBER assigns unique, coinsectuive whole, exactly as you requested. If there is a tie (two or more ID having exactly the same SUM (account)) then ROW_NUMBER will assign numbers separate, consecutive lines. It will be arbitrary in what id receives the lower number.
Tags: Database
Similar Questions
-
TMS support for SQL (standard/express) 2012
Is there a timetable yet for 2012 SQL support for MSDS? I have a situation where he would have preferred to use SQL 2012 rather than 2008.
That said, someone has actually tried it and if yes are there any problems or "traps"?
I guess while I'm, what about Windows Server 2012 support?
Hello Anthony.
Research on forums a few Windows and SQL 2012 support questions. This is a debate which answer your questions both...
-
PDF IFilter support for 8.1 Windows and SQL Server 2014
Hello
We use Adobe PDF iFilter Version 64 11.0.01 (here: https://www.adobe.com/support/downloads/detail.jsp?ftpID=5542) full-text support for PDF files on SQL Server and Windows Server 2012 2012. This works also on Windows Server R2 from 2012 to 2014 of SQL-Server even if both is not listed in the list of the applications/OS supported. But it does not work for the combination of 8.1 to Windows and SQL-Server, 2014.
Can anyone provide a solution to make it work for this combination, or know when it will be officially supported?
Kind regards
Stefan
Hi stefankainz663,
Please see this KB for the workaround iFilter PDF search doesn't work on Windows 8 x 64.
Kind regards
Nicos -
SQL Developer 3.0 EA 1 Advanced support for the type of data in the unit tests
Hello
According to SQL Developer 3.0 EA 1 New Feature List (http://www.oracle.com/technetwork/developer-tools/sql-developer/rel3-featurelist-ea1-166831.html#ut)
the EA 1 version 3.0 supported advanced data types in the unit tests. This means support the ANYDATA and RECORD types? I installed version 3.0 of EA 1 to CentOS linux, but it seems that those advanced types are not supported yet. When I try to add a unit test for a function that returns the record type, I get quick error: "the return of PL/SQL RECORD type is not supported. Cannot test (function_name) because 1 arguments have not supported for types". Also if I try to unit test procedure which parameter is of type ANYDATA, I get quick error: "the type UNDEFINED P_DATA argument is not supported. Cannot test (procedure_name) because 1 arguments have not supported for types". Are those advanced data types supported in SQL Developer 3.0 FINAL version?
Thank you
Miikka L
Edited by: user12844253 the 27.10.2010 16:31Hi Mikka,
Only simple PL/SQL records are currently supported i.e. those containing no optional or repeating components and where all components are themselves supported. This restriction is in place, due to the fact that we are using JDBC as a parameter mechanism which does not directly support the passage the PL/SQL record type.
ANYTYPE and ANYDATA are currently not supported because they have a dynamic value type and must be set programmatically. In the future, it would be possible to support these via the dynamic value and and validation features.
This will remain for the final version.
Kind regards
Richard -
Where the conditional, or PL/SQL block as a source for an interactive report?
I have this situation: my app's main screen displays a list of documents. For now, there must be a quick way to 'security' integrated, so that administrators can see all documents, but only other users can see what documents, they created (connection of the creator is stored in the table of documents). In the future we will use probably VPD to enforce certain rules, but for the moment we need a quick solution.
So I stored administrators in a separate table. Now I want the interactive Act report on the homepage as follows:
-If an admin is connected, it must have this query: select field 1, 2, 3 area in documents
-For all other users: select the field 1, 2, area 3 documents where creator =: app_user
Is this possible in a single interactive report? I could do two reports with different queries, and make conditional depending on who is connected, but this gives me two interactive reports to maintain. Is it possible to use a PL/SQL block as a source for the report? I tried, but I get a syntax error. Is it possible to do where proviso on somehow?Hello
Install the demo application to your workspace:
Home > create an Application and select Demo Application.Check page 1 interactive report. This should give idea how.
BR, Jari
-
Hi all. I'm on oracle 9i.
I have a problem: I start my sql file, which has a share of some SQL commands and in it there is a part which is a PL/SQL block.
What I want is that if a certain if the condition is verified, he must get out of the PL/SQL block and also he must leave all files!
Here is a part of the code:
drop table test1;
create table test1
in select * from test2;
create the table prova_test1
in select * from test_1
where 1 = 2;
DECLARE
number of account: = 0;
Valore number: = 0;
contap number: = 0;
valorep number: = 0;
Stop varchar2 (2000): = null;
BEGIN
Select count (1), sum (val) contap, valorep
of prova_test1;
Select count (1), sum (val) in conta, valore
of test_1;
If conta <>contap or valore <>valorep then
Training: = "exit";
run immediately stop;
on the other
other sql statements.
....
....
end if;
end;
/
So what I want is that if the condition is true, he must get out of pl/sql block and the entire process.
How can I achieve that?
Thank you for the collaboration,
FabrizioSimply - what you want to do is not easy to do because you mix server with client code code and wait for the two to work in perfect harmony as if it were a single whole. It is not the case.
PL/SQL code is sent to Oracle and PL/SQL anonymous blocks. They are analysed. Executed. Then, control is returned to SQL * more. SQL * more is do not have a "programming language" - it has a few macro commands. It does not support conditional processing logic (there is no IF command in SQL * more).
To achieve what you want, you need to tell SQL * over how to respond to the mistakes of the Oracle server. Should continue despite the error? Should it end?
For example
-- // client call whenever sqlerror continue -- // server call: should this result in an error, continue processing drop table foo; -- // client call whenever sqlerror exit failure -- // server call: should this result in an error (exception), terminate processing begin .. pl/sql code.. end; / ..etc..
Very sure that you do not confuse the side Server and client - side you need to know exactly what is running on the server (SQL and PL/SQL) and how the client makes the call to the server, and how he responds after the call to the server is made.
-
First execution of pl/sql block is slow.
Hello
I've implemented TimesTen to improve performance of an Oracle pl/sql block.
To do this, I created some cachegroups in TimesTen for caching oracle data.
After everything is done on TimesTen, when we execute the pl/sql block on TimesTen, I observed that it took 35 seconds for the first run time on Timesten (compared with 48 seconds on Oracle). The next run of the same pl/sql block with the same parameters take only 6 seconds. I want to achieve the same flow rate (6 sec) when the pl/sql block is executed for the first time. Can you please suggest what exactly I should look into.
Thank you
Amit
Ye, it's a phenomenon known as I mentioned, but the 'hit' on the first run is usually not nearly this big. However, Windows as a platform is suffering more than most from this phenomenon and also Windows supports only not MemoryLock = 4, which further compounds the issue.
Would you happen to have an available Linux system where you could test this with MemoryLock = 4, just so we can see what the difference between Linux and Windows? I think it would be a very useful thing to study to quantify how much this is due to Windows itself.
A 'workaround' could be just application make a 'fake' execution of the PL/SQL procedure, immediately after I start and then all 'real' subsequent executions will be fast.
Chris
-
change a pl/sql block using "bulk collect.
Hello
I have a pl/sql block, short it slows...
DECLARE
CURSOR CURUPDATE1 IS
SELECT MF_TJ. UID_LO
OF MF_TJ
WHERE MF_TJ. DTYP (SELECT CD
OF MF_DOC_TYPE
WHERE MF_DOC_TYPE. DTYP_CAT = 'xx')
AND MF_TJ. LINE_TYP IS SET TO NULL;
BEGIN
FOR T IN CURUPDATE1
LOOP
UPDATE MF_TJ
THE MF_TJ VALUE. LINE_TYP = "NR."
WHERE MF_TJ. UID_LO = T.UID_LO;
UPDATE MF_AJ
THE MF_AJ VALUE. LINE_TYP = "NR."
WHERE MF_AJ. TJ_UID_LO = T.UID_LO;
END LOOP;
END;
/
now I change to use bulk collect, but I split it into two pl/sql blocks (each for an update)
DECLARE
CURSOR CURUPDATE1 IS
SELECT MF_TJ. UID_LO
OF MF_TJ
WHERE MF_TJ. DTYP (SELECT CD
OF MF_DOC_TYPE
WHERE MF_DOC_TYPE. DTYP_CAT = 'xx')
AND MF_TJ. LINE_TYP IS SET TO NULL;
TYPE of recs_type IS the TABLE OF CURUPDATE1% ROWTYPE directory INDEX;
REB recs_type;
BEGIN
CURUPDATE1 OPEN;
Go SEARCH the CURUPDATE1 COLLECT in BULK IN REB 8000 limit;
CLOSE CURUPDATE1;
FORALL i IN 1.recs. COUNTY
UPDATE MF_TJ
THE MF_TJ VALUE. LINE_TYP = "NR."
WHERE MF_TJ. UID_LO = (i) recs. UID_LO;-END;
/
DECLARE
CURSOR CURUPDATE1 IS
SELECT MF_TJ. UID_LO
OF MF_TJ
WHERE MF_TJ. DTYP (SELECT CD
OF MF_DOC_TYPE
WHERE MF_DOC_TYPE. DTYP_CAT = 'xx')
AND MF_TJ. LINE_TYP IS SET TO NULL;
TYPE of recs_type IS the TABLE OF CURUPDATE1% ROWTYPE directory INDEX;
REB recs_type;
BEGIN
CURUPDATE1 OPEN;
Go SEARCH the CURUPDATE1 COLLECT in BULK IN REB 8000 limit;
CLOSE CURUPDATE1;
FORALL i IN 1.recs. COUNTY
UPDATE MF_AJ
THE MF_AJ VALUE. LINE_TYP = "NR."
WHERE MF_AJ. TJ_UID_LO = (i) recs. UID_LO;-
END;
/Is there a way I can just use pl/sql block using bulk collect?
Thank you very much
Hi 5181139
As Paulzip and Jarkko Turpeinen have pointed out, you could do it using only SQL...
This is a course using COLLECT in BULK:
DECLARE blimit CONSTANT PLS_INTEGER := 500; CURSOR curupdate1 IS SELECT MF_TJ.UID_LO FROM MF_TJ WHERE MF_TJ.DTYP IN (SELECT CD FROM MF_DOC_TYPE WHERE MF_DOC_TYPE.DTYP_CAT = 'xx') AND MF_TJ.LINE_TYP IS NULL; TYPE c_arr IS TABLE OF curupdate1%ROWTYPE; c_rows c_arr; BEGIN OPEN curupdate1; LOOP FETCH curupdate1 BULK COLLECT INTO c_rows LIMIT blimit; FORALL i IN c_rows.FIRST..c_rows.LAST UPDATE MF_TJ SET MF_TJ.LINE_TYP = 'NR' WHERE MF_TJ.UID_LO = c_rows(i).uid_lo; FORALL i IN c_rows.FIRST..c_rows.LAST UPDATE MF_AJ SET MF_AJ.LINE_TYP = 'NR' WHERE MF_AJ.TJ_UID_LO = c_rows(i).uid_lo; EXIT WHEN c_rows.COUNT < blimit; END LOOP; CLOSE curupdate1; END;
See you soon,.
Gas
-
Huge performance difference between stored proc and anonymous PL/SQL block. Why?
Hello! I searched various online resources and have been unable to find those who have addressed this problem, so I hope that someone here may be able to offer advice.
I have a stored procedure that is approximately 300 lines long, takes no parameters, and sets a record and a few types of internal tables. When I run it on a particular data set, it takes about 50 seconds at the end of my environment. Unfortunately, it will have to be performed as a block anonymous PL/SQL instead of a stored procedure, because of the policies that exist about the environment which I deployment. However, when I converted it to an anonymous PL/SQL block, make no other code changes whatsoever and it connecting the same schema that belongs to the stored procedure, it takes about 6.5 minutes (nearly 8 times as long) to complete. Aside from the burden of analysis and validation, which could add a fraction of a second, can someone please suggest some possible reasons for the large performance difference and offer advice on what I can do about it? In which case it is important, the procedure uses in bulk binds (for example, in bulk collect, forall) where it makes sense and doesn't call other objects in PL/SQL. Thanks in advance.
Without seeing your code, it is difficult for me to contribute more.
Note also that...
1 roles are turned on in the anonymous blocks but not (at least not by default) in the stored procedures. This is why the anonymous block could have MORE rights (those granted through roles) probability that you can get more items through anonymous block.
2. ensure that, in both cases, it does reference the same target tables.
Debug by calculating the difference of time after certain steps in your code. Who should get an idea on this or activate the trace.
-
Error when you try to create a region of the page generated by the anonymous pl/sql block
Hi guys I tried to create a region of the page which is the source and anonymous pl/sql block and I have been making a few mistakes. Basically what I want this region to do, is to give the current user of the application one summarized data compared to there user name which is: app_user the code I used was
declare
ven_ret varchar2 (15);
BEGIN
ven_ret: = (select u.vendor of USERS4ARCHITEC u )
where
u.e_mail = V ('APP_USER')
and not exists (select null from arch_tbl I where u.vendor = i.vendor and user_id = V ('APP_USER'))
order u.vendor in ven_ret);
END;
/
the structure of the table to the USERS4ARCHITEC table is
User varchar2 (15) vendor2 (20)
----------------------------------------------------------------------------------
user@1 sap
user@1 oracle
user@1 IBM <---------sample data
user@2 Oracle
user@2 cisco
the structure of the table to the arch_tbl table is
user vendor
--------------------------------------------------------------
user@1 sap
So if user@1 logs in the application of the region using the pl/sql code code above should display oracle and IBM, because these two sellers are always under his username that he has already used a form to insert the sap into the arch_tbl table. Please tell me what I'm doing wrong here. Thank you guys
Why would you build a type psedu at APEX report MANUALLY when you can just build a relationship with the same selection you use now for your pl/sql dynamic region? What is the purpose of building your own report when the tool made for you?
Thank you
Tony Miller
Software LuvMuffin
Ruckersville, WILL -
"Declaration of execution" and anonymous PL/SQL blocks
I often use control - enter to execute the statement that the cursor is currently over. Normally, this works very well. But it's a little twisted once I added an anonymous PL/SQL block to the worksheet. As long as the anonymous block is the last thing on the spreadsheet, I can "run statement" as usual. But if I add a SQL queries after an anonymous block and try to run the statement, rather than just the running query, SQL Developer aims apparently to compile everything since the beginning of the first anonymous block until the current as a block statement.
For example, if I have a spreadsheet as follows:
SELECT 1 FROM DUAL; --run statement on this line works as expected, running just this query BEGIN --run statement anywhere within this block works as expected, running just this block DBMS_OUTPUT.PUT_LINE('X'); END; SELECT 1 FROM DUAL; --run statement on this line goes back to the "BEGIN" on line 3 and gives a compilation error
It is a nuisance major for me, as I have often a mixture of SQL and anonymous blocks on a worksheet. I know that I can point out that the code I want and execute statement in this way, but I'd rather not have to do. I was expecting that developer SQL would be smart enough to know where each block begins / ends and realize my current statement is not part of the block above him. Is there a setting that can change this behavior? Or is it the way it is supposed to work?
Whatever it is, thanks for the excellent tool.
Add a ' / ' at line 5 and line 5 to line 6 bump
-
Oracle report calling in a PL/SQL block
Hi all
I need to call an Oracle (10g Developer Suite) report in a PL/SQL block. I read online that the same can be achieved using the utl_http package.
Are there documents or links that tells how the above is achieved with an example? Also how to set the URL of the report?
Oracle DB Version: 10.2.0.5.0
Thanks in advance.
AKS
Use the package instead of srw. It is easier to use and has good debugging options:
With the help of event publication
(it is 11g manual, but it's the same thing for 10g).
-
to change the pl/sql block to get the value of the user
In this code rather than affect the value of the SID in the block, I want to get the sid of the user.
Help, please.
Oracle Database 10 g Express Edition Release 10.2.0.1.0 - product PL/SQL Release 10.2.0.1.0 - Production CORE 10.2.0.1.0 Production AMT for 32-bit Windows: Version 10.2.0.1.0 - Production NLSRTL Version 10.2.0.1.0 - Production declare
v_sname t1.sname%type;
v_issue_date t3.issue_date%type;
v_book_title t2.book_title%type;
v_book_id t2.book_id%type;
cursor c1 is
Select t1.sname, t3.issue_date, t2.book_title, book_id
join T1 T3
using (SID)
Join t2
using (book_id)
where sid = 1;
Start
Open c1
loop
dbms_output.put_line (v_sname |) » ' || v_issue_date | » ' || v_book_title | ' ' || v_book_id);
extract the c1 in v_sname, v_issue_date, v_book_title, v_book_id;
When exit c1% notfound;
end loop;
Close c1;
end;
/
Thank you
If I set up a script that I want to pass a value, I just a configuration variable and name it and use it very similar to a procedure or function. Makes it easy to implement a procedure/function, or to convert a function/procedure in a PL/SQL block for test/debugging with relatively few changes to the code inside:
declare in_sid number := to_number('&1'); v_sname t1.sname%type; v_issue_date t3.issue_date%type; v_book_title t2.book_title%type; v_book_id t2.book_id%type; cursor c1 is select t1.sname, t3.issue_date, t2.book_title, book_id from t1 join t3 using(sid) join t2 using(book_id) where sid=in_sid; begin open c1 loop dbms_output.put_line( v_sname ||' ' || v_issue_date ||' ' || v_book_title || ' ' || v_book_id); fetch c1 into v_sname, v_issue_date, v_book_title, v_book_id; exit when c1%notfound; end loop; close c1; end; /
-
Ignore the error and continue the pl/sql block
Dear all,
Please help me to fix the script below.
I had an obligation to write a pl/sql that will handle the update instructions.
For example:
A table that contains 10 rows of data. Through pl/SQL block, I update the 10 rows (or a smaller number of lines).
Now, the scenario is by updating registration / line 4, oracle has met an error and then oracle leave pl/sql block and cancel the transaction.
My requirement here is, by updating the records, if oracle encounters an error, it must raise an error or ignore the record and continue to process records. Oracle wouldn't pl/sql block.
We are using oracle 10g.
Thank you
KODSAs has already been suggested, you might check DML ERROR LOGGING
-
Select the query within the PL/SQL block.
Hello Experts,
I'm just a beginner with PL/SQL.
If I write a select query of client like fire against a database and SQL dev, it gives me result.
For example: select * from employee;
Now suppose that when I use the same query within a PL/SQL block:
Declare
Start
Select * from employee;
end;
/
It gives error during execution, by mentioning that an INTO should etc...
I have my doubts here:
1. is it impossible to use a simple select statement within a PL/SQL block (If yes why?)
I know it's a very basic question, I tried to search it on the forum but could not find the thread, please redirect me to the link if it is already the answer.Please read this first. may ask why?
http://docs.Oracle.com/CD/B28359_01/AppDev.111/b28370/TOC.htm
Maybe you are looking for
-
Satellite Pro P300-1ES (PSPCDE) - speed with W - LAN problem
Hello just got my new laptop Toshiba (see subject). Unfortunately, I had a big problem with the W - Lan laptop speed. Compared to my old laptop (satellite Pro A120, with a chip of WLAN Intel 3945) the new laptop (with a chip Atheros AR9281) scores on
-
Satellite A300 - startup repair does not work
When I went to use the Startup Repair option in the advanced boot options at startup that he told me that the application cannot run and shut down the computer. I have a laptop Satellite A300-1OM.
-
Satellite L30 - 11 d: update Bios to boot from USB
I have a Satellite L30 11(d) bought Sept 07. I'm interested in trying to boot from USB, at the present time, my bios does not.I am looking to update my bios. There is a updated bios updated for me to download (3.10WIN). I have 3 questions: (1) 3.10WI
-
Recently, I transfer my Labview file to a new computer. My set up has the following features, FP-1000F P-RTD-122 and FP - RLY-422. I installed the latest driver of the Fieldpoint, however, when I try to run my file. It says "cannot locate the file of
-
I can't update to Windows XP (KB2656369) - the site has encountered a problem
I can't update Windows XP. I scanned the various suggestions and tried several proposed solutions, nothing helps. For example, I used various Microsoft 'FixIt' 'solutions '. They fix anything, even if at some point, the computer ran at 50% of CPU