selection of the results aggregated into a PL/SQL block gives me ORA-00934
HelloI have a simple table of objects on the map that were inclusive. That is to say:
CREATE TABLE tbl (
id NUMBER(11,0), -- Id of this record
parentId NUMBER(11,0), -- Id from some parent table
bb_sw_lat FLOAT, -- SW bounding box corner - Latitude
bb_sw_lng FLOAT, -- SW bounding box corner - Longitude
bb_ne_lat FLOAT, -- NE bounding box corner - Latitude
bb_ne_lng FLOAT -- NE bounding box corner - Longitude
);
INSERT INTO tbl VALUES (1, 1, 10, 10, 20, 20);
INSERT INTO tbl values (2, 1, 5, 5, 35, 35);
INSERT INTO tbl values (3, 1, -5, -20, 0, 0);
INSERT INTO tbl VALUES (4, 2, 9, 9, 10, 10);
INSERT INTO tbl values (5, 2, 1, 1, 1, 1);
I can query the number of entries for a parent entity and the use of aggregate functions calculate the framework encompassing total for the parent entity:SELECT
count(*),
NVL(MIN(bb_sw_lat),0),
NVL(MIN(bb_sw_lng),0),
NVL(MAX(bb_ne_lat),0),
NVL(MAX(bb_ne_lng),0)
FROM tbl
WHERE parentId=1;
but the same select cannot be put to the PL/SQL block:DECLARE
cnt NUMBER;
sw_lat FLOAT; sw_lng FLOAT; ne_lat FLOAT; ne_lng FLOAT;
BEGIN
SELECT
count(*) INTO cnt,
NVL(MIN(bb_sw_lat),0) INTO sw_lat, -- ORA-00934: group function is not allowed here
NVL(MIN(bb_sw_lng),0) INTO sw_lng,
NVL(MAX(bb_ne_lat),0) INTO ne_lat,
NVL(MAX(bb_ne_lng),0) INTO ne_lng
FROM tbl
WHERE parentId=1;
END;
can someone please explain to me why and what to do with it? Examples are executable as they are, it should be fairly easy to reproduce.Thank you very much!
Kuba
Published by: user3620664 on May 14, 2009 02:14 added formatting
without testing, just an IN
DECLARE
cnt NUMBER;
sw_lat FLOAT; sw_lng FLOAT; ne_lat FLOAT; ne_lng FLOAT;
BEGIN
SELECT
count(*),
NVL(MIN(bb_sw_lat),0),
NVL(MIN(bb_sw_lng),0),
NVL(MAX(bb_ne_lat),0),
NVL(MAX(bb_ne_lng),0)
INTO cnt,
sw_lat,
sw_lng,
ne_lat,
ne_lng
FROM tbl
WHERE parentId=1;
END;
Published by: Alex Nuijten on May 14, 2009 11:19
Tags: Database
Similar Questions
-
How to do a select on the results of a stored procedure?
Hello
I am new to Oracle. I work with SQL Developer.
I'm doing a simple select on the results of a stored procedure call. I don't know how to do it. Here's what I have so far:
declare
type ref_cursor is ref cursor;
results ref_cursor;
Start
MyStoredProcedure (123 results);
Select * from results;
end;
/but he said to me:
Error from the 1 in the command line:
declare
type ref_cursor is ref cursor;
results ref_cursor;
Start
GET_TAX_TYPE_BY_TAX_ENTITY_KEY (60670100000000, results);
Select * from results;
end;
Error report:
ORA-06550: line 6, column 15:
PL/SQL: ORA-00942: table or view does not exist
ORA-06550: line 6, column 1:
PL/SQL: SQL statement ignored
06550 00000 - "line %s, column % s:\n%s".
* Cause: Usually a PL/SQL compilation error.
* Action:Obviously, select * results; is not the right way to do it. But what is?
Thanks for any advice forthcoming.
If a SQL cursor is built by a reporting system, a Java application, a c# program, or a PL/SQL call - the database doesn't care, because he doesn't know the difference. A Select SQL cursor created in PL/SQL through the ref cursor interface, won't be faster than the same SQL select in Eclipse. If the SQL source code is the same, the same cursor SQL program will be used by both.
What give you BIRT is the flexibility of the use of code Server (PL/SQL) to create the slider - this code doing business and technical decisions on how to design side than SQL, Select. Which is a good thing because it summarized the data model and the complexity BIRT server technique.
So my choice would be to use the procedural interface and return to the reporting system for the rendering of the ref Cursor.
The question of a slider running via the slider (selection of a cursor), is questionable. Yes, there are a set of specifications that allows to do this kind of thing. But it must be very firmly justified and careful design because it really is an exception. I personally (blame my DBA) would need a justification because it is much more of an exception. I have never seen it put in place in production in more than a decade of DBA'ing, despite the developers try to use such a hack - as it has always been much more powerful and the deployment of alternatives.
The concept for robust and efficient code for Oracle is: Maximise SQL. Minimize the PL/SQL (or Java / c# / etc.).
That means when it comes to database power, write an SQL program to do. Stop thinking of SQL as a language of data recovery a single simplistic statement. Think of it as a programming language. Extremely complex problems can be resolved with a single SQL, which requires easy code 100 + lines of PL/SQL, Java, or c#. Write SQL programs. Not SQL one-liners for a grinding program PL/SQL or Java data.
Why then PL/SQL? It is the best language to manage the creation of SQL, dealing with the process flow, conditional processing, and so on of exception handling. It is less than SQL (such as Java and c#) in the treatment of the data.
-
assign the value to a selection of the result of a query control
I want to assign a value to my controls with the result of the query.
It works for CFINPUT TEXT, but it does not work to SELECT
I want to know are there any way tp affect my drop-down list value based on the result of questy.
I have CFSTOREPROC as follows:
< cfstoredproc procedure = "PSP" >
< cfprocparam value = '#form. "IDNumber #" CFSQLTYPE = "cf_sql_integer" >
< name cfprocresult = resultset "spResult" = "1" >
< / cfstoredproc >
< type CFINPUT = 'text' id = "txtIDNumber" value = "" #spResult.IDNumber # "/ >"
I am able to name a TEXT of ENTRY CF as above the code value,
< select id = "lstNumber" value = "#spResult.lstNumber #" > < / select >
but it does not affect the value of my result of the query to SELECT entry.
Is it possible to assign a value to the query result SELECTION control?
I tried to use JavaScript that works if I pass a number, but it does not work if I pass a query result,
Your help is very appreciated,
Kind regards
Iccsi,
@Iccsi,
My bad! Yes, you will either need to the CFOUTPUT tag (that you commented out in your code) but without specifying a query or change the CFLOOP query CFOUTPUT = "Notes". If one of these should work:
OR
-Carl V.
-
How to test different Select into a PL/SQL block?
Hello
I'm relatively new to PL/SQL and I'm doing several int selects only one PL/SQL block. I am faced with the fact that if a single select statement returns no data, I have to go to the when exception DATA_NOT_FOUND.
Or, I would test selects different.
In an authentication script, I'm looking for a table for a USER ID (USERID) and an ID application, to check if a user is registered under this username for this APPLICATION.
There are different possibilities: 4 possibilities:
-Existing USER name or do not exist and
-Aplication ID found or not found for this particular USER ID.
I would test teas 4 possibilities to obtain the status of this user do regardin this application.
The problem is that if a select returns no rows, I'll not found exception data.
In the example below you can see that if no line is returned, with the exception
I would like to first of all make this statement:DECLARE P_USERID VARCHAR2(400) DEFAULT NULL; P_APPLICATION_ID NUMBER DEFAULT NULL; P_REGISTERED VARCHAR2(400) DEFAULT NULL; BEGIN SELECT DISTINCT(USERID) INTO P_USERID FROM ACL_EMPLOYEES WHERE USERID = :P39_USERID AND APPLICATION_ID = :APP_ID ; :P39_TYPE_UTILISATEUR := 'USER_REGISTERED'; EXCEPTION WHEN NO_DATA_FOUND THEN :P39_TYPE_UTILISATEUR := 'USER_NOT_FOUND'; END;
Do this if the user is found:SELECT DISTINCT(USERID) INTO P_USERID FROM ACL_EMPLOYEES WHERE USERID = :P39_USERID
etc...SELECT DISTINCT(USERID) INTO P_USERID FROM ACL_EMPLOYEES WHERE USERID = :P39_USERID AND APPLICATION_ID = :APP_ID ;
Basically, I don't want to go to the not found exception before you have tested the 4 possibilities.
Do you have a suggestion?
Thank you very much for your help!
ChristianIf you I had to check several conditions, this is how I would do:
DECLARE P_USERID VARCHAR2(400) DEFAULT NULL; P_APPLICATION_ID NUMBER DEFAULT NULL; P_REGISTERED VARCHAR2(400) DEFAULT NULL; BEGIN SELECT USERID , MAX(DECODE(application_id, :APP_ID, :APP_ID)) app_id_valid INTO P_USERID , P_APPLICATION_ID FROM ACL_EMPLOYEES WHERE USERID = :P39_USERID GROUP BY USERID IF P_APPLICATION_ID IS NULL THEN :P39_TYPE_UTILISATEUR := 'NOT REGISTERED TO APPLICATION_ID'; ELSE :P39_TYPE_UTILISATEUR := 'USER_REGISTERED'; END IF; EXCEPTION WHEN NO_DATA_FOUND THEN :P39_TYPE_UTILISATEUR := 'USER_NOT_FOUND'; END; /
not tested
C.
-
Concatenate the result set into a SQL string
Hi, I need help with the concatenation of a result set in order to avoid the duplication of data.
I have 3 tables:
SCRIPT
ID - number PK
DATE - day
TITLE - Varchar2
AUTHOR
A_ID - number PK
A_Name - Varchar2
SCRIPT_AUTHOR
ID - number - PK, FK of Script.ID
A_ID - number PK, FK of Author. A_ID
I need the list of all authors for each script on a single line, for the moment I have the following SQL code:
Select S.Title, SA. A.ID
SCRIPT S, SCRIPT_AUTHOR SA
WHERE SCRIPT.ID = SCRIPT_AUTHOR.ID
and as expected it's returning a dataset as follows:-give me 2 lines in this case for a script:
S.TITLE, SA. A_ID
1, 1
1, 2
What I'm really after is a result set that combines the two authors in this case a file: 1, 1:2, so I don't have 1 line by script.
Scripts can have many authors, and I want to do it for a lot of scripts at a time.
I hit a blank on how to do it, is it possible to do it with SQL?
Thank you very much
p.s. help: Oracle Database 10g Enterprise Edition release 10.2.0.3.0Hello
This is called 'aggregation of chain.
[AskTom.oracle.com | http://asktom.oracle.com/pls/asktom/f?p=100: 11:0:P11_QUESTION_ID:2196162600402] shows several ways to do so.I recommend the first, the function defined by the user STRAGG, that you can copy from this page.
Once you have installed STRAGG, your query is simply
Select S.Title , STRAGG (SA.A.ID) AS sa_id_list FROM SCRIPT S , SCRIPT_AUTHOR SA WHERE SCRIPT.ID = SCRIPT_AUTHOR.ID GROUPB BY s.Title;
On Oracle 10 (and more) you can have a similar function, the WM_CONCAT (property WMSYS), already installed.
WM_CONCAT is not documented, so you can't use it in your Production applications. -
Load the XML file into oracle using sql loader
Hello
I'm trying to load an xml file into a table using sqlldr.
I have a table as follows:
I have a control file that I know is perfectly false:CREATE TABLE xmlloadtable ( id number, data_xml XMLType ) XmlType data_xml STORE AS CLOB;
I googled for the file control and tried in different ways, but of no use.LOAD DATA INFILE '/home/oraread/' INTO TABLE xmlloadtable ( id, data_xml )
I want to load the entire xml file into the table.
Can someone help me with the correct control file. Any help is appreciated!Try this
LOAD DATA INFILE '/home/oraread/' INTO TABLE xmlloadtable (id, file_name filler, data_xml lobfile(file_name) terminated by eof )
You can add the file as a column name field to your table between the id and xml column and remove the word to fill in the .ldr file if you need to keep the name of the file
-
EtreCheck version: 2.9.12 (265)
Report generated 2016-05-01 17:52:49
Download EtreCheck from https://etrecheck.com
Time 08:31
Performance: Below average
Click the [Support] links to help with non-Apple products.
Click [details] for more information on this line.
Problem: Computer is too slow
iMac (21.5 inch, mid 2011)
[Data sheet] - [User Guide] - [warranty & Service]
iMac - model: iMac12, 1
1 2.5 GHz Intel Core i5 CPU: 4 strands
12 GB of RAM expandable - [Instructions]
BANK 0/DIMM0
OK 2 GB DDR3 1333 MHz
BANK 1/DIMM0
OK 2 GB DDR3 1333 MHz
0/DIMM1 BANK
OK 4 GB DDR3 1333 MHz
BANK 1/DIMM1
OK 4 GB DDR3 1333 MHz
Bluetooth: Old - transfer/Airdrop2 not supported
Wireless: en1: 802.11 a/b/g/n
AMD Radeon HD 6750M - VRAM: 512 MB
iMac, 1920 x 1080
OS X El Capitan 10.11.4 (15E65) - since the start time: about 6 days
WDC WD5000AAKS-402AA0 disk0: (500,11 GB) (rotation)
EFI (disk0s1) < not mounted >: 210 MB
Recovery HD (disk0s3) < not mounted > [recovery]: 650 MB
Macintosh HD (disk 1) /: 498,91 go-go (375,32 free)
Encrypted AES - XTS unlocked
Storage of carrots: disk0s2 499.25 GB Online
OPTIARC DVD RW AD - 5690H)
AudioEngine Audioengine D1
Computer, Inc. Apple IR receiver.
Card reader Apple
Apple Inc. FaceTime HD camera (built-in)
Apple Inc. BRCM2046 hub.
Apple Inc. Bluetooth USB host controller.
Apple Inc. Thunderbolt_bus.
Mac App Store and identified developers
/ Library/Application Support/LogMeIn/drivers
com.logmein.driver.LogMeInSoundDriver [no charge] (1.0.0 - 2012-07-19) [Support]
/ Library/Extensions
[loading] com.sophos.kext.sav (9.4.52 - SDK 10.9 - 2016-04-05) [Support]
[no charge] com.sophos.nke.swi (9.4.52 - SDK 10.9 - 2016-04-05) [Support]
/ System/Library/Extensions
[loading] com.rim.driver.BlackBerryUSBDriverInt (0.0.74 - 2016-04-05) [Support]
[no charge] com.rim.driver.BlackBerryUSBDriverVSP (0.0.74 - 2016-04-05) [Support]
[loaded] 8 tasks Apple
[loading] 153 tasks Apple
[operation] 73 tasks Apple
[killed] 4 tasks Apple
4 processes killed due to lack of RAM
[loaded] 43 tasks Apple
[loading] 143 tasks Apple
[operation] 93 tasks Apple
[killed] 10 tasks Apple
10 killed process lack of RAM
[failure] com.adobe.ARMDCHelper.cc24aef4a1b90ed56a... plist (2015-11-07) [Support]
[operation] com.logmein.logmeingui.plist (02 / 02/2013) [Support]
com.LogMeIn.logmeinguiagent.plist [no charge] (2013-04-08) [Support]
com.LogMeIn.logmeinguiagentatlogin.plist [no charge] (2013-04-08) [Support]
[operation] com.rim.BBAlbumArtCacher.plist (2012-04-19) [Support]
[operation] com.rim.BBLaunchAgent.plist (2012-04-19) [Support]
[operation] com.sophos.uiserver.plist (2015-09-26) [Support]
[operation] net.culater.SIMBL.Agent.plist (2013-04-03) [Support]
[loading] com.adobe.ARMDC.Communicator.plist (2015-11-07) [Support]
[loading] com.adobe.ARMDC.SMJobBlessHelper.plist (2015-11-07) [Support]
[loading] com.adobe.fpsaud.plist (2016-04-15) [Support]
com.LogMeIn.logmeinserver.plist [no charge] (2012-07-19) [Support]
[operation] com.memeo.Memeod.plist (2009-09-30) [Support]
[operation] com.rim.BBDaemon.plist (2012-04-19) [Support]
[operation] com.sophos.common.servicemanager.plist (2016-02-11) [Support]
[failure] com.adobe.ARM. [...]. plist (2013-02-18) [Support]
[market] com.akamai.single - user - client.plist (2015-09-23) [Support]
[operation] com.amazon.music.plist (2015-03-07) [Support]
com.apple.AddressBook.ScheduledSync.PHXC... plist [loading]
[operation] ws.agile.1PasswordAgent.plist (2014-09-18) [Support]
Hidden OpenDNS Updater Application (/ Applications/OpenDNS Updater.app)
Nikon Message Center 2 launch application (/ Applications/Nikon/Nikon Message Center 2 software / Nikon Message Center 2.app/Contents/SharedSupport/Launch Nikon Message Center 2.app)
Eye - Fi Helper Application (/ Applications/Eye-Fi/Eye-Fi Helper.app)
MemeoAgent Application (/ Library/Application Support/Memeo/Memeo Backup/Agents/MemeoAgent.app)
[ongoing] 2BUA8C4S2C.com.agilebits.onepassword4 - helper
[performance] P72E3GC48.com.Dashlane.DashlaneAgent
com [running]. Growl.GrowlHelperApp.96032
com [running]. Memeo.MemeoAgent.92832
[ongoing] com.opendns.OpenDNS_Updater.72352
[ongoing] com.Sophos.AutoUpdate
[ongoing] com.Sophos.Configuration
[ongoing] com.Sophos.InterCheck
[ongoing] com.Sophos.notification
[ongoing] com.Sophos.scan
[ongoing] com.Sophos.sxld
[ongoing] fi.eye.helper.98912
[loading] 383 tasks Apple
[operation] 223 tasks Apple
[killed] 11 tasks Apple
JavaAppletPlugin: 15.0.1 - 10.11 (2012-08-14) check the version of the SDK
FlashPlayer - 10.6: 21.0.0.226 - SDK 10.6 (2016-04-25) [Support]
QuickTime Plugin: 7.7.3 (2016-03-25)
AdobePDFViewerNPAPI: 15.009.20069 - SDK 10.8 (2015-09-30) [Support]
Flash Player: 21.0.0.226 - SDK 10.6 (2016-04-25) [Support]
AdobePDFViewer: 15.009.20069 - SDK 10.8 (2015-09-30) [Support]
CANONiMAGEGATEWAYDL: 3.1.0.2 (2009-09-08) [Support]
EPPEX plugin: 3.0.5.0 (2009-07-29) [Support]
Default browser: 601 - SDK 10.11 (2016-03-25)
GarminGpsControl: 4.0.2.6 Beta - SDK 10.6 (2012-11-16) [Support]
iPhotoPhotocast: 7.0 - 10.8 SDK (2013-04-19)
CitrixOnlineWebDeploymentPlugin: 1.0.104 (2013-04-11) [Support]
Dashlane: Dashlane 1.0.0 - SDK 10.7 (2014-04-11) [Support]
Ka-block! -David Graham & Josh Peek - http://kablock.com (2016-04-22)
AdBlock Ultimate - Secure Download - https://adblockultimate.net/ (2016-02-07)
Ghostery - GHOSTERY, Inc. - https://www.ghostery.com/ (2016-03-11)
EverNote Web Clipper - Evernote Corp. - http://evernote.com (2016-02-07)
Keeper® Password Manager & Digital Vault - Keeper Security, Inc. - https://keepersecurity.com (2016-03-11)
DuckDuckGo - DuckDuckGo - http://duckduckgo.com (2015-07-13)
1Password - AgileBits - https://agilebits.com/onepassword (2016-03-29)
AdBlock - BetaFish, Inc. - https://getadblock.com (2016-04-29)
Adblock more - Eyeo GmbH - https://adblockplus.org/ (2016-03-26)
WOT - WOT Services Ltd. - http://www.mywot.com/ (2016-04-22)
YoutubeWide - Pedrocc - http://www.pedrocc.com/safari (2014-10-22)
Dashlane - Dashlane Inc. - http://www.dashlane.com (2016-02-07)
Save on Pocket - Read It Later, Inc. - http://getpocket.com/ (2015-11-07)
Blur - Abine, the society for the protection of personal information online. - https://www.abine.com (2016-05-01)
TrafficLight - Bitdefender SRL - http://trafficlight.bitdefender.com/ (2016-02-07)
Akamai NetSession preferences (2015-09-23) [Support]
Flash Player (2016-04-15) [Support]
Growl (2006-12-30) [Support]
Time Machine not configured!
13% WindowServer
Dock of 10%
7% launchd
6% kernel_task
1% Memeod
Top of page process of memory: ⓘ
2.83 GB com.apple.WebKit.WebContent (8)
2.08 GB Safari
917 MB kernel_task
467 MB softwareupdated
406 MB iTunes
310 MB free RAM
12,00 GB used RAM (2.47 GB being cached)
134 MB used Swap
When you see a beachball cursor or the slowness is particularly bad, note the exact time: hour, minute, second.
These must be run as administrator. If you have only one user account, you are the administrator.
Run the Console application in one of the following ways:
☞ Enter the first letters of his name in a Spotlight search. Select from the results (it should be at the top).
☞ In the Finder, select go utilities ▹ of menu bar or press the combination of keys shift-command-U. The application is in the folder that opens.
☞ Open LaunchPad and start typing the name.
The title of the Console window should be all Messages. If it isn't, select
SYSTEM LOG QUERIES ▹ all Messages
in the list of logs on the left. If you don't see this list, select
List of newspapers seen ▹ display
in the menu at the top of the screen bar.
Each message in the journal begins with the date and time when it was entered. Highlight date back to the time you noted above.
Select the messages entered since then until the end of the episode, or until they begin to repeat, whichever comes first.
Copy messages to the Clipboard by pressing Control-C key combination. Paste into a reply to this message by pressing command + V.
The journal contains a large amount of information, almost all this is useless to solve any particular problem. When you post a journal excerpt, be selective. A few dozen lines are almost always more than enough.
Please don't dump blindly thousands of lines in the journal in this discussion.
Please do not post screenshots of log messages - text poster.
Some private information, such as your name, may appear in the log. Anonymize before posting.
When you post the journal excerpt, an error message may appear on the web page: "you include content in your post that is not allowed", or "the message contains invalid characters." It's a bug in the forum software. Thanks for posting the text on Pastebin, then post here a link to the page you created.
If you have an account on Pastebin, please do not select private in exposure menu to paste on the page, because no one else that you will be able to see it.
-
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
-
Hi SQL & PL/SQL gurus...
A bit of advice please...
IM loading documents in the system... In this context, I have a routine that check the progress of loading (upload_records) against an existing table (supplier_records). If the details differ so it updates, and if the folder does not exist, it inserts a new record...
About 90% of the time, recording will be unchanged and the statement will do nothing...
The challenge I have is that I get the error above fairly regularly, because (I think) there are simultaneous users, loading documents in the system... so, both tables change regularly... The merge statement is below... but my question is: I would achieve anything by converting the merge statement into a PL/SQL loop that checks if the recordset contains a record that needs to either update or insertion? Would be the first simple quick check that reduction of 90% of the files works better, (with further processing if the folder must insert or update) and this would remove the error above, or the merge statement made the same thing anyway, and I should leave it as what? or is my incorrect merge statement and which contribute to the error? The merge statement, if it finds a match, updates the record anyway, even if she didn't need to... (which is not very effective)... However a pl/SQL loop will have to check if the record exists. check if it needs to be changed, change it if she does... Insert if the folder does not exist.
MERGE statement is:
MERGE INTO s suppliers
USING (select distinct (sup_provision_id),
provider,
sup_acc_holder,
sup_bank_acc,
sup_bank_name,
payments_upload sup_bank_branch
where csv_id =: P20_CSV_ID) could
WE (pu.sup_provision_id = s.supplier_id)
WHEN MATCHED THEN
GAME UPDATE
s.SUPPLIER = pu.supplier,
s.SUP_ACC_HOLDER = pu.sup_acc_holder,
s.BANK_ACC_NO = pu.sup_bank_acc,
s.BANK_NAME = pu.sup_bank_name,
s.BRANCH_NO = pu.sup_bank_branch
WHEN NOT MATCHED THEN
INSERT (s.SUPPLIER_ID,
s.SUPPLIER,
s.SUP_ACC_HOLDER,
s.BANK_ACC_NO,
s.BANK_NAME,
s.BRANCH_NO,
s.CAT)
VALUES (pu.sup_provision_id,
able. Beg,
Pu.sup_acc_holder,
Pu.sup_bank_acc,
Pu.sup_bank_name,
Pu.sup_bank_branch,
'S' );
Thank you very much
Richard
Hi, Richard,.
Richard Legge wrote:
Hello.. Thanks for the reply...... The reason for the 'distinct' to ensure that the query retrieves only one line (based on the extraction of the full line, as you point out)... (so why he would never get more than one?) Well Yes... know that the media are not quite relevant...
The reasoning is that out or 5000 records. 4000 will have the same provider... so want to retrieve a single record for what it (or other unique visitors who may be similar but have different criteria) and simply update the corresponding record, insert if there is no trace...
Rgds
Richard
SELECT DISTINCT guarantees that no 2 rows will be exactly alike. In other words, if you compare the 2 rows in the result set, either sup_provision_id supplier of GOLD supp_acc_holder for GOLD OR one of the other columns (or maybe 2 or more columns) will be different. It does not guarantee that any 1 column will be unique.
FUSION requires that, when a match is found, it should only be 1 line in the result set generated by the USING clause. Given that the matching condition is
WE (pu.sup_provision_id = s.supplier_id)
This means that pu_sup_provision must be unique. The ORA_30926 error occurs if it is not unique. SELECT DISTINCT to ensure that complete lines in pu are unique, but it does not guarantee that any single column will be unique.
Depending on your data and your needs, you may need to change the USING clause, so that sup_provision_id is unique. You may need to add more conditions to the WHERE clause, or do a GROUP BY or use an analytic function such as ROW_NUMBER.
If you need help, post a small example of data (that is, CREATE TABLE and INSERT statements for all the tables involved, as they are before the MERGER) and the exact results you want (that is, indicate which suppliers should contain after the MERGER).
Check out the Forum FAQ: Re: 2. How can I ask a question on the forums?
-
Insert the result of a query select in another table
Hello
I have a strange problem when I try to insert all the results of a query select in another table, using the declaration of the order.
With the declaration of COMMAND it works fine
Work:
------------------------------
INSERT INTO ADART01 (SELECT (codart)
"STOCK". "" CODART_STO ".
Of
"DB". ' ' 'ACTIONS');
------------------------------
But if I try to sort the result using the declaration of the ORDER, I have the following error:
Error: ORA-00907 missing right parenthesis
------------------------------
INSERT INTO ADART01 (SELECT (codart)
"STOCK". "" CODART_STO ".
Of
"DB". "" "ACTIONS"
ORDER BY
"STOCK". ("' CODART_STO ASC ');
------------------------------
Any idea?
Thank you for your help,
Angel.delete "()" to select
create table test1 (a number, b varchar2(100)); insert into test1 (a, b) select level, 'level ' || level from dual connect by level < 101; insert into test1 (a, b) select level, 'level ' || level from dual connect by level < 101 order by to_char(sysdate - level, 'D'); select * from test1; drop table test1;
-
Set a variable to the result of an instruction select
I create a list view of the numbers that I have in the system. I'm doing a table with only a list of numbers from 1 to whatever number max is in view. IIf 89 324 is so the last number in the system, so I want a table with 1 thru 89324. Then I can use the NOT EXIST to determine what numbers are miissing in the system. so, if 1 to 200 are not used, but by 89 324 201 is used, then I want the output to 1,2,3... 200.
The code to make the display works and the code to create the table is good, the loop works when I use a number defined for example 100. I just have problems affecting a variable in the number max.
Here's what I have (which of course does not)
Published by: james3302 on August 11, 2010 15:59CREATE OR REPLACE PROCEDURE test IS n number := 1; maxNum number; BEGIN execute immediate 'create view check_numbers as select num from table1 union select num from table2 union select num from table3'; maxNum := EXECUTE IMMEDIATE 'select max(num) from check_numbers'; --I also tried taking out the EXECUTE IMMEDATE here and it still did not work WHILE n <= maxIpid LOOP insert into numList values(n); n := n + 1; END LOOP; --Here I will put in the code to compare the two and display the numbers that are in numList but not in Check_numbers END; /
James,
The solution to your immediate problem to get the result of the immediate execution in a variable is to use
EXECUTE IMMEDIATE 'select max(num) from check_numbers' into maxNum;
You can also do without running to the immediate assistance
select max(num) into maxNum from check_numbers;
Of course, you should definitely consider using one of the other solutions already provided.
Depending on what you ultimately trying to reach, another option to consider is to get the list of discrepancies between the numbers to help
Method of Tabibitosan of Aketi ({: identifier of the thread = 1005478}).with t as ( select 1 as n from dual union all select 2 as n from dual union all select 7 as n from dual union all select 8 as n from dual union all select 11 as n from dual ) select * from ( select grp, n1, n2, 1+lag(n2,1,0) over(order by n1) as gap_n1, n1-1 as gap_n2 from ( select grp, min(n) as n1, max(n) as n2 from ( select n, n - row_number() over(order by n) as grp from t ) group by grp ) ) where grp>0 order by grp ; GRP N1 N2 GAP_N1 GAP_N2 ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- 4 7 8 3 6 6 11 11 9 10
Kind regards
BobPublished by: BobLilly on August 11, 2010 15:00
-
Select a table returned in the result of the query
Hi, I'm trying to find a way to query a table name that I'm back to a different query. I am doing this in pure SQL and PL/SQL, if I can.
Here's the situation. I have a table called FILES, a table called TYPE and an unknown number of different reference tables with different names.
Each entry in the FILE has a reference to a TYPE id, and each entry type is a varchar that contains the name of a table reference, such as PHOTO_INFORMATION, PDF_INFORMATION or XML_INFORMATION.
I want to be able to extract the data from the reference table for any data file. So with a file id, I question TYPE to get the name of the reference table (IE, "PHOTO_INFORMATION" back) then the request it is at this table for all of its columns, using the reference id in the FILE table.
The thing is that I wish it were generic, so that I can just add an entry to AA_TYPE and a new table for this type, and then I can ask her but I want, through the FILE table. The reason is that there are some data that is common for all files, and I would like to that data in one place.
Here is my paintings, I have two reference tables of the sample to the bottom "AA_FILETYPE1" and "AA_FILETYPE_PHOTO".
Here's an example query I would use:CREATE TABLE "AA_FILES" ( "FILE_ID" NUMBER, "FILE_NAME" VARCHAR2(4000), "FILE_TYPE" NUMBER, "REFERENCE_ID" NUMBER, CONSTRAINT "AA_TEST_FILE_PK" PRIMARY KEY ("FILE_ID") ENABLE ) / CREATE TABLE "AA_TYPE" ( "TYPE_ID" NUMBER NOT NULL ENABLE, "REFERENCE_TABLE" VARCHAR2(4000), CONSTRAINT "AA_TYPE_PK" PRIMARY KEY ("TYPE_ID") ENABLE ) / CREATE TABLE "AA_FILETYPE1" ( "REFERENCE_ID" NUMBER, "DATE_MODIFIED" DATE, "SUMMARY" VARCHAR2(4000), "TOTAL_VALUE" NUMBER(5,2), CONSTRAINT "AA_FILETYPE1_PK" PRIMARY KEY ("REFERENCE_ID") ENABLE ) / CREATE TABLE "AA_FILETYPE_PHOTO" ( "REFERENCE_ID" NUMBER NOT NULL ENABLE, "DATE_TAKEN" DATE, "CAMERA_NUMBER" VARCHAR2(4000), "WEATHER_CONDITIONS" VARCHAR2(4000), "CONSULTANT_NAME" VARCHAR2(4000), CONSTRAINT "AA_FILETYPE_PHOTO_PK" PRIMARY KEY ("REFERENCE_ID") ENABLE ) /
So who withdrew all the columns in the reference given in AA_TYPE table based on an entry in AA_FILES.select * from (select REFERENCE_TABLE from AA_TYPE where TYPE_ID = AA_FILES.FILE_TYPE) where REFERENCE_ID = AA_FILES.REFERENCE_ID;
I'm not entirely sure how to do this, or if this is possible even without using PL/SQL.
I'm open to suggestions on how to achieve what I want with a different design of table, I am a student and I'm not really experienced in database design. (My first design of database class isn't until next year!)
Thank you very much!Hello
[email protected] wrote:
Sorry about the confusion about file_id = 3, I meant the insert in the third I've included. I did not indicate the id_fichier in my inserts since it is the main key and it auto increments.It is important to post of the CREATE TABLE and INSERT statements that work. All those who want to help you to will want to recreate the problem and test solutions. Also, do not use strings for all entries. If the column is a NUMBER, use a NUMBER in the INSERT statement. If the column is a DATE, use a DATE or a function that returns a DATE.
So you should post something like:insert into AA_FILES(FILE_ID, FILE_NAME, FILE_TYPE, REFERENCE_ID) values (1, 'test-photo-1.jpg', 1, 1); insert into AA_FILES(FILE_ID, FILE_NAME, FILE_TYPE, REFERENCE_ID) values (2, 'test-xml-1.jpg', 2, 2); insert into AA_FILES(FILE_ID, FILE_NAME, FILE_TYPE, REFERENCE_ID) values (3, 'test-photo-2.jpg', 1, 2); -- The value file_type=1 immediately above was not in your original data, but seems to be what you meant. prompt ===== AA_TYPE Table: ===== insert into AA_TYPE(TYPE_ID, REFERENCE_TABLE) values (1, 'AA_FILETYPE_PHOTO'); insert into AA_TYPE(TYPE_ID, REFERENCE_TABLE) values (2, 'AA_FILETYPE1'); prompt ===== AA_FILETYPE1 Table: ===== insert into AA_FILETYPE1 (REFERENCE_ID, DATE_MODIFIED, SUMMARY, TOTAL_VALUE) values (1, TO_DATE ('01-01-02', 'MM-DD-RR'), 'An XML file that has some information about something', '14'); prompt ===== AA_FILETYPE_PHOTO Table: ===== insert into AA_FILETYPE_PHOTO (REFERENCE_ID, DATE_TAKEN, CAMERA_NUMBER, WEATHER_CONDITIONS, CONSULTANT_NAME) values (1, TO_DATE ('01-01-01', 'MM-DD/RR'), 'abc123', 'rainy!', 'John Smith'); insert into AA_FILETYPE_PHOTO (REFERENCE_ID, DATE_TAKEN, CAMERA_NUMBER, WEATHER_CONDITIONS, CONSULTANT_NAME) values (2, TO_DATE ('01-01-02', 'MM-DD/RR'), 'def456', 'slightly cloudy', 'Jane Jones'); commit;
To give you my workplace, I'm applying in Application Express. A user has entered the number '3' the file_id (I'm not worried about the distinction between passing in the id_fichier and the name of the file, I just my application one application or the other).
Now, run a query that will get related data which table it is stored in. I don't know the name of the table at design time, as that particular file may be of any type (each of which has a different table name). However, with a the file_id, I have a file_type (in aa_files) which refers to an entry in aa_type.
I see. You could add even add new tables after this query is written. As long as the new table has a column named reference_id, and there is a line for the new table in aa_files, the following query should work.
>
select FILE_TYPE from AA_FILES where FILE_ID = 3
I stored the name of the table, I need to ask for the rest of the data in aa_type at design time, so using the file_type value, I can get the name of reference_table:
select REFERENCE_TABLE from AA_TYPE where FILE_TYPE = 1
In the sample data, you have validated, Type_de_fichier = 2 on the 3rd row. I've changed that in my example 1 revised data.
Be very careful that your explanation fits your data. You talk to people who know about your application, and it is very easy for them to be induced in error or confusion.Now the '1' is here that the first query would return. I would like to use a subquery to combine these two queries into a single (I think?). This second query would return "AA_FILETYPE_PHOTO", which is the reference table.
So I have the reference table, which is a name of table to another table in my database. It contains the data that I'm actually looking for. I want it for this particular file (file_id 3), and in aa_files, I have a value of "reference_id", which refers to the respective line in the reference table. File_id 3, the reference_id is 2.
select * from AA_FILETYPE_PHOTO where reference_id = 2
If the above query gets me my final data.
Now, I've been watching substitution values and bind variables, here's another way to explain what I want:
Explanation step by step below is very useful. It would be more useful if each step uniquely and gavce movement results given the sample data and an example of setting (3 in this case)
-- get the file_type from aa_files for the desired file EXEC :file_type := (select file_type from aa_files where file_id = 3);
That we will call the step step (a) above.
Step (a) sets: Type_de_fichier 1 (given my corrected sample data)-- get the reference table from aa_types using the file_type EXEC :reference_table := (select reference_table from aa_type where type_id = :file_type);
That we will call the step step (b) above.
(B) sets the stage: reference_table to 'AA_FILETYPE_PHOTO '.-- get the reference_id from aa_files for the desired file EXEC :reference_id := (select reference_id from aa_files where file_id = 3);
That we will call the step step (c) above.
(C) sets the stage: reference_id 2-- using the reference table and reference id for the desired file, get the rest of the data select * from :reference_table where reference_id = :reference_id;
Not sure if this makes it more clear or not.
Yes, it helps a lot.
Basically I have a table full of table names. How do I write a query that pulls one of these table names and it then queries?
You need SQL dynamic, because you can't hardcode a table name in the query that you normally would be.
How dynamic SQL works normally (and the functioning of this example) are that the query is built by using a variable. In SQL * more (as shown below), you can simply use a variable substitution instead an identifier hardcoded, and that's what it takes to make the dynamic query from SQL * more resolves the substitution variables before sending the code for the compiler. I don't know much on the Apex, but I bet there's some way to do dynamic SQL in the Apex, too.
So the dynamic part here should include step d, since you can't hardcode the name of the table in the query.
Until we can step (d), then, did they to us to do the steps (a) and (b) to obtain this file name. In the example blelow, I used a separate, preliminary request to get the & table_name...
Step (c) could be made in the main query, using a subquery or a join. However, I chose to step (c) in the preliminary motion, as well as steps (a) and (b), since it's the same table same step (a). In this way, step (d) must refer to a table.Here's (finally) how to make this work in SQL * more:
ACCEPT file_id PROMPT "Enter the file_id (a number, e.g. 3): " -- Preliminary Query, to set table_name COLUMN reference_id_col NEW_VALUE reference_id COLUMN table_name_col NEW_VALUE table_name SELECT f.reference_id AS reference_id_col , t.reference_table AS table_name_col FROM aa_files f JOIN aa_type t ON f.file_type = t.type_id WHERE f.file_id = &file_id ; -- Main Query SELECT * FROM &table_name WHERE reference_id = &reference_id ;
The results, account required to the data from the sample I posted above, and the & file_id 3, are:
` CAMERA_ WEATHER_ CONSULTANT_ REFERENCE_ID DATE_TAKE NUMBER CONDITIONS NAME ------------ --------- ---------- --------------- --------------- 2 01-JAN-02 def456 slightly cloudy Jane Jones
-
I am running Windows XP. My deleted security a software threatens malware a few days before and since any file or program I select in the desktop, start menu or results of the status bar in a notice that "this file doesn't have a program associated with it for performing this action. Create an association in the folder options panel. Nothing I've tried has worked! Help!
Run the EXE File Association Fix http://www.dougknox.com/xp/file_assoc.htm
You probably also need to run the LNK (shortcut) file Association problem from the same site.Be sure to read the instructions at the top of the page.
-
Function of package of call per line in the statement INSERT INTO SELECT
Hello
I wrote the following SQL insert.
INSERT the Table_A (Col_A, Col_B, Col_C)
SELECT Col_A, Col_B, (SELECT PACKAGE1. DOUBLE FUNC())
FROM Table_A
WHERE Col_A = "AAA".
PACKAGE1. Func() is a function to create numbers using the sequence.
The result is
Col_a Col_B, Col_C
---------------------------------------
C003 AAA B1
C003 AAA B2
C003 AAA B3What I want is as follows:
Col_a Col_B, Col_C
---------------------------------------
C003 AAA B1
AAA B2 C004
AAA B3 C005I want different values per line in Col_C. is it possible to do this?
I think the fact that you put the function call in a subquery is why he executed only once (which is a useful thing to know if you want this feature). To get executed for each line, you only need to do this:
INSERT the Table_A (Col_A, Col_B, Col_C)
SELECT Col_A, Col_B, PACKAGE1. FUNC()
FROM Table_A
WHERE Col_A = "AAA".
However, as others have said, there is no reason to wrap a sequence.nextval in a function.
-
Need help with the analytical function select maximum and minimum of the results of the column
Hey there OTN.
I have an interesting application that I was hoping you would be able to help me with. I have a requirement to conditionally select the max and min of a column in bi-editor and since my editor works from an OBIEE analysis, I need store MAX and MIN of the column values in separate columns to match with. See the example below. You will notice that there are 4 stores including today's sales. I must have OBIEE through all the results of the column for sales, then choose the max of the dataset object. I can't use MAX here because he will choose the MAX of the line which will return only sales of this line. Instead, one must analyze all sales results and choose the appropriate column. Any idea on how to do this in OBIEE/publisher? Or is this not possible.
Day Store Sales Sales of MAX Sales MIN 05/11/15 Store 1 5000 8000 1000 05/11/15 Store 2 7500 8000 1000 05/11/15 Store 3 1000 8000 1000 05/11/15 Store 4 8000 8000 1000 I'm waiting for your answers. Thanks in advance!
PS: I will always mark messages that are useful and eventually mark it as correct answer if we come to a resolution!
See you soon.
You can't do the same thing with RANK ("dirty")?
Rank ("dirty") = 1: the max value in the result of sales
RANK (-1 * "Sales") = 1: the min in the result of sales value
I guess you can and then format the cells based on these values, where a value of 1 is the max or min according to the RANKING formula you used...
Maybe you are looking for
-
I want to know the first time I installed firefox on my pc?
I want to know my story of installing firefox.
-
Error code: 0X800B0100 (cannot install KB979688 & KB234886)
Cannot install KB 979688 & KB 234886 - tried the above fix, no joy
-
Microsoft Security Essentials: Machine state - potentially unprotected
Microsoft Security Essentials: When I try to update virus and spyware difinitions it seems to work but still reads "your computer does not have the latest updates on potential threats, which could endanger. I tried to update several times in recent d
-
Moving from SSL VPN licenses to other ASA
Hello Be gentle, it's my first post. We currently have an ASA 5520 with 25 remost SSL VPN licenses. We have also some 5510's unused. Anyone know if the SSL licenses are transferable to the 5510 unused to the 5520 to increase the amount that the 55
-
Seagate external hard drive is not recognized in Windows 7
I have a 1 to Seagate disc ext I used since February 2011, I changed my computer since then and only recently, it does not recognize the drive. I couldn't find any free software to download, and the drive did not come with CD. Please help? Thank you.