Problem with SQL aggregation
I tried several different ways to do it and can't seem to find the right way to do it. We're on 10.2, so not listagg. I have the following information:fld_a fld_b fld_c fld_d
12 10 1 it is
12-10-2 a test
14 5 1 second
14 5 2 test
I want to have the following result:
12: 10, it is a test (essentially fld_a, fld_b and fld_d, ordered by fld_c)
14, 5, second test (the fld_d on a line)
I'm not listagg, so I tried follows him (and combos of what follows).
Select fld_a, fld_b, fld_c,
RTrim (xmlagg (xmlelement (e, fld_d |))) ') .extract ('/ / text()'), ',') 'fld_d '.
of schemaname.tablename
Group of fld_a, fld_b, fld_c
and is not the fld_d of fld_a & fld_b group and ordered by fld_c.
Any ideas?
Thank you
Victoria
user3804901 wrote:
I tried several different ways to do it and can't seem to find the right way to do it. We're on 10.2, so not listagg. I have the following information:fld_a fld_b fld_c fld_d
12 10 1 it is
12-10-2 a test
14 5 1 second
14 5 2 testI want to have the following result:
12: 10, it is a test (essentially fld_a, fld_b and fld_d, ordered by fld_c)
14, 5, second test (the fld_d on a line)
Your problem is that your output requires no regrouping by FIELD_C - but in your query, you are group by FIELD_C
Him below will work...
with t (fld_a,fld_b,fld_c,fld_d) as
(
select 12, 10, 1,'this is' from dual union all
select 12, 10, 2,'a test' from dual union all
select 14, 5, 1,'second' from dual union all
select 14, 5, 2,'test' from dual
)
select fld_a, fld_b,
rtrim(
xmlagg(
xmlelement (e, fld_d || ' ') order by fld_c
).extract ('//text()')
) "fld_d"
from t
group by fld_a, fld_b
FLD_A FLD_B fld_d
----------------------------
12 10 this is a test
14 5 second test
Or sys_connect_by_path as already suggested
with t (fld_a,fld_b,fld_c,fld_d) as
(
select 12, 10, 1,'this is' from dual union all
select 12, 10, 2,'a test' from dual union all
select 14, 5, 1,'second' from dual union all
select 14, 5, 2,'test' from dual
)
select rtrim(replace(max(sys_connect_by_path(fld_d,'~')),'~',' ')) fld_d
from t
start with fld_c = 1
connect by prior fld_a=fld_a
and prior fld_b=fld_b
and prior fld_c = fld_c-1
group by fld_a,fld_b ;
Published by: JAC on February 12, 2013 09:50
Tags: Database
Similar Questions
-
Having problems with SQL Developer connection to the database on a LINUX machine
Having problems with SQL Developer connection to the database on a LINUX machine
Hello
I am trying to connect my machine to windows 7 Home premium to an oracle database 11 g on RedHat 5 machine using SQL Developer. I got this error on SQL Developer
Status: Failed - Test has failed: the network adapter could not establish the connection
on Linux
and TNSPINGLSNRCTL> status Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1))) STATUS of the LISTENER ------------------------ Alias LISTENER Version TNSLSNR for Linux: Version 10.2.0.1.0 - Production Start Date 03-APR-2013 16:13:13 Uptime 7 days 22 hr. 16 min. 41 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora Listener Log File /u01/app/oracle/product/11.2.0/db_1/network/log/listener.log Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.X.X.X)(PORT=1521))) Services Summary... Service "PLSExtProc" has 1 instance(s). Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service... Service "orc11g" has 1 instance(s). Instance "orc11g", status READY, has 1 handler(s) for this service... Service "orc11gXDB" has 1 instance(s). Instance "orc11g", status READY, has 1 handler(s) for this service... Service "orc11g_XPT" has 1 instance(s). Instance "orc11g", status READY, has 1 handler(s) for this service... The command completed successfully LSNRCTL>
Tnsnames.ora on Linux,tnsping 172.x.x.x TNS Ping Utility for Linux: Version 10.2.0.1.0 - Production on 11-APR-2013 14:32:17 Copyright (c) 1997, 2005, Oracle. All rights reserved. Used parameter files: /u01/app/oracle/product/11.2.0/db_1/network/admin/sqlnet.ora Used EZCONNECT adapter to resolve the alias Attempting to contact (DESCRIPTION=(CONNECT_DATA=(SERVICE_NAME=172.x.x.x))(ADDRESS=(PROTOCOL=TCP)(HOST=172.x.x.x)(PORT=1521))) OK (0 msec) [oracle@ltebilling ~]$
Listner on Linux,ORC11G = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 172.x.x.x)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orc11g) ) )
hosts/ect/Linux,SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = PLSExtProc) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1) (PROGRAM = extproc) ) ) LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1)) (ADDRESS = (PROTOCOL = TCP)(HOST = 172.x.x.x)(PORT = 1521)) ) )
and there is no problem to ping linux from windows# Do not remove the following line, or various programs # that require network functionality will fail. 127.0.0.1 localhost.localdomain localhost 172.x.x.x LTEBilling
Published by: user11309581 on April 11, 2013 15:16user11309581 wrote:
as I have already desciped earlier, I can't connect to the server throw Linux my Windows SQL Server, with error message below.
tatus: failed - Test has failed: the network adapter could not establish the connectionIt's too generic to mean anything. The application is hidden the real error message. You got when you did the tnsping and obtained "TNS-12535: TNS:operation has expired. Now THAT's an error.
This indicates a problem firewall and routing. You said earlier you could ping the server, but now we see tnsping fails. Two different protocols of usage, so that both the successful ping turns out a valid physical path, it guarantees not that all traffic will pass. What happens with
c:\ telnet 172.x.x.x 1521
-
Connection problem with SQL Developer 3.0.0.4
I have a strange problem with SQL Developer (SD) 3.0.0.4. So that the implementation of a new connection I have in double entries listed for some of the databases listed in my TNSNAMES.ora file. When I try to connect to one of the databases has entered duplicated, I get the following Oracle error:ORA-01034: Oracle not available ORA-27101: Kingdom does not exist SVR4 shared memory error: 2: no files or directory
however, if I try to connect to the same database using SQL * more or TOAD, it works perfectly and TOAD has no duplicates.
At first, I thought maybe that SD has been reading multiple copies of the TNSNAMES.ora so I checked and removed all the duplicate files and set the variable of environment TNS_ADMIN to point to that and the single instance of the TNSNAMES.ora file. Yet once, SQLPlus and TOAD to work fine, but SD is always showing entries twice and always have reported the above error when I try to connect to a database with a duplicate entry. I should mention, I'm able to connect to the database that have only a single entry listed use SD.
If I understand correctly, SD uses JDBC as underlying connection mechanism. Based on this "agreement" I thought that maybe I had a file corrupted in the Java Cache, so I cleared the cache, but I always get errors.
As mentioned, I use SQL Developer 3.0.0.4 with Java 1.6.0_11 (included in the download). In addition, I have installed JRE 1.6.0_24 and I am running Windows XP SP3. Any ideas or suggestions are greatly appreciated.
Craig...Hi Craig,.
Or, if I have misunderstood completely the scenario you describe, here's a post on the forum about duplicate entries appear in the drop-down list Alias network when the connection Type is TNS:
Developer SQL 2.1.0.63 TNS name in characters of the connection
This solution involves clean a bad TNSNAMES. ORA file with double score entries to test the death of SID.
-Gary
-
Hello
I have problems using SQL Loader with ODI. I am filling an oracle table with data from a txt file. Initially, I had used 'File to SQL' LKM, but due to the size of the file (700 MB) source, I decided to use 'file to Oracle (SQLLDR)' LKM.
The error that appears in myFile.txt.log is: "SQL * Loader-101: invalid argument for the name of user and password.
I think the problem might be in the definition of the database server (physical JavaBeans in topology), because I left empty Host, user and password.
What is the problem? What host and user should I use? With "File to SQL" works fine living that white, but takes too much time.
Thanks in advanceNote the last * @*. He expects a connection string after him.
So, goto Oracle server topology, specify Instance/Dblink (server) as the SID of the oracle database you want to connect.
-
Problem with SQL Developer to capture
Hi guys,.
I am facing a problem for the last 4 days with SQL Developer. I use to migrate sql database to oracle SQL Developer. It worked well before and I had migrated some tables as well. But all of a sudden a few days before I had a mistake, I was unable to capture the objects. While I am trying to capture the sql database or the tables the progress dialog box is displayed as usual, but he suddenly gets hit and the green light turns red which is in the upper left corner. Said at that time, the progress message that appears at the bottom of the box +' stored jdbc:jtds:sqlserver: / / < hostname >: < port > / < the database name > ' +. But if I use another oracle server, then I can capture objects.
Because of this error, I'm not able to go forward. I tried to solve this problem in many ways. But nothing helps! Please help me solve this problem, as it's an emergency.
Thanks in advance.
RAM.
Published by: Ram Dhilip on March 22, 2010 08:16
Published by: Ram Dhilip on March 22, 2010 08:16
Published by: Ram Dhilip on March 22, 2010 08:19
Published by: Ram Dhilip on March 22, 2010 08:34You can use the method of capture in offline mode:
Click on tools-> Migration-> third party database offline Capture-> Capture database creation scripts
Now select the output directory of these scripts and the source database. Also, make sure that you have selected the Batch mode. Once this is done, copy all scripts on a computer with an installed SQL Server client or perform the export on the SQL Server computer directly.
Run the script and you'll get 2 directories with a couple of DAT files created. ALL switch to SQL Developer machine and load them into the SQL Developer
Click on tools-> Migration-> third party database offline Capture-> Capture Script output load of database -
The problem with SQL after the migration of the database to another machine
Having a SQL strange problem trying to extract a database being moved from one machine to the other. Both machines are running SQL 2008 32-bit and are both Windows 2008 servers. When I try to backup the database using the SQL tools and restore the. BAK file on the new SQL Server, I get the following error:
Restore failed for server 'servername' (Microsoft.SqlServer.Smo)
Additional information:
System.Data.SqlClient.SqlError: RESTORE detected an error on the page (44:2097184) in database 'RestoreDBName' read from the backup set.
Similarly, when I am trying to copy the. MDF and. LDF files to the new server and tie them, I get the following error:
Attach the database failed for the server 'servername '.
Additional information:
An exception occurred during the execution of a Transact-SQL statement or batch.
A system assertion failed. An assertion failure is usually caused by a corruption of data or software bug. To check the database, consider running DBCC CHECKDB. If you have agreed to send images to Microsoft during installation, a mini dump will be sent to Microsoft. An update can be an available from Microsoft in the latest Service Pack or a QFE from Technical Support.
Could not open new database 'NewDatabaseName' create a DATABASE is dropped.
"" Location: "logmgr.cpp": 3277
Expression: lfh-> lfh_startOffset is startOffset
SPID:55
PID: 292876 (Microsoft SQL Server, error: 3624)
Everything I've read, these errors usually indicate some sort of database corruption. However when I run DBCC CHECKDB on the database on the source server, it is up to perfectly don't own... None detected corruption. In fact, this server hosts 8 different databases. Departure from all the correct DB on the source server, none of them will restore however to a new server using one of the methods above. I'm having a hard time to believe that each of them could be corrupted when they show absolutely no indication of a problem.
Anyone have any ideas?Try to make the backup and restore via SQLCMD (or via a query in SQL Server MS window).
The backup will be the following (obviously, change "MaBase" and "D:\BACKUPS" to some database and the location you wish to save - just using for example):
BACKUP DATABASE MyDatabase
TO DISK = 'D:\BACKUPS\MyDatabase.bak. '
WITH NOFORMAT, NOINIT,.
NAME = 'Database MyDatabase - Full Backup',
NOREWIND, NOUNLOAD, STATS = 10, SKIP
Copy your backup to the other server and file make:
RESTORE the DATABASE to MyDatabase
FROM DISK = 'E:\Backups\MyDatabase.bak' WITH FILE = 1,
GO to "MyDatabase_Data" to "E:\SQLDATA\MyDatabase_Data.mdf,"
GO to "MyDatabase_Log" to "E:\SQLLOG\MyDatabase_Data.ldf,"
NOUNLOAD, STATS = 10 REPLACE
Again, change your names and locations in function.
If this does not work, try to restore a database by third-party tools. You can find them in Google. If you don't want to spend the time to research, you can try a tool SQL Server Recovery Toolbox. All the details about this program on the link. http://www.oemailrecovery.com/sql_repair.html
-
Problems with SQL server 2008 nvarchar type varchar in oracle.
Hello
I did a heterogeneous connectivity between db to SQL server 2008, and Oracle 11 g, well, but when I try to display the data of colum on RPD (only the varchar type) I see only the first character of the string.
One last thing, when I try to see the data on Oracle SQL developer, I get strange characters, like when we have the wrong character encoding in your browser.
Some print to illustrate the problem.
Query Oracle SQL developer:
http://postimg.org/image/5cvyqw6ih/
Developer Microsoft SQL query:
http://postimg.org/image/skddx991f/Printscreen RPD:
http://postimg.org/image/aok2337cp/SQLplus (as you can see are spaces between characters):
http://postimg.org/image/664xw1xjh/
To finish the data be used to build a mobile application with the oracle mobile app Designer.Thank you
Hello
Thank you kgronau
I've corrected this problem setting in the file gateway (in my case dg4odbc) HS_NLS_NCHAR = UCS2 init
-
Hi s/n,.
I am facing problems when loading the dates in the database by using sql loader. My data file can have several date formats, so I have a function that interprets date and removes the time settings and the date of return.
Something like that.
For example:
I have a table-
CREATE TABLE TEMP1234
(
IDENTIFICATION NUMBER,
DATE OF ASOF_DATE
);
Data file
10001172 | 09/12/1945
Control file:
OPTIONS (DIRECT = TRUE, SILENT (FEEDBACK) =, skip = 0)
DATA RELATING TO SUNK COSTS
REPLACE
in the temp1234 table
' fields completed by "|" possibly provided by ' "'
TRAILING NULLCOLS
(ID,
ASOF_DATE "decode (: ASOF_DATE, null,:ASOF_DATE,conv_date1(:ASOF_DATE))).
)
Function CONV_DATE1:
FUNCTION to CREATE or REPLACE conv_date1 (p_str IN VARCHAR2)
DATE OF RETURN
IS
RETURN_VALUE DATE;p_str1 VARCHAR2 (15): = NULL;
FmtArray TYPE IS a TABLE OF VARCHAR2 (30);
g_fmts fmtArray
: = fmtArray ("yyyy-mm-dd",
"yyyy/mm/dd"
mm/dd/yyyy"."
"dd-mm-yyyy",
"dd/mm/yyyy",
"mm-dd-yyyy");
BEGIN
p_str1: = SUBSTR (p_str, 1, 10);BECAUSE me in 1... g_fmts. COUNTY
LOOP
BEGIN
return_value: = TO_DATE (p_str1, g_fmts (i));
EXIT;
EXCEPTION
WHILE OTHERS
THEN
NULL;
END;
END LOOP;IF (return_value IS NULL)
THEN
RAISE PROGRAM_ERROR;
END IF;RETURN Return_value;
END;
/In this case, if the year in the data file shown in 1945, date which is load in the poster 2045 database.
But when I run this function by putting a sql editor - it returns the correct value.
Select double conv_date1('12/09/1945');
Please help me understand what is causing the problem.
I think there may be an implicit conversion going on with the combination of decode and checking nvl and function within SQL * Loader. I put the nvl checking in function and simply use the function in the control file, as shown below.
OPTIONS (DIRECT = TRUE, SILENT (FEEDBACK) =, skip = 0)
DATA RELATING TO SUNK COSTS
REPLACE
in the temp1234 table
' fields completed by "|" possibly provided by ' "'
TRAILING NULLCOLS
(ID,
asof_date ' conv_date1 (: asof_date).
)
FUNCTION to CREATE or REPLACE conv_date1 (p_str IN VARCHAR2)
DATE OF RETURN
IS
RETURN_VALUE DATE;
p_str1 VARCHAR2 (15): = NULL;
FmtArray TYPE IS a TABLE OF VARCHAR2 (30);
g_fmts fmtArray
: = fmtArray ("yyyy-mm-dd",
"yyyy/mm/dd"
mm/dd/yyyy"."
"dd-mm-yyyy",
"dd/mm/yyyy",
"mm-dd-yyyy");
BEGIN
IF p_str IS NULL
THEN RETURN NULL;
ON THE OTHER
p_str1: = SUBSTR (p_str, 1, 10);
BECAUSE me in 1... g_fmts. COUNTY
LOOP
BEGIN
return_value: = TO_DATE (p_str1, g_fmts (i));
EXIT;
EXCEPTION
WHILE OTHERS
THEN
NULL;
END;
END LOOP;
IF (return_value IS NULL)
THEN
RAISE PROGRAM_ERROR;
END IF;
RETURN Return_value;
END IF;
END;
/
-
I'm a java developer and having the problem of writing a simple sql query. Any help is appreciated.
FILE_TBL
CREATE TABLE FILE_TBL
*(*
FILE_ID VARCHAR2 (8 BYTE),
PUBLICATION_DATE DATE,
LOCATION_CODE VARCHAR2 (2 BYTE),
*)*
Examples of data
INSERT INTO FILE_TBL (FILE_ID, PUBLICATION_DATE, LOCATION_CODE) VALUES ('1', ' 2011-04-11', "AF001");
INSERT INTO FILE_TBL (FILE_ID, PUBLICATION_DATE, LOCATION_CODE) VALUES ('2', ' 2011-04-11', 'SF057');
INSERT INTO FILE_TBL (FILE_ID, PUBLICATION_DATE, LOCATION_CODE) VALUES ('2', ' 2011-04-14', 'AF081');
INSERT INTO FILE_TBL (FILE_ID, PUBLICATION_DATE, LOCATION_CODE) VALUES ('3', ' 2011-04-11', 'SF022');
INSERT INTO FILE_TBL (FILE_ID, PUBLICATION_DATE, LOCATION_CODE) VALUES ('3', '' 2011-04-14, "AF012");
INSERT INTO FILE_TBL (FILE_ID, PUBLICATION_DATE, LOCATION_CODE) VALUES ('4', ' 2011-04-11', 'SF057');
INSERT INTO FILE_TBL (FILE_ID, PUBLICATION_DATE, LOCATION_CODE) VALUES ('5', ' 2011-04-11', 'AF036');
It comes to my table structure, where the data must be retrieved.
Now, I have a requirement to get the file_ids for all the corresponding files whose date of publication is either or after 11/04/2011. Everything works fine with the following query.
SELECT FILE_ID
OF FILE_TBL
WHERE PUBLICATION_DATE > = TO_DATE ('2011-04-11', "yyyy-mm-dd")
AND ((LOCATION_CODE LIKE «% SF») OR (LOCATION_CODE LIKE ' AF %'))))
Now there is a particular requirement, where if there are multiple records for a particular file with dates id be or after 11/04/2011, then the records to be filtered.
For example: overall data above, for the id file 2 and 3, I have two records with release dates of April 11, 2011 "and 14 April 2011". In this case since there are no more entries, a record, it should not be displayed and needs to be filtered from the result set.
Any help to fix the query would be much appreciated.
Thank you.Hello
SirGeneral wrote:
Thanks for the reply!Apologize for not to test applications before posting and it will not be repeated. It was a mistake caused all by simplifying the case.
Thank you. They work very well now.
What are the results you want with this new requirement?I also have a requirement, and don't know if I can do it without a loop data.
That means 'loop data? "
Data file comes mainly as a batch with publication_dates for different ID of file. In each such lot, the publication_date would be the same for all different file IDS. Thus, when a new batch arrives, all the old batch files should be ignored.
Say with all corrected data published:
First batch:
INSERT INTO FILE_TBL (FILE_ID, PUBLICATION_DATE, LOCATION_CODE) VALUES (TO_DATE '1', (' 11/04/2011 ',' DD-MM-YYYY '), "AF001");
INSERT INTO FILE_TBL (FILE_ID, PUBLICATION_DATE, LOCATION_CODE) VALUES (TO_DATE '2', (' 11/04/2011 ',' DD-MM-YYYY '), 'SF057');
INSERT INTO FILE_TBL (FILE_ID, PUBLICATION_DATE, LOCATION_CODE) VALUES (TO_DATE '3', (' 11/04/2011 ',' DD-MM-YYYY '), 'SF022');
INSERT INTO FILE_TBL (FILE_ID, PUBLICATION_DATE, LOCATION_CODE) VALUES (TO_DATE '4', (' 11/04/2011 ',' DD-MM-YYYY '), 'SF057');
INSERT INTO FILE_TBL (FILE_ID, PUBLICATION_DATE, LOCATION_CODE) VALUES (TO_DATE '5', (' 11/04/2011 ',' DD-MM-YYYY '), 'AF036');Second batch:
INSERT INTO FILE_TBL (FILE_ID, PUBLICATION_DATE, LOCATION_CODE) VALUES (TO_DATE '2', (' 14/04/2011 ',' DD-MM-YYYY '), 'AF081');
INSERT INTO FILE_TBL (FILE_ID, PUBLICATION_DATE, LOCATION_CODE) VALUES (TO_DATE '3', (' 14/04/2011 ',' DD-MM-YYYY '), "AF012");Fixed create stmt:
CREATE TABLE FILE_TBL
(
FILE_ID VARCHAR2 (8 BYTES),
PUBLICATION_DATE DATE,
LOCATION_CODE VARCHAR2 (5 BYTES)
)Now under the new requirement I need to get the file_ids for matching files whose publication date is either or after today's date (11/04/2011 ~ changes depending on when his current enforcement) unless a new batch has not arrived. If a new batch has arrived, only the files of the new batch.
A solution that I can think of is to retrieve the data in descending order of PUBLICATION_DATE > today and loop by collecting the ID of file. If the PUBLICATION_DATE changes, can stop a loop and returns the ID of the collected file.
You can use ROW_NUMBER, or similar analytical functions, to do in SQL; No function defined by the user or the PL/SQL is required.
Is there a way to write this in a single SQL query? Appreciate any help on this.
I'm not sure I understand.
It is clear that you want to encode in hard 11 April 2011 in the query, but I'm not sure what you want in its place. The following query uses today's date, regardless of who is be.
Do you mean that only the most recent publication_date account each file_id? In other words, file_ids 1, 4 and 5 rows only dated Date April 11, while the April 11 lines count for these file_ids, but file_ids 2 and 3 have more late publication_date, while the later date accounts for them, so the lines dated 11 April are ignored for file_ids 2 and 3?
If so:WITH got_rnk AS ( SELECT file_id , COUNT (*) AS cnt , ROW_NUMBER () OVER ( PARTITION BY file_id ORDER BY publication_date DESC ) AS rnk FROM file_tbl WHERE publication_date >= TRUNC (SYSDATE) AND SUBSTR (location_code, 1, 2) IN ('AF', 'SF') GROUP BY file_id , publication_date ) SELECT file_id FROM got_rnk WHERE rnk = 1 AND cnt = 1 ;
With the sample data you posted all 5 file_ids are selected, assuming that it is performed on April 11, 2011. (No file_id has more than 1 rank on any one date.)
Or do you mean that all dated April 11 date lines should be ignored if there is no line at a later date?
In this case:SELECT file_id FROM file_tbl WHERE publication_date = ( SELECT MAX (publication_date) FROM file_tbl WHERE publication_date >= TRUNC (SYSDATE) ) AND SUBSTR (location_code, 1, 2) IN ('AF', 'SF') GROUP BY file_id HAVING COUNT (*) = 1 ;
The result of this query will include only file_ids 2 and 3. Here, April 14 is the deadline for the table, so all the lines from April 11, any file_id, are ignored.
It is not known if you want that the conditionSUBSTR (location_code, 1, 2) IN ('AF', 'SF')
to be in the main query (as above), subquery, or both.
Published by: Frank Kulash, April 11, 2011 20:42
-
Other new lines in SQL script file and problem with SQL * more
Hi all
I would like to ask a question on the characters of new line inside files SQL scripts. I have a very long SQL query, stored in a file txt (ANSI encoding). Because query instructions are very long (several table joins and WHERE conditions) tried to separate, WHERE and ORDER BY clauses by inserting several new characters of lines (just hit the entrance) among them in order to improve the clarity of the source code. Now the problem is, whenever these newline characters are inserted in the file, apparently SQL * Plus cannot parse the file properly and gives me the following error message:
The problem is definitely related to these new line because characters that when I remove them, the scripts runs without any problem. I would appreciate that you could kindly guide me how should I deal with this problem. Is there any SQL * Plus command to run to correctly interpret the new line characters?SP2-0042: unknown command "FROM" - rest of line ignored. SP2-0734: unknown command beginning "myenterpri..." - rest of line ignored.
Thanks in advance,
Kind regards
DariyooshHello
In [SQL * Plus 9 | http://download.oracle.com/docs/cd/B10501_01/server.920/a90842/ch13.htm#1013073] (and), you can tell
SET SQLBLANKLINES ON
allow to completely empty rows in an SQL statement.
-
Hi there, please help me! Here's the problem: I do exercise 3.1 (pag. 54) of the book "Hands on oracle db 10g express edition for windows" but
(1) if I use Sql * Plus, once it executes all the script sql command * more session closed.
(2) if I use cmd, I have this problem
http://i982.Photobucket.com/albums/ae308/Tbeker/1-1958.jpg
http://i982.Photobucket.com/albums/ae308/Tbeker/2-5.jpg
Cuold help you my guy? I don't understand why the table does not exist!
Thank you very much!
Hi clcarter, finally I understood the problems:
(1) on my pc the date of oracle XE is expressed as "Giu-DD-YYYY' because I'm Italian, but in the exercises in the book, the date is in English"JUN-DD-YYYY "; (ORA-01843: not one month valid);
(2) I don't understand the reason but in the exercises, tables or values have been inserted without the "SCHEMA" and the "orders" table was so not all values (error ORA-00942: table or view does not exist);
Now, after a separation of headaches, I can't continue, thank you for your help!
-
PROBLEM WITH SQL QUERY.
Hi all
I am executing the following query, which I use to retrieve unique records.
SELECT OH. ORDER_ID, OH. ORDER_DATE, OH. GRAND_TOTAL, OSI. DESCRIPTION ACE ORDER_STATUS,
PMT. DESCRIPTION AS PAYMENT_METHOD, TR. AS PAYMENT_STATUS DESCRIPTION
OF ORDER_HEADER OH INNER JOIN ORDER_PAYMENT_PREFERENCE OPP ON OH. ORDER_ID = OPP. ORDER_ID and
OPP. CREATED_DATE = (SELECT MAX (CREATED_DATE) OF ORDER_PAYMENT_PREFERENCE WHERE THE ORDER_ID = OH. ORDER_ID)
PAYMENT_METHOD_TYPE PMT, STATUS_ITEM SO, STATUS_ITEM OSI
WHERE OPP. PAYMENT_METHOD_TYPE_ID = PMT. PAYMENT_METHOD_TYPE_ID AND
OPP. BATCH = IF. BATCH AND OH. BATCH = OSI. BATCH AND
(OH. BATCH = "ORDER_CREATED" | OH. BATCH = "ORDER_HOLD") AND
OH. "CREATED_STAMP > = ' 2011-12-03 11:41:04.
Problem I am facing is, for some a few order_ids we have several entries in ORDER_PAYMENT_PREFERENCE with CREATED_DATE even where query return me of duplicate records.
I applied OPP. "CREATED_DATE = (SELECT MAX (CREATED_DATE) OF ORDER_PAYMENT_PREFERENCE WHERE THE ORDER_ID = OH. ORDER_ID)' forced to get the record, unique, but as I said to few recordings, we have several lines in ORDER_PAYMENT_PREFERENCE corr. ORDER_ID single and multiple records have same CREATED_DATE.
Can you suggest a few changes, the query to retrieve unique records.
I know I'm a very abstract information, shortly I'll provide table structure and little info I want in this query.
It's because of the tight work schedule.
Thank you
Jagdeep SinghHello
Basically, you need to convert a number in his order inside each created_date order_payment_preference. However, if you have more than one created_date which is him even you'll actually choose one of them at random unless you specify an order more squeezed by the clause. For example, you might have a numeric value from a sequence that could be added to determine which input was really the most recent. In any case the following should give you an idea what I mean...
SELECT order_id, order_date, grand_total, order_status, payment_method, payment_status FROM ( SELECT oh.order_id, oh.order_date, oh.grand_total, osi.description AS order_status, pmt.description AS payment_method, si.description AS payment_status ROW_NUMBER() OVER(PARTITION BY opp.order_id ORDER BY opp.created_date DESC) rn FROM order_header oh JOIN order_payment_preference opp ON oh.order_id = opp.order_id JOIN payment_method_type pmt ON opp.payment_method_type_id = pmt.payment_method_type_id JOIN status_item si ON opp.status_id = si.status_id JOIN status_item osi ON oh.status_id = osi.status_id WHERE AND oh.status_id IN('ORDER_CREATED','ORDER_HOLD') AND oh.created_stamp >= '2011-12-03 11:41:04' ) WHERE rn = 1
Some notes if - it is not a good idea to mix the styles of the junction between ansi and oracle style, it makes it difficult to follow. Just choose one or the other.
OH.STATUS_ID='ORDER_CREATED' || OH.STATUS_ID='ORDER_HOLD'
Makes no sense. I took a guess that you meant, OR then I converted to an IN clause that will do the same job.
HTH
David
-
problem with sql default_where statement
Hello gurus
I use forms 6i, shaped with blocks of data AREA and the area euro1, their sources of data are derived from a table of unique 'space '.
right side of the form displays the list of all the domain names (one attribute in a table) inserted before the trigger of when_new_form instance (i.e. Grenier1 block).
by clicking on: AREA1.NAME I want to execute the details of corner table block area...
to do this, I specified trigger on_mouse_click
and I call it a procedure on prior requestgo_block('area'); execute_query;
Matching(:Area1.Name);
Code of procedure of correspondence is
It works only 2 or 3 times, but now it gives me the error FRM-40505 unable to execute the queryPROCEDURE matching(c_name in varchar2) IS sql_state varchar2(100); BEGIN ----- if not null then if c_name is not null then sql_state := 'UPPER(name) like ''%'''||UPPER(c_name)||'''%'''; set_block_property('area',default_where,sql_state); else message('feild is empty'); end if; exception when others then display_error; END;
There is no any element non-base of data on two blocks of
What can be the problem, please
Thank youlike ''%' ||UPPER(c_name)|| '%''';
-
Problems with SQL Server availability at the time of the instant withdrawal
I use VMware VCB to backup a virtual computer that is running SQL Server 2005. Hang it works very well when the snapshot was taken, but I'm getting errors in my web applications .NET at the same time that the deletion of the snapshot is in progress. The errors indicate that the SQL Server is not available. Thus, the network does not respond for the snapshot validation process or e/s SQL Server gets interrupted (perhaps through an another quiesce?), when the snapshot is removed. Anyone know why that would happen? Do not hang the OS VMware at time of the instant withdrawal as well?
No patch I know which would cause instant removal to pause the plu VM. 3.5 U2 introduced VSS in the virtual machine, but components that should affect only when a snapshot is created. Also create the snapshot with smack memory made a break the considerably longer VM, but still affects only the creation of the snapshot not the elimination.
If you have found this or other useful information, please consider awarding points to 'Correct' or 'useful '.
-
Hello world:
IM using a 11.1.0.6.0 database running on RHEL 5.
When I use OEM to execute SQL on a SQL advisor sometimes it shows:
Is el perfil SQL "SYS_SQLPROF_014bb22810410002" para esta sentencia there is ha much durante el proceso of adjusts.
Translation: there is a SQL profile "SYS_SQLPROF_014bb22810410002" for this statement and it was ignored during the adjustment process.
what it means? The "SYS_SQLPROF_014bb22810410002" is worse than him actually?
Thank youuser13748341 wrote:
So if the SQL Advisor ignore a profile is because it's worse in fact, right?# The idea of a profile is to correct how the optimizer deals with statistics. Since the reason comes from the shortcomings in the way that statistics tell the optimizer the best thing to do, the Advisor attempts to use additional information to identify gaps. The information may or may not be generally true, so it could be better or worse. The hypothesis is more recent and more information is better, but with changing circumstances and still other deficiencies, it must be the judge. If the new profile is better, fine. If this isn't the case, it's very well also. There may be situations where either is better, too.
Maybe you are looking for
-
AE last gen and stereo receiver: coupling with amplified speakers
Hello I have a TEAC A - H01 receiver I have also a speaker: WIFI Libratone Zipp powered only no Bluetooth. Finally, I have a last gen Airport Express. Here's what I can do: I can use my Libratone with my iPad air2 and Airplay for dissemination and to
-
HP Pavilion DV7-1444us Replace wireless card
I recently updated my HP from Windows Vista to Windows 8. 1. the software works very well but I started having problems connecting to my Modum Cisco home through the Cox cable connection. The computer worked fine for a few weeks then I had to miss t
-
Transfer works of Mac iOS but not iOS for Mac
I get the transfer icon on my screen lock and the bottom of multitasking on my iPhone 6 and first generation iPad look so I have a compatible application Handoff open on my new Macbook or other iOS devices, but I never see a transfer icon on the dock
-
your account has been closed due to violation of the terms and conditions
my e-mail account has been infiltrated and it starts by sending spam to everyone on my contact list, I sent a copy to spam@hotmail, but have now had my account closed. How he reactivated
-
BlackBerry Hub edit email in conversation view project
Hello Can you help me?? I could ' t determine how to modify a draft e-mail (automatically saved) appear in conversation view... What's wrong?? In normal mode, I can modify the project by opening it. Thank you very much for your help! boscha