need to customize SQL query verification
Friends,I need to create a custom sql query. Please see the following scenarios:
I want to audit all users who are successfully and unsuccessfully to logon to my oracle database. Tahts why I enbale 2 following options:
SQL > session audit every time that successful;
Verification succeeded.
SQL > noaudit session each time it fails.
Verification succeeded.
And I found all the users using the following sql query:
"Select username, to_char (timestamp," MM/DD/YY HH24 ' ") Timestamp, obj_name, returncode, action_name of."
"dba_audit_trail where action_name in ('LOGIN', 'LOGOUT') order by timestamp desc '.
USERNAME TIMESTAMP OBJ_NAME RETURN_CODE ACTION_NAME
-------- --------- -------- ------------- -----------
RIPON 14-12-08 11:51 0 LOGON
SHIPON 14-12-08 11:50 1017 LOGON
RIPON 14-12-08 11:50 1017 LOGON
Here, return_code = 1017 means the user cannot successfully loged on
and, return_code = 0 the average user can successfully connected
Now, I want to custom to the query that is readable to others easily. As
I want to add a column, which meets the follwing If condition.
Return_code = 0, then the column is 'USER CORRECTLY CONNECTED ON' and
If return_code = 1017, then the column displays "USER NOT CORRECTLY CONNECTED ON".
can someone please help with this?
Edited by: shipon_97 14 December 2008 13:28
A CASE statement is probably the easiest option
select username,
to_char(timestamp,'MM/DD/YY HH24:MI') Timestamp,
obj_name,
returncode,
action_name,
(CASE WHEN return_code = 0 THEN 'User logged in successfully'
WHEN return_code = 1017 THEN 'User specified an invalid password'
ELSE 'User failed to log in for some other reason'
END) reason_desc
from dba_audit_trail
where action_name in ('LOGON','LOGOFF')
order by timestamp desc
Note that any nonzero return code indicates a failed to connect. ORA-01017 indicates an invalid user name or password, which is probably the most common error.
Justin
Tags: Database
Similar Questions
-
need help with sql query dates
Hello
I have a sql query I need to extract some info between data dates. Where clause in this query is:
WHERE CPD_BUS_UNIT =: ESI_PRM_1
AND CPD_VOUCHER_DATE > =: P_DATE_FROM
AND CPD_VOUCHER_DATE < (: P_DATE_TO + 1).
When I run the query into a toad, I can view the data, but not the execution plan. It gives an error ORA-00932 inconsistent Datatypes.
But when I remove (+ 1): P_DATE_TO, I can c the execution plan and data. The data will be different from the previous.
Please suggest how to rewrite the query.Can you please give it a try?
WHERE CPD_BUS_UNIT=:ESI_PRM_1 AND CPD_VOUCHER_DATE >= :to_date(P_DATE_FROM) AND CPD_VOUCHER_DATE < (to_date(:P_DATE_TO)+1)
Concerning
-
Dear all,
I have a sql like query below
SELECT min (G.TRANSACTION_DATE), D.REQUEST_NUMBER
MTL_TXN_REQUEST_HEADERS D,.
MTL_TXN_REQUEST_LINES, E.
MTL_MATERIAL_TRANSACTIONS G,.
Mtl_Transaction_Types I have
WHERE D.HEADER_ID = E.HEADER_ID
AND G.TRANSACTION_TYPE_ID = I.TRANSACTION_TYPE_ID
AND Upper (I.Transaction_Type_Name) = Upper ('TEC outcome')
AND E.LINE_ID = G.MOVE_ORDER_LINE_ID
AND D.MOVE_ORDER_TYPE = 5
TO_DATE (G.TRANSACTION_DATE) BETWEEN TO_DATE('01-JAN-2014') AND TO_DATE('31-DEC-2014')
D.REQUEST_NUMBER GROUP
I need to get the first number of the application and finally ask for number based on the date of the transaction, how can I get the number of name application and based on the date of the transaction for the same query, please help me.
above query is back under results
If the query should return a line with the number of application like 2383 based on minimum transaction date and another column based on the maximum transaction date, please help me.
so in the example above, it must return
FIRST REQUEST NUMBER LAST NUMBER
2383 1886
Thank you
select min(request_number) keep(dense_rank first order by transaction_date asc ) request_number_min , min(request_number) keep(dense_rank first order by transaction_date desc) request_number_max from ( select min(g.transaction_date) transaction_date , d.request_number from mtl_txn_request_headers d , mtl_txn_request_lines e , mtl_material_transactions g , mtl_transaction_types i where d.header_id = e.header_id and g.transaction_type_id = i.transaction_type_id and upper(i.transaction_type_name) = upper('WIP Issue') and e.line_id = g.move_order_line_id and d.move_order_type = 5 and to_date(g.transaction_date) between to_date('01-jan-2014') and to_date('31-dec-2014') group by d.request_number )
-
Need help with sql query performance
Dear all,
I have a sql like query below, I need to give the following query please help me identify which statement I should tune to have better performanece.
Select rownum LINE_NUM,
A.LINE_ID,
TO_CHAR (A.INVITMID),
TO_NUMBER (A.PICKQTY),
UNLOADINGPNT NULL,
RRNUM NULL,
WORKORDNUM NULL,
WORKORDDESC NULL,
A.PONUM,
DTR_DUMB NULL,
A.DESCRIPTION,
FROM_SUB NULL,
TO_SUB NULL,
NO SOURCE,
ASSET_NUMBER NULL,
A.RECEIPTNUM,
MOVEORD NULL,
FROM_LOC NULL,
TO_LOC NULL,
MSD_NUM NULL,
CONTAIN_LINE NULL,
A.UOM,
A.PO_RELEASE
de)
Select headerid Po.Po_Header_Id,
rcv1. Po_Line_Id LINE_ID,
rcv1.item_id INVITMID,
(NVL(Rcv1.Transact_Qty,0)-NVL(rcv2.transact_qty,0)) PICKQTY,
Po.Segment1 PONUM,
Rcv1.Receipt_Num RECEIPTNUM,
Rcv1.Item_Desc DESCRIPTION,
Rcv1.Transact_Uom GLU,
Rcv1.Po_release
Po_Headers_All in.,.
(Select rcv3. Po_Header_Id, RCV3.receipt_num, rcv3. Po_Line_Id, rcv3. Destination_Type_Code, rcv3. Item_Id, rcv3. Item_Desc, rcv3. Transact_Uom, SUM (rcv3. Transact_Qty) Transact_Qty, rcv3. PO_RELEASE OF)
SELECT A.Po_Header_Id,
C.RECEIPT_NUM receipt_num,
A.Po_Line_Id,
A.Destination_Type_Code,
B.Item_Id,
B.item_description Item_Desc,
A.UNIT_OF_MEASURE Transact_Uom,
A.QUANTITY Transact_Qty,
D.RELEASE_NUM PO_RELEASE
OF RCV_TRANSACTIONS,.
RCV_SHIPMENT_HEADERS C.
B RCV_SHIPMENT_LINES,
PO_RELEASES_ALL D
WHERE C.SHIPMENT_HEADER_ID = A.SHIPMENT_HEADER_ID
AND B.SHIPMENT_LINE_ID = A.SHIPMENT_LINE_ID
AND UPPER (A.Transaction_Type) = "to DELIVER".
AND higher (A.Destination_Type_Code) = "EXPENSES".
AND D.PO_RELEASE_ID = A.PO_RELEASE_ID
UNION ALL
SELECT A.Po_Header_Id,
C.RECEIPT_NUM receipt_num,
A.Po_Line_Id,
A.Destination_Type_Code,
B.Item_Id,
B.item_description Item_Desc,
A.UNIT_OF_MEASURE Transact_Uom,
A.QUANTITY Transact_Qty,
D.RELEASE_NUM PO_RELEASE
OF RCV_TRANSACTIONS,.
RCV_SHIPMENT_HEADERS C.
B RCV_SHIPMENT_LINES,
PO_RELEASES_ALL D
WHERE C.SHIPMENT_HEADER_ID = A.SHIPMENT_HEADER_ID
AND B.SHIPMENT_LINE_ID = A.SHIPMENT_LINE_ID
AND B.ITEM_ID IS NULL
AND UPPER (A.Transaction_Type) = "to DELIVER".
AND higher (A.Destination_Type_Code) = "WORKSHOP".
D.PO_RELEASE_ID AND = A.PO_RELEASE_ID) rcv3
GROUP BY rcv3. Po_Header_Id, RCV3.receipt_num, rcv3. Po_Line_Id, rcv3. Destination_Type_Code, rcv3. Item_Id, rcv3. Item_Desc, rcv3. Transact_Uom, rcv3. Rcv1 PO_RELEASE),
(SELECT A.PO_LINE_ID,
Sum (A.Quantity) transact_qty,
A.PO_HEADER_ID,
C.RECEIPT_NUM
OF RCV_TRANSACTIONS,.
RCV_SHIPMENT_HEADERS C.
B RCV_SHIPMENT_LINES,
PO_RELEASES_ALL D
WHERE C.SHIPMENT_HEADER_ID = A.SHIPMENT_HEADER_ID
AND B.SHIPMENT_LINE_ID = A.SHIPMENT_LINE_ID
AND UPPER (A.Transaction_Type) = "RETURN to the RECEPTION"
AND D.PO_RELEASE_ID = A.PO_RELEASE_ID
A.PO_LINE_ID, A.PO_HEADER_ID, C.RECEIPT_NUM GROUP) Rcv2
Where Po.Po_Header_Id = Rcv1.Po_Header_Id (+)
And Rcv1.Po_Line_Id = Rcv2.Po_Line_Id (+)
And Rcv1.Receipt_Num = Rcv2.Receipt_Num (+)
And Rcv1.Transact_Qty <>Nvl(Rcv2.Transact_Qty,999999999)
Group of po.po_header_id, rcv1.po_line_id, po.segment1, rcv1.receipt_num, rcv1.item_id, Rcv1.Item_Desc, rcv1. TRANSACT_UOM, rcv1. PO_RELEASE, (NVL(Rcv1.Transact_Qty,0)-NVL(RCV2.transact_qty,0))) has
Is my version of the database: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
Please find the attached PLAN to EXPLAIN.
Thank you
May be essentially the same join (between a, b, c and d) twice instead of three times
sounds like it could be done with a single join (between a, b, c, and d), but you do not some columns than the columns of rcv1 rcv2
We can work on what we can see only
Select rownum line_num,
rcv1.po_line_id line_id,
TO_CHAR (rcv1.item_id) invitmid,
NVL(rcv1.transact_qty,0) - nvl(rcv2.transact_qty,0) pickqty,
unloadingpnt null,
rrnum null,
workordnum null,
workorddesc null,
Po. Ponum Segment1,
dtr_dumb null,
description of the rcv1.item_desc,
from_sub null,
to_sub null,
No source,
asset_number null,
rcv1.receipt_num receiptnum,
moveord null,
from_loc null,
to_loc null,
msd_num null,
contain_line null,
Glu rcv1.transact_uom,
rcv1.po_release
of po_headers_all in.
left outer join
(select a.po_header_id,
c.receipt_num,
a.po_line_id,
a.destination_type_code,
b.item_id,
b.item_description item_desc,
a.unit_of_measure transact_uom,
Sum (a.Quantity) transact_qty,
d.release_num po_release
from (select shipment_header_id,
shipment_line_id,
po_release_id,
po_header_id,
po_line_id,
destination_type_code,
unit_of_measure,
quantity
of rcv_transactions
where upper (a.transaction_type) = "to DELIVER".
and upper (a.destination_type_code) ('charge', 'WORKSHOP')
) a
inner join
rcv_shipment_lines b
On a.shipment_line_id = b.shipment_line_id
inner join
c rcv_shipment_headers
On a.shipment_header_id = c.shipment_header_id
left outer join
po_releases_all d
On a.po_release_id = d.po_release_id
where upper (a.destination_type_code) = "EXPENSES".
or (upper (a.destination_type_code) = 'WORKSHOP'
and b.item_id is null
)
A.po_header_id group,
c.receipt_num,
a.po_line_id,
a.destination_type_code,
b.item_id,
b.item_description,
a.unit_of_measure,
d.release_num
) rcv1
On po.po_header_id = rcv1.po_header_id
left outer join
(select a.po_line_id,
Sum (a.Quantity) transact_qty,
a.po_header_id,
c.receipt_num
from (select shipment_header_id,
shipment_line_id,
po_release_id,
po_header_id,
quantity
of rcv_transactions
where upper (a.transaction_type) = "RETURN to THE RECIPIENTS.
) a
inner join
rcv_shipment_lines b
On a.shipment_line_id = b.shipment_line_id
inner join
c rcv_shipment_headers
On a.shipment_header_id = c.shipment_header_id
left outer join
po_releases_all d
On a.po_release_id = d.po_release_id
A.po_line_id group,
a.po_header_id,
c.receipt_num
) rcv2
On rcv1.po_line_id = rcv2.po_line_id
and rcv1.receipt_num = rcv2.receipt_num
where rcv1.transact_qty! = nvl(rcv2.transact_qty,999999999)
Concerning
Etbin
-
Need help with SQL Query - change of name history of audit table.
I need your help to find the result in the following way...
Emp No New_name Old_Name ----------------------------------------------- 1 Name3 Name2 1 Name2 Name1
Thank you...create table emp(emp_id number(10), emp_name varchar(50), constraints emp_pk primary key(emp_id) ); create table emp_audit( audit_id number(10), emp_id number(10), emp_name varchar(50), audit_date date, constraints emp_audit_pk primary key (audit_id), constraints emp_audit_emp_fk foreign key(emp_id) references emp(emp_id)); insert into emp values(1,'Name3'); insert into EMP_AUDIT (audit_id, emp_id, emp_name, audit_date) values (1, 1, 'Name1', to_date('14-08-2011', 'dd-mm-yyyy')); insert into EMP_AUDIT (audit_id, emp_id, emp_name, audit_date) values (2, 1, 'Name2', to_date('15-08-2011', 'dd-mm-yyyy')); commit;
Dipabkar Bédard (DB) wrote:
We write is the query without using "partition by" in oracle...?
with t as ( select audit_id, emp_id, emp_name, row_number() over(order by audit_id) rn from emp_audit order by emp_id, audit_id ) select a.audit_id, a.emp_id, a.emp_name old_name, nvl(b.emp_name,(select c.emp_name from emp c where c.emp_id = a.emp_id)) new_name from t a left join t b on ( b.emp_id = a.emp_id and b.rn = a.rn + 1 ) / AUDIT_ID EMP_ID OLD_NAME NEW_NAME ---------- ---------- -------------------------------------------------- ------------ 1 1 Name1 Name2 2 1 Name2 Name3 SQL>
And without analytical functions:
with t1 as ( select audit_id, emp_id, emp_name from emp_audit order by emp_id, audit_id ), t2 as ( select audit_id, emp_id, emp_name, rownum rn from t1 ) select a.audit_id, a.emp_id, a.emp_name old_name, nvl(b.emp_name,(select c.emp_name from emp c where c.emp_id = a.emp_id)) new_name from t2 a left join t2 b on ( b.emp_id = a.emp_id and b.rn = a.rn + 1 ) / AUDIT_ID EMP_ID OLD_NAME NEW_NAME ---------- ---------- -------------------------------------------------- ---------- 1 1 Name1 Name2 2 1 Name2 Name3 SQL>
SY.
-
Need for the sql query to have several columns in a single coulumn
Hi all
I need create the query to have several columns in a single column with several lines.
Select a.customer_trx_id, a.previous_customer_trx_id
of ra_customer_trx_all one
where a.customer_trx_id =: customer_trx_id
Here, a.customer_trx_id and a.previous_customer_trx_id are in two columns. I need to put them in a single column.
Say: the foregoing is output
--------------------------------------------------------------------------------
a.customer_trx_id a.previous_customer_trx_id
--------------------------------------------------------------------------------
123456 87654
--------------------------------------------------------------------------------
Need for a single column
As
--------------------------------------------------------------------------------
123456
87654
--------------------------------------------------------------------------------
Please do the needful. Please note that it is not the UNION.
Thank you
AbdulHello
You want a way to confirm that what looks like two rows is really a line?
Here are three ways:
(1) count the lines:
WITH my_original_querry AS ( select a.customer_trx_id || CHR(13) || a.previous_customer_trx_id as id from ra_customer_trx_all a where a.customer_trx_id = 274881 ) SELECT COUNT (*) FROM my_original_query;
(2) in SQL * Plus, have SQL * more count them for you:
SET FEEDBACK 1 select a.customer_trx_id || CHR(13) || a.previous_customer_trx_id as id from ra_customer_trx_all a where a.customer_trx_id = 274881;
(3) implicitly count them with the ROWNUM Pseudo-column
select a.customer_trx_id || CHR(13) || a.previous_customer_trx_id as id , ROWNUM from ra_customer_trx_all a where a.customer_trx_id = 274881;
-
Need help with SQL query (10 years since I have SQL)
Hi guys,.
I tried to remove some rust SQL. I did not go to SQL within a certain time.
Here are the tables (% = ent $ = varcchar)
-----------------
RESULT
-----------------
% RESULT_ID-$ RC-% YEAR_ID - PERIOD_ID-% CONTRACT_NO-% value %
20841---1439---83---37---010427102---1
20842---1439---83---41---010427102---2
20843---1439---84---37---010427102---3
20844---1439---84---41---010427102---4
20845---1439---83---34---010427102---5
-----------------
YEARS
-----------------
YEAR_ID - YEAR_DESC
83 2010-2011
84 2011-2012
-----------------
PERIOD
-----------------
PERIOD_ID - PERIOD_DESC
34 14
37 02
41 03
What I want is to get the last period of each year in the RESULT table. (I'll work the rest of the WHERE statement myself, because I have omitted some news, or columns for simplicity)
Note that I can't rely on the ID of the period, as the chronological order is not respected.
In the scenario above, I should GET
% RESULT_ID-$ RC - YEAR_ID - PERIOD_ID-% CONTRACT_NO-% % value %
20844---1439---84---41---010427102---4
20845---1439---83---34---010427102---5
I have the following, but it only returns values if the year is the last time!
SELECT DISTINCT RESULTS. RESULT_ID, RESULT. RC, RESULT. PERIOD_ID, RESULT. YEAR_ID, RESULT. CONTRACT_NO, YEARS. YEAR_DESC
RESULT, YEARS
WHERE TO TRAIN. YEAR_ID = YEARS. YEAR_ID AND - it is my problem, I want the last period for each year.
RESULT. PERIOD_ID = (SELECT PERIOD_ID FROM PERIOD WHERE CAST (PERIOD_DESC AS INT) = (Select MAX (CAST (PERIOD_DESC AS INT)) of the period)) - I think it works fine I'm able to get the last period
ORDER BY YEARS. YEAR_DESC;
Published by: 935079 on May 17, 2012 11:32
Add space not formatted tabs
Published by: 935079 on May 17, 2012 11:35Your way to present the data that makes it very tedious to create test data. Next time please simply provide CREATE TABLE and INSERT statements so that we can all share the same test data.
Without test data, I think you want Frank solution with a very minor change: order value instead of id, then the number of line 1 is the highest value.
with GOT_R_NUM as ( SELECT r.* -- or list the columns you want , ROW_NUMBER() over(partition by R.YEAR_ID, R.CONTRACT_NO order by -- P.PERIOD_ID P.PERIOD_VALUE DESC NULLS LAST) AS r_num FROM result r JOIN period p ON r.period_id = p.period_id ) SELECT * -- or list all columns except r_num FROM got_r_num WHERE r_num = 1;
-
Need help with sql query involving distinct and County
I have 2 tables and I want to get the number of specific names. Find the details below. It's hard to explain but I will try to provide as much detail as I can.
Table A:
ID of the SR
1001 1
1002 2
2 1003
1004 3
Table B:
Name of the key SrNew
1 David 1001
2 James 1002
3 James 1002
4 James 1003
5 James 1004
6 Mike 1004
Result: I'm looking:
Count names such as if the name appears for the same ID of Table A two times, and then only count 1.
Name of County
David 1
James 2 (1002 and 1003 for the same ID (ID #2) so count as 1 for this and then 1 more for 1004 and ID 3)
1 Mike
I have following question:
SELECT distinct (b.Name), a.ID
FROM TableA, TableB b
Where a.Sr = b.SrNew Group By b.Name, a.ID
and as a result I get:
ID name
David 1
James 2
3 James
3 Mike
Now, I want to just the number of each name with the result, but don't know how I can do this with a sql?
Thanks in advance.Who help me?
SELECT b.Name, count(distinct a.ID) FROM TableA a, TableB b Where a.Sr = b.SrNew Group By b.Name
Nicolas.
-
Hello
I have a table named demo with two columns (name brands), as shown below
Name brands
A 80
B 100
C 96
I need a Select SQL query that returns the result as shown below
Name brands
A 276
B 276
C 276
Brands of column must contain the sum of all the brands of the table against each of the name of the table. (Not necessarily with the same columns as the demo table names) This result should not be stored in the table and I need it just for display purpose.
Published by: 944160 on May 30, 2013 05:28Try this
select name, sum(marks) over () marks from demo
-
The search syntax of SQL query against the data type varchar2 preserving valid data.
Have a data model that we are not allowed to change and the column in question is a varchar2 (20). The column has at this stage no foreign key to the list of valid values. So, until we can get those who control the data model in order to make the adjustments we need for a SQL query that root out us bad data on the hours fixed.
Is what we expect to be good data below:
-Whole number, without floating point
-Length of 5 or less (greater than zero but less than 99999)
-Text "No_RP" can exist.
Request demo below works most of the time with the exception of 'or Column1 is null' is not contagious in the null record. I tried to change the logical terms around, but did not understand the correct layout still provide it. So help would be greatly appreciated it someone could put me straight on how to properly register a null value in the recordset that has been selected with other types of error for end users to correct their mistakes. Another thing, I suppose there could be a better approach syntactically to a call find all offender characters such as *, &, (and so on.)
WITH Sample_Data AS (SELECT '0' collar OF DOUBLE UNION ALL)
SELECT "2" collar OF DOUBLE UNION ALL
SELECT "99999" col OF DOUBLE UNION ALL
SELECT "100000" col OF DOUBLE UNION ALL
SELECT '1 a' collar OF DOUBLE UNION ALL
SELECT the "ABCD" OF DOUBLE UNION ALL pass
SELECT 'A1' collar OF DOUBLE UNION ALL
SELECT ' *' collar OF DOUBLE UNION ALL
SELECT "/" pass OF DOUBLE UNION ALL
SELECT '-' col OF DOUBLE UNION ALL
SELECT ' ' collar OF DOUBLE UNION ALL
SELECT "pass OF DOUBLE UNION ALL
4. SELECT 5 6' collar OF DOUBLE UNION ALL
SELECT "24.5" collar OF DOUBLE UNION ALL
SELECT '-3' collar OF DOUBLE UNION ALL.
SELECT 'A' collar OF DOUBLE UNION ALL
SELECT 'F' OF DOUBLE UNION ALL cervical
SELECT the 'Z' OF DOUBLE UNION ALL pass
SELECT the pass 'Bye' FROM DUAL UNION ALL
SELECT the "Hello World" OF DOUBLE UNION ALL pass
SELECT "=" col OF DOUBLE UNION ALL
SELECT "+" col OF DOUBLE UNION ALL
SELECT '_' pass OF DOUBLE UNION ALL
SELECT '-' col OF DOUBLE UNION ALL
SELECT ' (' col OF DOUBLE UNION ALL)
SELECT ')' collar OF DOUBLE UNION ALL
SELECT '&' collar OF DOUBLE UNION ALL
SELECT ' ^' collar OF DOUBLE UNION ALL
SELECT '%' collar OF DOUBLE UNION ALL
SELECT the pass of "$" OF DOUBLE UNION ALL
SELECT the pass ' # ' TO DOUBLE UNION ALL
SELECT ' @' collar OF DOUBLE UNION ALL
SELECT '!' collar OF DOUBLE UNION ALL
SELECT ' ~' collar OF DOUBLE UNION ALL
SELECT "' collar OF DOUBLE UNION ALL
SELECT '.' pass FROM DUAL
)
SELECT col from Sample_data
WHERE (translate (col, '_0123456789', '_') is not null
or length (col) > 5
col = 0 or
or col is null)
and (upper (col) <>'NO_RP');
One more thing, I also took the approach of the regular expression, but he could not understand. If anyone knows how to do with this approach, I would also appreciate learning this method as well. Below is a close because I had. Impossible to get a range to work as "between 0 and 100000", guessing because of the comparison of varchar2 and # even attempted using to_char and to_number.
Select to_number (column1) from the testsql where REGEXP_LIKE (column1, ' ^ [[: digit:]] + $') ORDER BY to_number (column1) CSA;
Thanks in advance for anyone to help.
NickHello
Thanks for posting the sample data in a useable form.
It would be useful that you also posted the accurate results you wanted from this data. You want the same results as those produced by the query you posted, except that nulls should be included? If so:SELECT col FROM sample_data WHERE CASE WHEN UPPER (col) = 'NO_RP' THEN 1 WHEN col IS NULL THEN -1 WHEN LTRIM (col, '0123456789') IS NOT NULL THEN -2 WHEN LENGTH (col) > 5 THEN -3 ELSE TO_NUMBER (col) END NOT BETWEEN 1 AND 99999 ;
The requirement that pass! = 0 gives that much more difficult. You could test easily for an integer from 1 to 5 digits, but then you must have a separate condition to make sure that the chain was not '0', '00', '000', ' 0000 'or ' 00000'.
(Unlike Solomon, I guess that do not want to choose no-0 numbers starting by 0, such as ' 007 'or ' 02138'.)Using regular expressions, you may lose a few keystrokes, but you also lose a lot of clarity:
SELECT col FROM sample_data WHERE REGEXP_LIKE ( col , '^0{1,5}$' ) OR NOT REGEXP_LIKE ( NVL ( UPPER (col) , 'BAD' ) , '^(([1-9][0-9]{0,4})|NO_RP)$' ) ;
Published by: Frank Kulash, December 13, 2010 21:50
Published by: Frank Kulash, December 13, 2010 22:11
Added regular expression solution -
Hello
I have a data in table (raj_table) with columns (char11) raj_id, raj_number (varchar2 (15)), raj_format (NUMBER), Primary_ID (identity with the values of the primary key column)
Primary_ID raj_id Raj_number Raj_format
1 raj rajvend 1
2 raj rajvend 1
3 raj rajvendor1 2
4 raj rajvendor1 2
5 raj rajvendor1 2
6 raj rajvendor2 3
I used under SQL to get query output as below, but has not achieved the required result:
Select client_id vendor_number, vendor_format, primary_id, row_number() on sl_no (client_id partition, primary_id, vendor_format order of client_id primary_id, vendor_format, vendor_number, vendor_number)
from raj_table by sl_no asc
SL_NO raj_id raj_number raj_format primary_id
1 1 raj rajvendor 1
1 2 raj rajvendor 1
2 3 raj rajvendor1 2
2 4 raj rajvendor1 2
2 5 raj rajvendor1 2
3 6 raj rajvendor2 3
I need help with a SQL query to get the result as above without using the group by clause. I want to bring together the combination of separate line of the three columns (raj_id, raj_number, raj_format) and add a unique serial number for each online game (SL_NO column below). So, above there are 3 unique set of (raj_id, raj_number, raj_format) I can get in a group by clause, but I can not add prmiary_id, SL_NO values if I group by clause. I used the analytical functions like row_number() but no luck. Need solution for this.
with t as)
Select 'raj' raj_id, 'rajvend' raj_number, 1 raj_format, 1 primary_id Union double all the
Select option 2, 'raj', 'rajvend', 1 double Union all
Select 3, 'raj', 'rajvendor1', 2 double Union all
Select 4, 'raj', 'rajvendor1', 2 double Union all
Select 5, 'raj', 'rajvendor1', 2 double Union all
Select 6, 'raj', 'rajvendor2', 3 double
)
Select dense_rank() over (order of raj_id, raj_number, raj_format) sl_no,
t.*
t
order by primary_id
/
PRIMARY_ID RAJ RAJ_NUMBER RAJ_FORMAT SL_NO
---------- ---------- --- ---------- ----------
1 1 raj rajvend 1
1 2 raj rajvend 1
2 3 raj rajvendor1 2
2 4 raj rajvendor1 2
2 5 raj rajvendor1 2
3 6 raj rajvendor2 36 selected lines.
SQL >
SY.
-
Database SQL query to get all virtual machines with comments enabled customization?
Hello
Does anyone know of a SQL query that can be executed against the vCloud Director DB for all virtual machines who invited enabled customization?
I can't have PowerShell to pull these data on a global scale.
Thank you
jkasal
Has taken a quick...
Select top 10 v.id, v.name, v.vapp_name, v.vc_id, v.moref, ui_vapp_vm_list_view v.guest_customize_enabled v with (NOLOCK)
seems to have if the setting is enabled or not.
-
Hi all
Sorry I can't speak English very well
=======================
I have a table that contains two columns
table name: total_sal
column name: hire_date
column name: salary
table syntax
create table total_sal (hire_date date
number (6.2)) of salary;
_________________________________________
Example of data in table format
hire_date | salary
01/01/2011 | 1000
01/02/2011 | 2000
01/05/2011 | 500
01/09/2011 | 400
I NEED a SQL QUERY to display the table, as in this example
OF | TO|||||||||||| TOTALSALAY
01/01/2011 | 01/02/2011 | 3000
07/05/2011 | 01/09/2011 | 900
|||||||||||||||||||||||||||||||||| 3900/* Formatted on 9/23/2011 10:14:40 AM (QP5 v5.149.1003.31008) */ WITH t AS (SELECT TO_DATE ('1/1/2011', 'mm/dd/yyyy') hire_date, 1000 salary FROM DUAL UNION SELECT TO_DATE ('2/1/2011', 'mm/dd/yyyy'), 2000 FROM DUAL UNION SELECT TO_DATE ('5/1/2011', 'mm/dd/yyyy'), 500 FROM DUAL UNION SELECT TO_DATE ('9/1/2011', 'mm/dd/yyyy'), 400 FROM DUAL) SELECT "From", "To", totalsalary FROM (SELECT hire_date "From", LEAD (hire_date) OVER (ORDER BY hire_date) "To", salary + LEAD (salary) OVER (ORDER BY hire_date) totalsalary, ROW_NUMBER () OVER (ORDER BY hire_date) rn FROM t) WHERE MOD (rn, 2) = 1 UNION ALL SELECT NULL, NULL, SUM (salary) FROM t
From To TOTALSALARY 1/1/2011 2/1/2011 3000 5/1/2011 9/1/2011 900 3900
-
Need to SQL query to filter records by limited rows and certain condition
Hello guru (s).
I need a SQL query for help.
For an example table t1 as below, I want to find the maximum of 5 larger, but there should be no more than 2 name of the same position. The "BOLD" is the response of desire.
Name Position size
N1 P1 5
N2 P2 50
N3 P3 500
N4 P1 6
N5 P2 60
N6 P3 600
N7 P1 7
N8 P2 70
N9 P3 700
Thank you.not tested!
select name,position,size, from (select name,position,size, row_number() over (order by size desc) a_count from (select name,position,size, row_number() over (partition by position order by size desc) a_count from your_table ) where a_count <= 2 ) where a_count <= 5
Concerning
Etbin
-
Need help with PL/SQL query complex
I need help with a query that need access to data from 3 tables. That's what I did
I created 3 tables
CREATE TABLE post_table
(
post_id varchar (20),
datepost DATE,
KEY (post_id) elementary SCHOOL
) ;
CREATE TABLE topic
(
TOPIC_ID varchar (20),
name varchar (20),
PRIMARY KEY (topic_id)
);
CREATE TABLE blogpost_table
(
TOPIC_ID varchar (20),
post_id varchar (20),
PRIMARY KEY (topic_id, post_id);
FOREIGN KEY (topic_id) REFERENCES topic (topic_id) ON DELETE CASCADE,
FOREIGN KEY (post_id) REFERENCES post_table (post_id) ON DELETE CASCADE
);
Now, I inserted a few values in these tables as
INSERT INTO post_table VALUES ('p1', to_date ('2009-09-14 18:00 "," MM/DD/YYYY mi:ss'));))
INSERT INTO post_table VALUES ('p2', to_date ('2009-07-18 18:00 "," MM/DD/YYYY mi:ss'));))
INSERT INTO post_table VALUES ('p3', to_date ('2009-07-11 18:00 "," MM/DD/YYYY mi:ss'));))
INSERT INTO post_table VALUES ('p4', to_date ('2009-03-11 18:00 "," MM/DD/YYYY mi:ss'));))
INSERT INTO post_table VALUES ('p5', to_date ('2009-07-13 18:00 "," MM/DD/YYYY mi:ss'));))
INSERT INTO post_table VALUES ('p6', to_date ('2009-06-12 18:00 "," MM/DD/YYYY mi:ss'));))
INSERT INTO post_table VALUES ('p7', to_date ('2009-07-11 18:00 "," MM/DD/YYYY mi:ss'));))
INSERT INTO VALUES subject ("t1", "baseball");
INSERT INTO category VALUES ('t2', 'football');
INSERT INTO blogpost_table VALUES ("t1", "p1");
INSERT INTO blogpost_table VALUES ('t1', 'p3');
INSERT INTO blogpost_table VALUES ("t1", "p4");
INSERT INTO blogpost_table VALUES ('t1', 'p5');
INSERT INTO blogpost_table VALUES ('t2', 'p2');
INSERT INTO blogpost_table VALUES ('t2', 'p6');
INSERT INTO blogpost_table VALUES ("t2", "p7");
I'm launching SQL queries on the table in this topic.
I want to write a SQL query that returns me the name of a topic (s) and the number of blog_post (s) associated with the topic in descending order of the number of blog posts created in July.
Can someone please help me to write this query?
Thank you
Published by: user11994430 on October 9, 2009 07:24Thanks for the test of the configuration!
SQL>SELECT t.NAME, COUNT(*) 2 FROM topic t, blogpost_table b, post_table p 3 WHERE b.topic_id = t.topic_id 4 AND p.post_id = b.post_id 5 AND p.datepost >= DATE '2009-07-01' 6 AND p.datepost < DATE '2009-08-01' 7 GROUP BY t.NAME 8 ORDER BY COUNT(*) desc; NAME COUNT(*) -------------------- ---------- baseball 2 soccer 2
HTH, Urs
Maybe you are looking for
-
The new iWorks and macOS doesn't just :(
The new iWorks and macOS does not work correctly. For example in the Pages I can no longer work. Its grip MUCH. Its almost unsusable. Please fix this quickly. I use a lot of Pages. This is a new problems that the macOS upgrade NAS and the last iWoks
-
My laptop just put update for Windows 10. A previous version of Firefox I open multiple windows at the same time.
-
Transfer box reception, envoys and to yahoo/sky records. Help, please!
I set up the details of the server according to the instructions of the sky... pop. Tools.Sky.comand to my Yahoo New Zealand account pop.mail.Yahoo.comboth are port 995. Unfortunately TB downloads only the inboxes to tuberculosis.Sky has been very us
-
Satellite NB10T-A-102 - horrible sound quality
Hello I bought a NB10T-A-102, but the sound is horrible almost not not tuned because that sounds like metal noise.I tried to change driver but without advantage.Do you know if it's because of the speakers of material or if there is a configuration th
-
Doc here with another tip to share! Are you worried as me on camera cable, Kit (USB OTG) which sticks to your Xoom, just waiting to be broken? Well, I traveled the four corners of the globe and found a square suitable OTG cable that works just as wel