Unix-pl/sql help reuuired
Sir, I am working for some data warehouse project in which I want to invoke unix shell command from PL/SQL Block, for example, I want to invoke a sql loder from a PL/SQL block. Is it possible. I have searched in all possible resources available with me but couldn't find any solution.
Any sample code will be of great help.
SQL> create table customer(custid varchar2(10),account number,checknos number);
Table created.
SQL> insert into customer values('C10', 124562, 0);
1 row created.
SQL> insert into customer values('c12', 124562, 0);
1 row created.
SQL> insert into customer values('C14', 124562, 0);
1 row created.
SQL> insert into customer values('C16', 124562, 0);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from customer;
CUSTID ACCOUNT CHECKNOS
C10 124562 0
c12 124562 0
C14 124562 0
C16 124562 0
SQL> merge INTO customer p USING
2 (SELECT t.*,row_number() over(order by custid ASC) rnum FROM customer t
3 ) q ON (p.custid=q.custid)
4 WHEN matched then
5 UPDATE SET p.checknos=q.rnum+9000;
4 rows merged.
SQL> select * from customer;
CUSTID ACCOUNT CHECKNOS
C10 124562 9001
c12 124562 9004
C14 124562 9002
C16 124562 9003
SQL> Use merge for maintaining the row order...I remember this done by someone the other day....
Ravi Kumar
Similar Messages
-
Sir, I am working for some data warehouse project in which I want to invoke unix shell command from PL/SQL Block, for example, I want to invoke a sql loder from a PL/SQL block. Is it possible. I have searched in all possible resources available with me but couldn't find any solution.
Any sample code will be of great help.You can try either of these, I don't know about the second one, I think you have to search that site for a Pl/SQL package to execute host commands.
http://www.ckamco.com/Execute_Command.zip
http://www.quest-pipelines.com/Pipelines/PLSQL/archives.htm#code -
Hi again
I need some PIVOT sql help
In this query:
SELECT
SUM([RATES]) as RATES
,SUM([CONVERSION])as CONVERSION
FROM REPORTING
outputs
RATES CONVERSION
23 234
How would change this query to display a table like:
Name Amount
RATES 23
CONVERSION 234
Keep up the good work !nikos101 wrote:
> How would change this query to display a table like:
Do you *HAVE* to change the query... you could just display
it in the
desired format if that it the ultimate and only goal.
<table>
<tr>
<td>name</td>
<td>amount</td>
</tr>
<cfoutput query="sumQry">
<tr><td>Rates</td><td>#rates#</td></tr>
<tr><td>Conversion</td><td>#conversion#</td></tr>
</cfoutput>
</table> -
JDBC Connection between Unix and SQL Server 2000
I have SQL Server 2000 installed in a pc as a data server and SQL Server 2000 JDBC Drive installed in a Unix machine. Both machines are connected and can ping each other. After setting up the environment data, I ran a test code to test the connection and got exceptions. ( I did the same process between a pc and the data server, it works well.)
Attached are the test code and error message. Hope someone can help me.
******* Test Code ********
import java.sql.*;
* Microsoft SQL Server JDBC test program
public class Test {
public Test() throws Exception {
// Get connection
DriverManager.registerDriver(new
com.microsoft.jdbc.sqlserver.SQLServerDriver());
Connection connection = DriverManager.getConnection(
"jdbc:microsoft:sqlserver://<hostname>","<username>","<password>");
if (connection != null) {
System.out.println();
System.out.println("Successfully connected");
System.out.println();
// Meta data
DatabaseMetaData meta = connection.getMetaData();
System.out.println("\nDriver Information");
System.out.println("Driver Name: "
+ meta.getDriverName());
System.out.println("Driver Version: "
+ meta.getDriverVersion());
System.out.println("\nDatabase Information ");
System.out.println("Database Name: "
+ meta.getDatabaseProductName());
System.out.println("Database Version: "+
meta.getDatabaseProductVersion());
} // Test
public static void main (String args[]) throws Exception {
Test test = new Test();
******* error message ********
Exception in thread "main" java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
at java.lang.Throwable.fillInStackTrace(Native Method)
at java.lang.Throwable.fillInStackTrace(Compiled Code)
at java.lang.Throwable.<init>(Compiled Code)
at java.lang.Exception.<init>(Compiled Code)
at java.sql.SQLException.<init>(SQLException.java:64)
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Compiled Code)
at java.sql.DriverManager.getConnection(DriverManager.java:137)
at Test.<init>(Test.java:10)
at Test.main(Test.java:32)
************ end of message ***********If it works from a PC and not from the Unix box then you may have a network issue of some sort, I.E. firewall not letting it through etc.
Try using telnet on the Unix box to see if you can connect to the sql server on the port that the SQL server is listening.
E.G.
telnet server_name 1433
You may need to change the port number to the one that the SQL server is using.
Col -
Spool Russian Characters from a unix(AIX) sql script
Hi All,
I have a problem selecting and spooling a column whose characters are in russian to a flat file. If I use oracle sql developer, the data comes out right, e.g
Р-Н ТАШКЕНТ
However is i try to run the same select from a unix sql script and spool the results, I get some gibberish like:
ò-î ôáûëåîô or a chain of question marks ?????????
select * from nls_database_parameters gives:
NLS_LANGUAGE=AMERICAN
NLS_TERRITORY=AMERICA
NLS_CHARACTERSET=UTF8
NLS_NCHAR_CHARACTERSET=AL16UTF16
I have tried exporting the environment variable using these various options individially to no avail:
export NLS_LANG=RUSSIAN_CIS.CL8MSWIN1251
RUSSIAN_RUSSIA.RU8PC866
RUSSIAN_RUSSIA.CL8KOI8R
RUSSIAN_RUSSIA.CL8MACCYRILLICS
RUSSIAN_RUSSIA.RU8PC855
RUSSIAN_RUSSIA.RU8BESTA
RUSSIAN_RUSSIA.CL8ISO8859P5
Please help.
Thanks,
Edited by: HouseofHunger on Apr 12, 2012 4:02 PMOs version: AIX 6.1.0.0
Database version: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit
with the default values for NLS_LANG, I run sqlplus
sqlplus user/password@oracle_sid
select column_name from table_name;
and the output is:
column_name
I exit and export NLS_LANG=RUSSIAN_CIS.CL8ISO8859P5
go back into sqlplus and run the same query as above, and the output is
column_name
À-½ °Ⱥµ½Â
À-¾½ ÃÀ°ǸÀǸºÁº¸¹
°Ⱥµ½Â
°Ⱥµ½Â
¾»Â¸½¾¹ À-¾½
³ ±µº°±°´
ΠǸÀǸºÁº¸¹ À-½ ÷±µº¸ÁÂ
Ä°À³¾½°
Ϻº°Á°À°¹Áº¸¹
°Ⱥµ½Â
Á°¼°Àº°½´
So it seems the output I get is somehow influenced by the value of environment variable NLS_LANG, so it may be that either I need the correct value for this environment variable or I need some config on the OS level.....?
Also the command locale -a gives following output - I am not very good on locales, so it maybe that the russian local isn't installed...?
$ locale -a
C
POSIX
en_US.8859-15
en_US.ISO8859-1
en_US
Thanks -
SQL help: return number of records for each day of last month.
Hi: I have records in the database with a field in the table which contains the Unix epoch time for each record. Letz say the Table name is ED and the field utime contains the Unix epoch time.
Is there a way to get a count of number of records for each day of the last one month? Essentially I want a query which returns a list of count (number of records for each day) with the utime field containing the Unix epoch time. If a particular day does not have any records I want the query to return 0 for that day. I have no clue where to start. Would I need another table which has the list of days?
Thanks
RayPeter: thanks. That helps but not completely.
When I run the query to include only records for July using a statement such as following
============
SELECT /*+ FIRST_ROWS */ COUNT(ED.UTIMESTAMP), TO_CHAR((TO_DATE('01/01/1970','MM/DD/YYYY') + (ED.UTIMESTAMP/86400)), 'MM/DD') AS DATA
FROM EVENT_DATA ED
WHERE AGENT_ID = 160
AND (TO_CHAR((TO_DATE('01/01/1970','MM/DD/YYYY')+(ED.UTIMESTAMP/86400)), 'MM/YYYY') = TO_CHAR(SYSDATE-15, 'MM/YYYY'))
GROUP BY TO_CHAR((TO_DATE('01/01/1970','MM/DD/YYYY') + (ED.UTIMESTAMP/86400)), 'MM/DD')
ORDER BY TO_CHAR((TO_DATE('01/01/1970','MM/DD/YYYY') + (ED.UTIMESTAMP/86400)), 'MM/DD');
=============
I get the following
COUNT(ED.UTIMESTAMP) DATA
1 07/20
1 07/21
1 07/24
2 07/25
2 07/27
2 07/28
2 07/29
1 07/30
2 07/31
Some dates donot have any records and so no output. Is there a way to show the missing dates with a COUNT value = 0?
Thanks
Ray -
URGENT!! problems with Unix command, please help
I am trying to use the following Unix command and I keep getting error messaages from stdError. However if I run the same command from the command line it works perfectly. For some reason when I run the command from inside the program it thinks the append symbol ">>" is another file.
String command = " cat /users/02/wjoc1/Test/list.mod >> /users/02/wjoc1/Test/Blacklist ";
Process p = Runtime.getRuntime().exec(command);
The error get is :
/bin/cat: >>: No such file or directory
Any help would be greatly appreciatedThe better solution for this problem is write a shell script for the action you wnat to perform and execute it using the runtime.exec().In your case just cut and paste cat /users/02/wjoc1/Test/list.mod >> /users/02/wjoc1/Test/Blacklist in to a file and save it. use that file as a argument for the exec method it will work.
cheers
R.Karuna -
My installation of OAS 4.0.8.1 on Digital Unix
4.0F is failing when it comes to try to
relink something called ntcontab.o
, an apparently missing header file :
cc: Severe: /usr/include/sys/types.h, line 77:
Cannot find file <standards.h> specified in #include directive.
(I did find the header file on the system but in a different place.
I tried a link to make it
appear where it should but that didn't work for
some reason)
My release notes specify 4.0D is required,
maybe thats the problem, though I wouldn't
expect a whole header file to be moved between
minor releases.
Any help very gratefully recieved. I am really
stuck.
Thanks
Alan McCulloch
email : [email protected]
BTW - I'm new to Digital Unix, previously
worked on Solaris. My subjective impression is Digital
Unix is alot less well supported and prevalent
than Solaris, and my feeling is we would
be more secure on Solaris.
Is this at all a valid point of view ? I'd
be very happy to be wrong about this !
nullHi Peter,
I believe that functionality was broken in the field test version of coordinate systems that shipped in 8.1.6 only for transforming data stored in the SDO_POINT type. I'm not sure, but I doubt this will be patched on tru64 unix.
If you need to get this working you might want to try storing your point data using the elem_info_array and the ordinate array rather than the optimized point type.
This problem is fixed in 8.1.7.
Hope this helps,
dan -
Hello,
I am having a query as a part of my procedure block that extracts the following xml and stores it into a variable that is of xmltype:
<FeatureRoot>
<Feature>
<FeatureName>qaz</FeatureName>
<FeatureAction>Add</FeatureName>
</Feature>
<Feature>
<FeatureName>wsx</FeatureName>
<FeatureAction>Remove</FeatureAction>
</Feature>
</FeatureRoot>
Now what i want to do is loop through this variable (which is of xmltype) and print the values of the tags <FeatureName> and <FeatureAction> for every Feature.
(ie)
qaz Add
wsx Remove
Can you please tell me how i can loop through to extract the values?
Many Thanks,
Kalyaniuser11912174 wrote:
Hello,
Thank you. The solutions may hold good on a normal context. What my problem is I want to run a loop through an anonymous block in pl/sql where I am already using a cursor where each record contains an xml value as above. So i need to be extracting for each run in a cursor. So i need to be extracting the <FeatureName> and <featureaction> values in each cursor run. Any help on this?
ThanksCan you not incorporate it as part of the cursor itself?
It can return the values as part of the data from the cursor rather than using PL/SQL extracts on the XML to do it.
SQL> ed
Wrote file afiedt.buf
1 with myxml as
2 (select xmltype('<FeatureRoot>
3 <Feature>
4 <FeatureName>qaz</FeatureName>
5 <FeatureAction>Add</FeatureAction>
6 </Feature>
7 <Feature>
8 <FeatureName>wsx</FeatureName>
9 <FeatureAction>Remove</FeatureAction>
10 </Feature>
11 </FeatureRoot>') myxml from dual union all
12 select xmltype('<FeatureRoot>
13 <Feature>
14 <FeatureName>aaa</FeatureName>
15 <FeatureAction>Add</FeatureAction>
16 </Feature>
17 <Feature>
18 <FeatureName>bbb</FeatureName>
19 <FeatureAction>Remove</FeatureAction>
20 </Feature>
21 </FeatureRoot>') from dual)
22 select extractvalue(VALUE(t),'/Feature/FeatureName') featurename
23 , extractvalue(VALUE(t),'/Feature/FeatureAction') featureaction
24 from myxml x
25* , table(xmlsequence(extract(x.myxml,'/FeatureRoot/Feature'))) t
SQL> /
FEATURENAME FEATUREACTION
qaz Add
wsx Remove
aaa Add
bbb Remove
SQL> -
I do not know if this is the right place for thius type of post. If it is not please advise where the right place is.
I need help generating a report, hopefully with SQL in 8.1.7
SQL Statement which produced the data below the query :
SELECT CHANGE.change_number, CHANGE.route_date as DATE_TO_CCB, nodetable.description AS Approver_required, (TRIM(BOTH ',' FROM CHANGE.PRODUCT_LINES)) AS PRODUCT_LINES /*, PROPERTYTABLE.VALUE as PRODUCT_LINES */
FROM CHANGE, signoff, workflow_process, nodetable /*, PROPERTYTABLE */
WHERE ( (CHANGE.ID = signoff.change_id)
AND (CHANGE.process_id = signoff.process_id)
AND ((nodetable.id = signoff.user_assigned) or (nodetable.id=signoff.user_signed))
AND (CHANGE.process_id = workflow_process.ID)
AND (CHANGE.ID = workflow_process.change_id)
AND (CHANGE.workflow_id = workflow_process.workflow_id)
AND (SIGNOFF.SIGNOFF_STATUS=0 )/* in (0, 2, 3)) */ /* 0=request needs attention, 2=request approved, 3=request rejected */
AND (SIGNOFF.REQUIRED=5 or SIGNOFF.REQUIRED=1) /* 1=Approver 5= Ad Hoc Approver */
AND (CHANGE.IN_REVIEW=1)
AND (CHANGE.RELEASE_DATE IS NULL)
AND (CHANGE.CLASS != '4928')
/* AND (PROPERTYTABLE.PROPERTYID IN (SELECT TRIM(BOTH ',' FROM CHANGE.PRODUCT_LINES) FROM CHANGE)) */
order by change.route_date desc
**** Results **********
CHANGE_NUMBER|DATE_TO_CCB|APPROVER_REQUIRED|PRODUCT_LINES
C02190|11/14/2008 3:34:02 PM|Anurag Upadhyay|270354,270362|
C02190|11/14/2008 3:34:02 PM|Dennis McGuire|270354,270362|
C02190|11/14/2008 3:34:02 PM|Hamid Khazaei|270354,270362|
C02190|11/14/2008 3:34:02 PM|Mandy York|270354,270362|
C02193|11/14/2008 3:05:18 PM|Hamid Khazaei|274279,266339,266340,266341|
C02193|11/14/2008 3:05:18 PM|Rob Brogle|274279,266339,266340,266341|
C02193|11/14/2008 3:05:18 PM|Xavier Otazo|274279,266339,266340,266341|
C02193|11/14/2008 3:05:18 PM|san|274279,266339,266340,266341|
C02194|11/14/2008 2:51:34 PM|Diana Young|271503|
C02194|11/14/2008 2:51:34 PM|Carl Krentz|271503|
C02194|11/14/2008 2:51:34 PM|Dennis Yen|271503|
C02194|11/14/2008 2:51:34 PM|Gordon Ries|271503|
C02194|11/14/2008 2:51:34 PM|Sunil Khatana|271503|
M00532|11/13/2008 1:34:42 PM|Dennis Yen|270356,270354,270360,274279,266339,266340,266341,276780,260784|
M00532|11/13/2008 1:34:42 PM|Jin Hong|270356,270354,270360,274279,266339,266340,266341,276780,260784|
M00532|11/13/2008 1:34:42 PM|Sunil Khatana|270356,270354,270360,274279,266339,266340,266341,276780,260784|
Each value in the numeric comma delimited string has a corresponding ID for the actual test string value in another table as shown below.
PROPERTYID|VALUE
260775|product 1
260776|Product 2
260777|Product x
260778|Product y
260779|Internal
260780|ORCA
260781|Tiger
260782|Orange product
260783|Restricted
260784|Product zz
266259|Product YYY
266260|Hercules
266261|Tangerine
*****Desired output****
CHANGE_NUMBER|DATE_TO_CCB|APPROVER_REQUIRED|PRODUCT_LINES
C02190|Nov/14/2008 03:34:02 PM|Anurag Upadhyay, Dennis McGuire, Hamid Khazaei, Mandy York|Product Y,Product 1
C02193|Nov/14/2008 03:05:18 PM|Hamid Khazaei, Rob Brogle, Xavier Otazo, san|Hercules,Apple,Product 3,Product zz
C02194|Nov/14/2008 02:51:34 PM|Diana Young, Carl Krentz, Dennis Yen, Gordon Ries, Sunil Khatana|Product 2
M00532|Nov/13/2008 01:34:42 PM|Dennis Yen, Jin Hong, Sunil Khatana|Product 1,Product 4,product yy,product YYY,ORCA,Tiger,Orange product,RestrictedHi,
Here's how you can do it in Oracle 8.1.
To get the individual sub-strings from product_lines, join your current result set to this "counter table"
( SELECT ROWNUM AS n
FROM all_objects
WHERE ROWNUM <= 10 -- upper bound on number of items
) cntrIf you don't know the worst case of how many items might be in product_lines, it's a little more complicated:
( SELECT ROWNUM AS n
FROM all_objects
WHERE ROWNUM <= 1 +
SELECT MAX ( LENGTH (product_lines)
- LENGTH (REPLACE (product_lines, ','))
FROM table_name
) cntrJoin this to the existing result set like this
WHERE ...
AND INSTR ( product_lines || ',' -- one extra comma added
, 1
, n
) > 0When you do the join, you will have
one copy of all the rows with one item in producgt_lines,
two copies of all the rows with two items in producgt_lines,
three copies of all the rows with three items in producgt_lines,
and so on.
When a row has been copied, each copy will have a different value of cntr.n.
To extract the n-th substring from product_lines:
SELECT ...
SUBSTR ( product_lines
, INSTR ( ',' || product_lines, ',', 1, n)
, ( INSTR (product_lines || ',', ',', 1, n)
- INSTR (',' || product_lines, ',', 1, n)
) AS product_lines_itemWhen you have derived this column, you can join to the table with the translations
WHERE TO_NUMBER (product_lines_item) = propertyidTo combine these rows into one row with a comma-delimited list, GROUP BY all the columns you want to select except the property_value ('produc 1', 'tangerine', etv.), and SELECT:
LTRIM ( MAX (CASE WHEN n = 1 THEN ',' || property_value END) ||
MAX (CASE WHEN n = 2 THEN ',' || property_value END) ||
MAX (CASE WHEN n = 10 THEN ',' || property_value END)
)I don't know a good way to re-combine the rows in Oracle 8 without assuming some limit on the number of items. I assumed there would never be more than 10 in the example above. You can say 20 or 100, I suppose, if you want to. If you guess too high, everything will still work: the query will just be slower.
This is a just one example of why packing several values into a single column is a bad idea. -
MACAPPLE extension - unix executable file - help!!
Hi all,
I have a program that has a install icon with MACAPPL extension ( *.macappl) ,
Anyone knows how to open / install it?
thanks for help
Mucho
iMac g5 Mac OS X (10.4.8)I created a file with the hex string 1F 07 00 3F 68 78 78 78 . I ran at the Unix file command against this string and got the following:
mac $ cd Desktop
mac $ pwd
/Users/mac/Desktop
mac $ ls -l hex
-rw-r--r-- 1 mac staff 8 Nov 7 16:15 hex
mac $ file hex
hex: DIF (DV) movie file (NTSC)
mac $
in particular this is the resulting string:
DIF (DV) movie file (NTSC)
looking through google on this string, there appears to be converters. The string is:
DIF (DV) movie file (NTSC) convert mac
I am not familiar with video files so I can only tell you this much.
Robert -
Configuring odbc.ini in Unix for SQL data sources in EAS
Hi All,
The first question I have is, which odbc.ini file should I edit?
The tech reference says navigate to /home/Common/ODBC/Merant/x.x/odbc.ini but I have 5 folders under Merant...
5.3
6.0
6.0SP1
6.1
7.0.1
The main problem I have is making the new connection show in EAS client, I have edited all the 5 of the ODBC.ini files on our Unix essbase server to include our DB name and left the values as default (for testing purposes), what I have found is that the new connection name does not appear in the SQL data sources as a drop down menu, do I need to restart anything to make the new value show in EAS?
OBIEDB=DataDirect 6.0 Oracle Wire Protocol
[OBIEDB]
Driver=/u02/oracle/obi11d/fmw/Oracle_BI1/common/ODBC/Merant/6.0/lib/ARora24.so
Description=DataDirect 6.0 Oracle Wire Protocol
AlternateServers=
ApplicationUsingThreads=1
ArraySize=60000
AuthenticationMethod=1
BulkBinaryThreshold=32768
BulkCharacterThreshold=-1
BulkLoadBatchSize=1024
CachedCursorLimit=32
CachedDescLimit=0
CatalogIncludesSynonyms=1
CatalogOptions=0
ConnectionRetryCount=0
ConnectionRetryDelay=3
DefaultLongDataBuffLen=1024
DescribeAtPrepare=0
EnableBulkLoad=0
EnableDescribeParam=0
EnableNcharSupport=0
EnableScrollableCursors=1
EnableStaticCursorsForLongData=0
EnableTimestampWithTimeZone=0
EncryptionMethod=0
FailoverGranularity=0
FailoverMode=0
FailoverPreconnect=0
FetchTSWTZasTimestamp=0
GSSClient=native
HostName=<Oracle_server>
HostNameInCertificate=
InitializationString=
KeyPassword=
KeyStore=
KeyStorePassword
LoadBalanceTimeout=0
LoadBalancing=0
LocalTimeZoneOffset=
LockTimeOut=-1
LoginTimeout=15
LogonID=
MaxPoolSize=100
MinPoolSize=0
Password=
Pooling=0
PortNumber=<Oracle_server_port>
ProcedureRetResults=0
QueryTimeout=0
ReportCodePageConversionErrors=0
ReportRecycleBin=0
ServerName=<server_name in tnsnames.ora>
ServerType=0
ServiceName=
SID=<Oracle_System_Identifier>
TimestampeEscapeMapping=0
TNSNamesFile=<tnsnames.ora_filename>
TrustStore=
TrustStorePassword=
UseCurrentSchema=1
ValidateServerCertificate=1
WireProtocolMode=1To answer my own question, the path to the true odbc.ini file is located here...ORACLE_INSTANCE/config/OPMN/opmn/opmn.xml, in my case, EAS was refering to an odbc.ini file located in my ARBORPATH and not /u02/oracle/obi11d/fmw/Oracle_BI1/common/ODBC/Merant/6.0/lib/ARora24
-
Please help ...
Data Sample:
A1 B1C1 D1
01 A 06/30/2008 1
01 B 06/10/2008 1
01 C 06/09/2008 1
01 D 06/09/2008 1
02 A 06/20/2008 1
02 C 06/20/2008 1
03 A 06/20/2008 1
04 A 06/10/2008 2
04 B 06/10/2008 1
04 C 06/09/2008 1
04 C 06/09/2008 1
Output Should be:
01 A 06/30/2008 1
02 A 06/20/2008 1
02 C 06/20/2008 1
03 A 06/20/2008 1
04 A 06/10/2008 2
Rules:
- Top D1 should be selected.
- If there are tie in D1 per A1, should be looking for C1 for the latest date
- if there are tie for the D1 and C1 per A1 this data should be selected
- if there are only one D1 which is the latest then inly 1 record will be selected.Hi,
try this:
SQL> with t as ( -- "sample data"
2 select '01' a1, 'A' b1, to_date('06/30/2008','mm/dd/yyyy') c1, 1 d1 from dual union all
3 select '01', 'B', to_date('06/10/2008','mm/dd/yyyy'), 1 from dual union all
4 select '01', 'C' , to_date('06/09/2008','mm/dd/yyyy'), 1 from dual union all
5 select '01', 'D' , to_date('06/09/2008','mm/dd/yyyy'), 1 from dual union all
6 select '02', 'A' , to_date('06/20/2008','mm/dd/yyyy'), 1 from dual union all
7 select '02', 'C' , to_date('06/20/2008','mm/dd/yyyy'), 1 from dual union all
8 select '03', 'A' , to_date('06/20/2008','mm/dd/yyyy'), 1 from dual union all
9 select '04', 'A' , to_date('06/10/2008','mm/dd/yyyy'), 2 from dual union all
10 select '04', 'B' , to_date('06/10/2008','mm/dd/yyyy'), 1 from dual union all
11 select '04', 'C' , to_date('06/09/2008','mm/dd/yyyy'), 1 from dual union all
12 select '04', 'C' , to_date('06/09/2008','mm/dd/yyyy'), 1 from dual
13 ) -- "end sample data"
14 select a1, b1, c1, d1
15 from (select a1, b1, c1, d1,
16 max(c1) over(partition by a1) mxc1,
17 max(d1) over(partition by a1) mxd1,
18 min(d1) over(partition by a1) mind1
19 from t)
20 where 1 = case when mind1 = mxd1 then
21 case when c1 = mxc1 then 1 end
22 else case when d1 = mxd1 then 1 end
23 end
24 /
A1 B1 C1 D1
01 A 6/30/2008 1
02 A 6/20/2008 1
02 C 6/20/2008 1
03 A 6/20/2008 1
04 A 6/10/2008 2 -
SQL help please. !!!!!!!!!!
hi
i need some help on the following problem. let's say i have a sql select that return the following rows
ME
EL
EO
FA
these are 4 rows of data returned by executing "select column1 from myTable where somecondition = true". however, i need to display these results as follow
MW,EL,EO,FA
which is just one row and they are concatenated as one result. is there any way to modify the sql to do it? your help is much appreciated. thankshi
i need some help on the following problem. let's say i
have a sql select that return the following rows
ME
EL
EO
FA
these are 4 rows of data returned by executing "select
column1 from myTable where somecondition = true".
however, i need to display these results as follow
MW,EL,EO,FA
which is just one row and they are concatenated as one
result. is there any way to modify the sql to do it?
your help is much appreciated. thanksit would be easier if you ahead know how many rows you going to get...
select
"row1" = select blah from table where blah = '1',
"row2" = select blah from table where blah = '2',
"row3" = select blah from table where blah = '3',
"row4" = select blah from table where blah = '4'
from table
make sure the sub select must return one record only... -
SQL help: Selecting tickets with no open tasks
Hi Gurus,
I'm new to SQL. I need your help in a script where I need to fetch the tickets with no open tasks.
Say, following is the Task table
Table: Task
| ticketid | taskid | taskstatus |
| 1 | 1 | O |
| 1 | 2 | O |
| 1 | 3 | O |
| 2 | 4 | C |
| 2 | 5 | C |
| 3 | 6 | C |
| 3 | 7 | O |
The query should return the ticketid(s) with all its taskstatus = 'C'.
Any help would be highly appreciated.
ThanksHi Surya,
Here's an Oracle style example (Sorry, I just can't do that ansi stuff)
SQL> with ticket as (select 1 ticketid, 'C' reason from dual union all
select 2 ticketid, 'O' reason from dual union all
select 3 ticketid, 'O' reason from dual union all
select 4 ticketid, 'C' reason from dual)
,taskstatus as (select 1 taskstatusid, 'O' taskstatus from dual union all
select 2 taskstatusid, 'C' taskstatus from dual union all
select 3 taskstatusid, 'P' taskstatus from dual union all
select 4 taskstatusid, 'F' taskstatus from dual union all
select 5 taskstatusid, 'O' taskstatus from dual union all
select 6 taskstatusid, 'C' taskstatus from dual union all
select 7 taskstatusid, 'P' taskstatus from dual union all
select 8 taskstatusid, 'F' taskstatus from dual)
,task as (select 1 ticketid, 1 taskid, 2 taskstatusid from dual union all
select 1 ticketid, 2 taskid, 3 taskstatusid from dual union all
select 1 ticketid, 3 taskid, 4 taskstatusid from dual union all
select 1 ticketid, 4 taskid, 4 taskstatusid from dual union all
select 2 ticketid, 5 taskid, 1 taskstatusid from dual union all
select 2 ticketid, 6 taskid, 1 taskstatusid from dual union all
select 2 ticketid, 7 taskid, 1 taskstatusid from dual union all
select 3 ticketid, 8 taskid, 2 taskstatusid from dual union all
select 3 ticketid, 9 taskid, 2 taskstatusid from dual union all
select 3 ticketid, 10 taskid, 6 taskstatusid from dual union all
select 4 ticketid, 11 taskid, 2 taskstatusid from dual union all
select 4 ticketid, 12 taskid, 6 taskstatusid from dual union all
select 4 ticketid, 13 taskid, 4 taskstatusid from dual union all
select 4 ticketid, 14 taskid, 8 taskstatusid from dual)
select a.ticketid, c.taskstatus
from task a, ticket b, taskstatus c
where a.ticketid = b.ticketid
and c.taskstatusid = a.taskstatusid
and (c.taskstatus = 'C' or c.taskstatus = 'F')
and b.reason = 'C'
and not exists (select null
from task a1, taskstatus c1
where a1.ticketid = a.ticketid
and c1.taskstatusid = a1.taskstatusid
and (c1.taskstatus = 'O' or c1.taskstatus = 'P'))
order by 1,2
TICKETID T
4 C
4 C
4 F
4 F
4 rows selected.Please note, how I made test data, that way is much more helpful than your tables
Regards
Peter
Maybe you are looking for
-
Trouble Installing CS5.5 Prod Prem Education Edition on New Win7 64bit
I am having the following errors after building a brand new Win 7 64bit machine. It has every Windows update and is running perfect otherwise. Here is my error log; Exit Code: 6 -------------------------------------- Summary -------------------------
-
Java Instalation Failed. ~Please Help?~
When i get to the installation step of download Java Version 6 Update 16 this error shows up. Error Msg: Installation Failed The wizard was interrupted before Java(TM) 6 Update 16 could be completely installed. To complete installation at another tim
-
Height of the richtexteditor dialog
Can we set the height of the richtext editor dialog? Is it possible to show more than 8 lines in the Rich Text component? When formatting multiple lines of text, it is easier to have more lines visible in the component dialog, having more room to wor
-
How can I download Blackberry Maps in my 8800?
It appears that my Blackberry 8800 device did not come with the pre-loaded Blackberry Maps, as I cannot activate the Maps (GPS) or find the Maps in the Service Book list. Is it possible to download the Maps into my phone? If so, how do I do it? I con
-
Wireless speed keeps slowing down on Early 2008 Macbook
My girlfriend has an early 2008 white Macbook. After four months from buying it her wireless connection began giving her trouble. After a few minutes of using the computer her internet speed would drop to almost nothing, this would prevent all her us