using the WITH Clause
The sql statement isSelect ename, job
from emp, dept
where emp.deptno = dep.deptno
and emp.deptno = 10
Union
Select ename, job
from emp, dept
where emp.deptno = dep.deptno
and emp.deptno = 20
the statement above using the WITH Clause
WITH dept10 AS
(select ename, job, hiredate, sal, comm, dname, emp.deptno
from emp, dept
where emp.deptno = dept.deptno
and emp.deptno = 10)
dept20 AS
(select ename, job, hiredate, sal, comm, dname, emp.deptno
from emp, dept
where emp.deptno = dept.deptno
and emp.deptno = 20)
SELECT *.
OF dept10
UNION
SELECT *.
OF dept20
Correct me if I'm wrong...
Thank you
Hello
SeenuGuddu wrote:
the Question is how u would provide the statement above by using the Clause
The answer is that the question is meaningless. You will not use a WITH clause for this work.
Because you must use a WITH clause to get the same results as the first query, I think the best way would be:
WITH unnecessary_sub_query AS
(
select DISTINCT
ename, job
-- , hiredate, sal, comm, dname,emp.deptno -- these columns are not in the original query
from emp
, dept
where emp.deptno = dept.deptno
and emp.deptno IN (10, 20)
)
SELECT *
FROM unnecessary_sub_query;
is this correct using Clause WITH or correct me
No, it's not ok to make queries more complex or slow they need to do.
In addition to the extra columns, it seems that the second query that you posted (the one who has a WITH clause) produces the same results as the first request.
Tags: Database
Similar Questions
-
I have trouble understanding the following query:
SELECT cust_city, COUNT (cust_last_name)
Customers
WHERE cust_credit_limit > 1000
GROUP BY cust_city
HAVING AVG (cust_credit_limit) BETWEEN 5000 AND 6000
According to my preparation for the review, it will work successfully without errors, although I don't understand why.
The AVG (cust_credit_limit) should also be included in with the rest of the fields to make it work correctly?
It would be greatly appreciated if someone could explain it to me better.
Thank you
Sean
5285cd35-2ff3-432e-B2FD-19285481be60 wrote:
I have trouble understanding the following query:
SELECT cust_city, COUNT (cust_last_name)
Customers
WHERE cust_credit_limit > 1000
GROUP BY cust_city
HAVING AVG (cust_credit_limit) BETWEEN 5000 AND 6000
According to my preparation for the review, it will work successfully without errors, although I don't understand why.
The AVG (cust_credit_limit) should also be included in with the rest of the fields to make it work correctly?
It would be greatly appreciated if someone could explain it to me better.
Thank you
Sean
No - the AVG function doesn't have to be in the select list. Explain why you think it should be.
How would it make a difference if you added to the SELECTION list and ignored, then?
When you have questions DOC the first thing you need to do is RTFM. See the HAVING clause in the RFSO of the SQL language
http://docs.Oracle.com/CD/B28359_01/server.111/b28286/statements_10002.htm
>
HAVING clause
Use of the
HAVING
clause to restrict groups of returns of the lines to these groups for which the specifiedcondition
isTRUE
.>
As the doc t says
He HAVING condition applies to the 'groups '.
If you use the HR. EMPLOYEES table you can see the effect of the HAVING clause. This query is similar to yours but with none HAVING clause, and the AVG (salary) added to the selection list to see which groups will have
>
Select department_id, count (last_name), avg (salary)
employees
where salary > 500
Group by department_id- DEPARTMENT_ID, COUNT (LAST_NAME), AVG (SALARY)
- 10,1,4400
- 20,2,9500
- 30,6,4150
- 40,1,6500
- 50,45,3475.55555555556
- 60,5,5760
- 70,1,10000
- 80,34,8955.88235294118
- 90,3,19333.3333333333
- 100,6,8601.33333333333
- 110,2,10154
- 1,7000
>
Note that 60 is the ONLY group with AVG (salary) between 5000 and 6000
Now, try the query using the HAVING clause
>
Select department_id, count (last_name)
employees
where salary > 500
Group by department_id
having avg (salary) between 5000 and 6000
DEPARTMENT_ID, COUNT (LAST_NAME)
60.5
>
Only group 60 has been selected - the HAVING condition has been applied to the first query GROUPS, not the lines.
-
Hi, I tried to use the nologging clause to improve the performance of DML on one of the table. However I have observed this table with nologging option actually decreases performance :(
Please see the next newspaper.
SQL > create table test_log (int id, name char (40))
2.
Table created.
Elapsed time: 00:00:00.03
SQL > create table test_nolog (int id, name char (40)) nologging
2.
Table created.
Elapsed time: 00:00:00.00
SQL > insert into test_log select ROWNUM *-1, DBMS_RANDOM. String('A',1) FROM DUAL CONNECT BY LEVEL < = 1000000
2.
1000000 rows created.
Elapsed time: 00:00:13.46
SQL > insert into test_nolog select ROWNUM *-1, DBMS_RANDOM. String('A',1) FROM DUAL CONNECT BY LEVEL < = 1000000
2.
1000000 rows created.
Elapsed time: 00:00:16.95
SQL > update test_log set id = 100
2.
1000000 lines to date.
Elapsed time: 00:00:46.35
SQL > update test_nolog set id = 100
2.
1000000 lines to date.
Elapsed time: 00:00:49.43Insert and update have no impact if the tables are created with the NOLOGGING clause or logging
It generates the same amount of redo for insert and UPDATE stmts stmts
NOLOGGING can help for the following things
1 CTAS
2.SQL * loader in direct mode
3. INSERT / * + APPEND * /...SYSTEM@rman 15/12/2008> truncate table test_log; Table truncated. Elapsed: 00:00:01.49 SYSTEM@rman 15/12/2008> truncate table test_nolog; Table truncated. Elapsed: 00:00:00.67 SYSTEM@rman 15/12/2008> insert into test_nolog select ROWNUM*-1,DBMS_RANDOM.STRING('A',1) FROM DUAL CONNECT BY LEVEL <=1000000; 1000000 rows created. Elapsed: 00:00:39.80 Execution Plan ---------------------------------------------------------- Plan hash value: 1731520519 ------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Cost (%CPU)| Time | ------------------------------------------------------------------------------ | 0 | INSERT STATEMENT | | 1 | 2 (0)| 00:00:01 | | 1 | COUNT | | | | | |* 2 | CONNECT BY WITHOUT FILTERING| | | | | | 3 | FAST DUAL | | 1 | 2 (0)| 00:00:01 | ------------------------------------------------------------------------------ Predicate Information (identified by operation id): --------------------------------------------------- 2 - filter(LEVEL<=1000000) Statistics ---------------------------------------------------------- 3081 recursive calls 41111 db block gets 8182 consistent gets 0 physical reads 60983504 _redo size_ 674 bytes sent via SQL*Net to client 638 bytes received via SQL*Net from client 3 SQL*Net roundtrips to/from client 2 sorts (memory) 0 sorts (disk) 1000000 rows processed SYSTEM@rman 15/12/2008> commit; Commit complete. Elapsed: 00:00:00.03 SYSTEM@rman 15/12/2008> insert into test_log select ROWNUM*-1,DBMS_RANDOM.STRING('A',1) FROM DUAL CONNECT BY LEVEL <=1000000; 1000000 rows created. Elapsed: 00:00:38.79 Execution Plan ---------------------------------------------------------- Plan hash value: 1731520519 ------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Cost (%CPU)| Time | ------------------------------------------------------------------------------ | 0 | INSERT STATEMENT | | 1 | 2 (0)| 00:00:01 | | 1 | COUNT | | | | | |* 2 | CONNECT BY WITHOUT FILTERING| | | | | | 3 | FAST DUAL | | 1 | 2 (0)| 00:00:01 | ------------------------------------------------------------------------------ Predicate Information (identified by operation id): --------------------------------------------------- 2 - filter(LEVEL<=1000000) Statistics ---------------------------------------------------------- 3213 recursive calls 41323 db block gets 8261 consistent gets 2 physical reads 60993120 _redo_ size 674 bytes sent via SQL*Net to client 636 bytes received via SQL*Net from client 3 SQL*Net roundtrips to/from client 2 sorts (memory) 0 sorts (disk) 1000000 rows processed SYSTEM@rman 15/12/2008> commit;
They simply generate the same anount of redo
If you use hint APPEND, you can reduce the timings of INSERT stmt
SYSTEM@rman 15/12/2008> truncate table test_nolog; Table truncated. Elapsed: 00:00:00.28 SYSTEM@rman 15/12/2008> INSERT /*+ APPEND */ into test_nolog select ROWNUM*-1,DBMS_RANDOM.STRING('A',1) FROM DUAL CONNECT BY LEVEL <=100 1000000 rows created. Elapsed: 00:00:28.19 Execution Plan ---------------------------------------------------------- ERROR: ORA-12838: cannot read/modify an object after modifying it in parallel SP2-0612: Error generating AUTOTRACE EXPLAIN report Statistics ---------------------------------------------------------- 3125 recursive calls 8198 db block gets 929 consistent gets 0 physical reads 161400 redo size 660 bytes sent via SQL*Net to client 652 bytes received via SQL*Net from client 3 SQL*Net roundtrips to/from client 2 sorts (memory) 0 sorts (disk) 1000000 rows processed SYSTEM@rman 15/12/2008>
You can also view time significant difference/redo generated between INSERT and INSERT with append on a table NOLOGGING
-
Cannot use the command clause contained in the posting online of a cursor
Dear people,
I use Oracle 10 g with forms 6i. I had a requirement where I gotto choose the latest ten records and view the sorting in the opposite order.say for ex.
But my problem is all the time that I came to know that we cannot use the order by clause in the view of a cursor line in forms 6i. Think it's one of the limitations of forms 6i.so u can suggest me what I can do to get the expected results? do we not have any alternative?Cursor C is select * from (select ename,sal from emp order by sal desc) where rownum<=10;
Thanking you,
Concerning
Vids
Published by: vidusnat on July 4, 2012 03:38Hello
Please specify!
Forms 6i must be with an older version of SQL and PL/SQL (8.x).To keep it simple create a VIEW in the comics with your as its source and the use of the VIEW in the form. As you noted, it works in 10g and exploit it.
See you soon,.
-
DML with values returned of dml another inside the WITH clause
Hello community, I want to use the ELECTION of an insert or update values to other insertion within a single transaction without staging of values returned. Here's what I mean. In some other dbs, I can do it like this
WITH moved_rows AS)
DELETE FROM products
"WHERE purchased_date > = ' 2010-10-01' AND purchased_date < ' 2010-11-01"
RETURN *.
)
INSERT INTO products_log
SELECT product_id, product_date, sysdate, user moved_rows;
I know the return value must be assigned to a local variable before they can be used within other dml, but I'm curious to know if the approach described above is supported in Oracle. Note that outside dml returns all columns (*) of the table products and then I took and chose the values I want to be inserted in the log table.
Hello community, I want to use the ELECTION of an insert or update values to other insertion within a single transaction without staging of values returned. Here's what I mean. In some other dbs, I can do it like this
WITH moved_rows AS)
DELETE FROM products
WHERE purchased_date > = "2010-10-01' AND purchased_date<>
RETURN *.
)
INSERT INTO products_log
SELECT product_id, product_date, sysdate, user moved_rows;
I know the return value must be assigned to a local variable before they can be used within other dml, but I'm curious to know if the approach described above is supported in Oracle. Note that outside dml returns all columns (*) of the table products and then I took and chose the values I want to be inserted in the log table.
Non - "approach above" don't is NOT supported in Oracle.
For operations from multiple tables, you must use SET of treatment to prevent other sessions modify data during your transaction.
Jarkko #8 post shows the steps involved.
-
HOW TO USE THE CONNECT_BY CLAUSE
Hi guys... I have a table like this
create table emp_del (ename varchar2 (10), mname varchar2 (10))
Insert into emp_del values ('ABC', 'MNO')
Insert into emp_del values ('MNO', 'XYZ')
Insert into emp_del values ('XYZ', 'king')
Insert into emp_del values ('king', NULL)
I use this sql to return the name of any employee senior...
SELECT SYS_CONNECT_BY_PATH (MNAME, '-->') "MANAGER_NAME".
OF EMP_DEL
CONNECT PRIOR MNAME = ENAME
START BY ENAME =: P_EMPLOYEE_NAME
ex: ename = ABC
released as: - > MNO
-> MNO-> XYZ
-> MNO-> XYZ-> King
-> MNO-> XYZ-> king - >
I just need the output to be-> King
can you guys help meOne way:
select ename from( select e.*,connect_by_isleaf lf from emp_del e connect by prior mname=ename start with ename=:P_EMPLOYEE_NAME ) where lf = 1
Note: it can be simplified as below, just used a subquery to understand...
select ename from emp_del e where connect_by_isleaf = 1 connect by prior mname=ename start with ename=:P_EMPLOYEE_NAME
-
How to use WITH Clause of Apex classic report
Hello.
I use Apex 4.2.1 on mod_plsq and Oracle 11 g 3.
I need to create a report classic usiing a WITH clause in the SQL report. Apex keeps throwing the error 'CAN finf SELECT statement.
I then wrapped my report query in an envelope, SELECT * clause. Apex then raises an error you need to use a variable LONG.
How is - a uses a WITH clause in the report query.
Here is my report query:
SELECT *.
Of
(
WITH W
AS
(
SELECT
MIN (W1. URMT_BTRS_PK URMT_BTRS_PK),
MIN (W1. EARLIER_NOTICE_ID URMT_NOTICES_ID),
TO_CHAR (MAX (W1. EARLIER_NOTICE_TYPE NOTICE_TYPE)),
TO_CHAR (MAX (W1. NOTICE_TYPE)) | '- Day' EARLIER_NOTICE_TYPE_DESC,.
MAX (W1. LATER_NOTICE_ID URMT_NOTICES_ID),
TO_CHAR (MIN (W1. LATER_NOTICE_TYPE NOTICE_TYPE)),
TO_CHAR (MIN (W1. NOTICE_TYPE)) | '- Day' LATER_NOTICE_TYPE_DESC,.
W1. NOCHG_STATUS_ORDER,
W1. CHG_STATUS_ORDER,
W1. ADD_STATUS_ORDER,
W1. REM_STATUS_ORDER
Of
(
SELECT
URMT_BTRS_PK,
URMT_NOTICES_ID,
NOTICE_TYPE,
: P202_NOCHG_STATUS_ORDER AS NOCHG_STATUS_ORDER,
: P202_CHG_STATUS_ORDER AS CHG_STATUS_ORDER,
: P202_ADD_STATUS_ORDER AS ADD_STATUS_ORDER,
: P202_REM_STATUS_ORDER AS REM_STATUS_ORDER
Of
V_URMT_COMPARE_NUCLIDE_DATA
WHERE
URMT_NOTICES_ID IN (TO_NUMBER(:P202_COMPARE_EARLER_NOTICE_ID), TO_NUMBER (:P202_COMPARE_LATER_NOTICE_ID))
) W1
)
------------------
SELECT
CASE WHEN (X.STATUS IS NULL) THEN
CASE WHEN (INSTR(X.MASS ||)
X.NUCLIDE_FRACTION
((' *', 1, 1) > 0) THEN '< div class = "chg_highlight" >' | HTF. ESCAPE_SC (' changed (' |)) (SELECT EARLIER_NOTICE_TYPE |) ' => ' || LATER_NOTICE_TYPE | ((' W)) | "< / div >"
Else 'no change '.
END
WHERE (X.STATUS = 'Added') THEN ' < div class = "add_highlight" > ' | HTF. ESCAPE_SC(X.STATUS ||) "To" | (BY SELECTING LATER_NOTICE_TYPE_DESC IN W)) || "< / div >"
WHERE (X.STATUS = 'Deleted') THEN "< div class ="rem_highlight"> ' |" HTF. ESCAPE_SC(X.STATUS ||) 'From ' | (BY SELECTING EARLIER_NOTICE_TYPE_DESC IN W)) || "< / div >"
OF OTHER X.STATUS
END AS STATUS
----
CASE WHEN (X.STATUS_ORDER IS NULL) THEN
CASE WHEN (INSTR(X.MASS ||)
X.NUCLIDE_FRACTION
((' *', 1, 1) > 0) THEN (SELECT CHG_STATUS_ORDER FROM W)
OTHER (SELECT NOCHG_STATUS_ORDER FROM W)
END
OF OTHER X.STATUS_ORDER
END AS STATUS_ORDER,
----
X.NUCLIDE,
----
CASE WHEN (X.STATUS IS NULL) THEN
BOX WHEN (SUBSTR (X.MASS, 1, 1) = ' *') THEN SUBSTR (X.MASS, 2).
OF OTHER X.MASS
END
OF OTHER X.MASS
MASS OF THE END AS,
----
CASE WHEN (X.STATUS IS NULL) THEN
BOX WHEN (SUBSTR (X.NUCLIDE_FRACTION, 1, 1) = ' *') THEN SUBSTR (X.NUCLIDE_FRACTION, 2).
OF OTHER X.NUCLIDE_FRACTION
END
OF OTHER X.NUCLIDE_FRACTION
END AS NUCLIDE_FRACTION
Of
(
-THE NUCLIDES EXIST IN * TWO * BEFORE AND AFTER VIEW. SOME OF THEIR ATTRIBUTES (MASS, NUCLIDE_FRACTION, ETC.) MAY HAVE CHANGED.
SELECT
STATUS AS NULL,
VALUE NULL AS STATUS_ORDER,
C.NUCLIDE,
BOX WHEN (NVL (C.A_MASS, 'Null')! = NVL (C.B_MASS, 'Null')) THEN ' *' | '< div class = "chg_highlight" >' | HTF. ESCAPE_SC (NVL (C.A_MASS, 'Null') |) ' => ' || NVL (C.B_MASS, 'Null')) | "< / div >"
Of ANOTHER NVL (C.B_MASS, 'Null')
MASS OF THE END AS,
----
BOX WHEN (NVL (C.A_NUCLIDE_FRACTION, 'Null')! = NVL (C.B_NUCLIDE_FRACTION, 'Null')) THEN ' *' | '< div class = "chg_highlight" >' | HTF. ESCAPE_SC (NVL (C.A_NUCLIDE_FRACTION, 'Null') |) ' => ' || NVL (C.B_NUCLIDE_FRACTION, 'Null')) | "< / div >"
Of ANOTHER NVL (C.B_NUCLIDE_FRACTION, 'Null')
END AS NUCLIDE_FRACTION
Of
(
SELECT
A.NUCLIDE,
TO_CHAR(A.MASS, '999.99EEEE') AS A_MASS,
TO_CHAR(A.NUCLIDE_FRACTION, '99999.999EEEE') AS A_NUCLIDE_FRACTION,
----
TO_CHAR(B.MASS, '999.99EEEE') AS B_MASS,
TO_CHAR(B.NUCLIDE_FRACTION, '99999.999EEEE') AS B_NUCLIDE_FRACTION
Of
V_URMT_COMPARE_NUCLIDE_DATA, A.
V_URMT_COMPARE_NUCLIDE_DATA B
WHERE
1 = 1
AND A.URMT_BTRS_PK = B.URMT_BTRS_PK
AND A.NUCLIDE = B.NUCLIDE
AND A.URMT_BTRS_PK = (SELECT URMT_BTRS_PK FROM W)-TO_NUMBER(:P202_URMT_BTRS_PK)
AND A.URMT_NOTICES_ID = (SELECT EARLIER_NOTICE_ID FROM W) - TO_NUMBER(:P202_COMPARE_EARLER_NOTICE_ID) - PRIOR NOTICE (EXAMPLE: 30 DAYS)
AND B.URMT_NOTICES_ID = (SELECT LATER_NOTICE_ID FROM W) - TO_NUMBER(:P202_COMPARE_LATER_NOTICE_ID) - FURTHER VIEWS (EXAMPLE: 7 DAYS.) NOTE: PRIOR NOTICE IS COMPARED WITH OPINIONS LATER, FOR EXAMPLE, 30 DAYS IS COMPARED TO 7 DAYS)
) C
UNION
-ADDED NOTICE LATER NUCLIDES. THEY DO NOT APPEAR IN THE EARLIER OPINION.
SELECT
"Added" AS the STATUS,
(BY SELECTING ADD_STATUS_ORDER IN W) AS STATUS_ORDER,
A.NUCLIDE,
TO_CHAR(A.MASS, '999.99EEEE') AS A_MASS,
TO_CHAR(A.NUCLIDE_FRACTION, '99999.999EEEE') AS A_NUCLIDE_FRACTION
Of
V_URMT_COMPARE_NUCLIDE_DATA HAS
WHERE
1 = 1
AND A.URMT_BTRS_PK = (SELECT URMT_BTRS_PK FROM W)-TO_NUMBER(:P202_URMT_BTRS_PK)
AND A.URMT_NOTICES_ID = (SELECT LATER_NOTICE_ID FROM W)-TO_NUMBER(:P202_COMPARE_LATER_NOTICE_ID)
AND NOT EXISTS
(SELECT NULL
OF V_URMT_COMPARE_NUCLIDE_DATA B
WHERE B.URMT_BTRS_PK = A.URMT_BTRS_PK
AND B.NUCLIDE = A.NUCLIDE
AND B.URMT_NOTICES_ID = (SELECT EARLIER_NOTICE_ID FROM W)-TO_NUMBER(:P202_COMPARE_EARLIER_NOTICE_ID)
)
UNION
-DELETED THE PREVIOUS NOTICE NUCLIDES. THEY DO NOT APPEAR IN THE NOTICE LATER.
SELECT
'Removed' AS the STATUS,
(BY SELECTING REM_STATUS_ORDER IN W) AS STATUS_ORDER,
A.NUCLIDE,
TO_CHAR(A.MASS, '999.99EEEE') AS A_MASS,
TO_CHAR(A.NUCLIDE_FRACTION, '99999.999EEEE') AS A_NUCLIDE_FRACTION
Of
V_URMT_COMPARE_NUCLIDE_DATA HAS
WHERE
1 = 1
AND A.URMT_BTRS_PK = (SELECT URMT_BTRS_PK FROM W)-TO_NUMBER(:P202_URMT_BTRS_PK)
AND A.URMT_NOTICES_ID = (SELECT EARLIER_NOTICE_ID FROM W)-TO_NUMBER(:P202_COMPARE_EARLER_NOTICE_ID)
AND NOT EXISTS
(SELECT NULL
OF V_URMT_COMPARE_NUCLIDE_DATA B
WHERE B.URMT_BTRS_PK = A.URMT_BTRS_PK
AND B.NUCLIDE = A.NUCLIDE
AND B.URMT_NOTICES_ID = (SELECT LATER_NOTICE_ID FROM W)-TO_NUMBER(:P202_COMPARE_LATER_NOTICE_ID)
)
) X
)
I have searched this forum for clues but found nothing.
Any help would be appreciated.
Thank you.
Elijah
EEG wrote:
I'll now try to place my report within a packaged procedure, and then run it from there. You don't love doing cela, but seem to don't have is not a choice.
Elijah
Huh? How can you put a SELECT statement in a procedure? you return a cursor reference?
You create VIEWS. You have three sections. Give an opinion on each of them. Test them with SQL Developer (or SQL * more)
Build from there.
In fact, it looks like you are trying to compare two tables"and return a DIFF
THINKING IN SETS
Use the WITH clause to build a 'virtual' table for EARLIER_NOTICE and a 'virtual' table for LATER_NOTICE.
Use FULL OUTER JOIN to compare the two.
THE FORMAT OF THE EXAMPLE:
select * from ( with w as ( .... ) ,table_A as ( -- build the Virtual Table for EARLIER_NOTICE SELECT * FROM V_URMT_COMPARE_NUCLIDE_DATA A1 join W on (A1.urmt_btrs_pk, W.urmt_btrs_pk and A1.earlier_notcie_id=W.earlier_notice_id) -- old code -- WHERE -- 1 = 1-- why??? -- AND A.URMT_BTRS_PK = (SELECT URMT_BTRS_PK FROM W) --TO_NUMBER(:P202_URMT_BTRS_PK) -- AND A.URMT_NOTICES_ID = (SELECT EARLIER_NOTICE_ID FROM W) --TO_NUMBER(:P202_COMPARE_EARLER_NOTICE_ID) ,table_b as ( -- build the Virtual Table for the LATER_NOTICE select * from V_URMT_COMPARE_NUCLIDE_DATA B1 join W on (b1.urmt_btrs_pk = W.urmt_btrs_pk and b1.urmt_notice_id=W.later_notice_id) ) --/*** NOW - WE COMPARE THE TWO ***/ select CASE when A.urmt_btrs_pk is null then 'ADDED' when B.urmt_btrs_pk is null then 'DELETED' else 'possibily updated' end CHANGES_MADE , A.* , B.* FROM TABLE_A A FULL OUTER JOIN B ON ( A.URMT_BTRS_PK = B.URMT_BTRS_PK AND A.NUCLIDE = B.NUCLIDE )
-
Formula using the following string...
Hi all
Given a set of strings that can is be parsed (see format below), possible to do a TWG
a set of such strings - i.e. the chain may have the form (from
another thread (pricing using the string formula)) the chain is a bulk
dicount "record" for a product - product code not included for now.
I want to use SQL exclusively, but am open to suggestions - examples
using WITH are especially welcome - has spent time last night, a truck load
rising WITH (of no use, it must be added ;))
_100 (20) 90 (50) 80_ String format
See the code below*-20 first purchased items cost 100,.
the cost of the next 50 90 and all the foregoing is 80/unit.
What I would like is to be able to build a 'table' that I can join real Oracle
tables - imagine these "records" of the chain are coming thick and fast and for reasons x, y
or z, prices can be written to a permanent table. A product code must be
included, but I think fundamental analysis once did, adding such a code should not
be a problem.
So, if I have a set of these strings, how build a TWG?
If it is the right approach.
Any ideas, references, URL - be it, much appreciated.
What would be really cool is if the code could take a product with an arbitrary
number of discounts - 2, some 3 (that is, for example), 4... & c...
TIA
Paul...
Code-Cerca Trova of another thread
My own efforts (did not know that Cerca Trova had done) - even if it's rubbish, at leastwith t as( select '100(20)90(50)80' str from dual ) select regexp_replace(regexp_substr(str,'\)\d*',1,2),'\)|\(','')from t -- 80 --select regexp_replace(regexp_substr(str,'\d*(\)|\()',1,1),'\)|\(','')from t -- 100 --select regexp_replace(regexp_substr(str,'\d*(\)|\()',1,2),'\)|\(','')from t -- 20 --select regexp_replace(regexp_substr(str,'\d*(\)|\()',1,3),'\)|\(','')from t -- 90 --select regexp_replace(regexp_substr(str,'\d*(\)|\()',1,4),'\)|\(','')from t -- 50
I tried ;)
Below retrieves the number 20 - sample - allows to extract all the numbersWITH StrTab AS -- *returns 100* = Price1 ( SELECT '100(20)90(50)80' iStr FROM Dual ) SELECT( TO_NUMBER(SUBSTR(iStr, 1, INSTR(iStr, '(', 1, 1) -1)) ) AS "Price1" FROM StrTab;
Published by: Paulie 9 may 2012 12:32SELECT -- *returns 20* = Quantity 1 TO_NUMBER( SUBSTR('100(20)90(50)80', (INSTR('100(20)90(50)80', '(', 1, 1) + 1) , (INSTR('100(20)90(50)80', ')', 1, 1) - (INSTR('100(20)90(50)80', '(', 1, 1) + 1)))) AS "Quantity1" FROM Dual;
Published by: Paulie 9 may 2012 12:36Hello
Whenever you have a problem, please post a CREATE TABLE and INSERT statements for a small example of data like this:
CREATE TABLE table_x ( id NUMBER (6) PRIMARY KEY , txt VARCHAR2 (30) ) ; INSERT INTO table_x (id, txt) VALUES (0, NULL); INSERT INTO table_x (id, txt) VALUES (1, '75'); INSERT INTO table_x (id, txt) VALUES (2, '100(10)80'); INSERT INTO table_x (id, txt) VALUES (3, '100(20)90(50)80'); COMMIT;
In addition, to say what version of Oracle you are using. The query below work Oracle 10.1 and higher:
WITH cntr AS ( SELECT LEVEL AS n FROM dual CONNECT BY LEVEL <= 5 -- worst case ) , rates AS ( SELECT x.id , x.txt , c.n , TO_NUMBER ( REGEXP_SUBSTR ( '0)' || x.txt , '[^()]+' , 1 , (2 * c.n) - 1 ) ) AS start_qty , TO_NUMBER ( REGEXP_SUBSTR ( x.txt , '[^()]+' , 1 , (2 * c.n) - 1 ) ) AS rate FROM table_x x JOIN cntr c ON c.n <= LENGTH (txt) + 1 - LENGTH (REPLACE (txt, '(')) ) SELECT * FROM rates ORDER BY id , n ;
Output:
` ID TXT N START_QTY RATE ---------- ------------------------------ ---------- ---------- ---------- 1 75 1 0 75 2 100(10)80 1 0 100 2 100(10)80 2 10 80 3 100(20)90(50)80 1 0 100 3 100(20)90(50)80 2 20 90 3 100(20)90(50)80 3 50 80
If you use the WITH clauses above in any question, you can use rates in table form in the following parts of the query.
This assumes you know an upper limit for the number of items in the string. I took 5 different rates above, but you can easily change that to any fixed number. You can also derive the exact number of data themselves. I'll leave that as an exercise.
You can use the analytical function of LEAD to add another column, end_qty, rates.
Published by: Frank Kulash, 9 may 2012 10:24
It also means that txt is well-formed. A space before or after the parentheses is probably correct, but in additional brackets, letters, several decimal places or sign in the same 'number' and things like that will cause all errors.START_QTY is a misleading name; I should have used something like LOW_QTY or PREV_QTY. In the example above, the row with id = 3 and start_qty = 20 applies in reality to the amount above 20, i.e. 21 to 50 inclusively (since 50 is START_QTY for this id).
-
Insert using the table with the clause and select?
Hello gurus,
Can I insert in a table by making use of clause and select?
something similar to this...
Thank you very much!!!insert into test_table (with abc as (select * from emp_tble where dept_no = 10 ) select * from abc; ); if not i would i do by making use of with clause & select ... any example would be great !!
Brackets are disturbing only:
SQL> insert into test_table (with t as (select * from emp) select * from t) / Error at line 12 ORA-32034: unsupported use of WITH clause SQL> insert into test_table with t as (select * from emp) select * from t / 14 rows created.
-
PL/SQL parameter in fusion by using the clause
Hi all
I need to create a procedure where I use the Merge clause. However, by using the condition, I have to put value user_define (V_LOCALE_CD). This value checks table of locale and then to make a match with table of flex_labels_test.
There is no specific requirement and I don't have the test data.
My only question how do I use user set the value using the condition. Here is the procedure I created as follows.
create or replace the PROCEDURE UPSERT_FLEX_LABEL_3 (V_LOCALE_CD IN VARCHAR2,
V_VALUE IN VARCHAR2,
V_FIELDVALUE IN VARCHAR2,
V_FIELDNAME IN VARCHAR2,
V_TABLENAME IN VARCHAR2,
N_FLEX_TYPE NUMBER,
V_COLOR IN VARCHAR2 DEFAULT NULL,
N_IMAGE_LIBRARY_ID IN THE NUMBER DEFAULT NULL,
N_HIERARCHY_ID IN DEFAULT NUMBER 5237260000000000001,
N_IS_INHERITED IN THE DEFAULT NUMBER 1)
AS
L_COUNT NUMBER;
NUMBER OF N_LOCALE_ID;
NUMBER OF NN_HIERARCHY_ID: = 5237260000000000001;
NUMBER OF NN_IS_INHERITED: = 1;
NUMBER OF INSERTCOUNT;
UPDATECOUNT NUMBER;
NUMBER OF ERR_CODE;
ERR_MSG VARCHAR2 (100);
BEGIN
-SELECT ID IN N_LOCALE_ID OF PLACES WHERE LOCALE_CD = V_LOCALE_CD;
/ * IT WILL CHECK DUPLICATES, IF THEY ARE PRESENT, THEN IT WILL UPDATE RECORD ELSE IT WILL INSERT A NEW RECORD * /.
BEGIN
Merge into fl flex_labels_test
using (select locale id where locale_cd = V_LOCALE_CD) L
on (l.id = fl.locale_id)
When matched then
GAME UPDATE
HIERARCHY_ID = NVL (N_HIERARCHY_ID, NN_HIERARCHY_ID),
IS_INHERITED = NVL (N_IS_INHERITED, NN_IS_INHERITED),
FLEX_TYPE = N_FLEX_TYPE,
VALUE = V_VALUE,
IMAGE_LIBRARY_ID = N_IMAGE_LIBRARY_ID,
COLOR = V_COLOR
WHERE TABLENAME = V_TABLENAME
AND FIELDNAME = V_FIELDNAME
AND FIELDVALUE = V_FIELDVALUE
When not matched then
INSERT (HIERARCHY_ID, ID_PARAMETRES_REGIONAUX, IS_INHERITED, FLEX_TYPE, TABLENAME, FIELDNAME, FIELDVALUE, VALUE, IMAGE_LIBRARY_ID, COLOR)
VALUES (NVL (N_HIERARCHY_ID, NN_HIERARCHY_ID), N_LOCALE_ID, NVL (N_IS_INHERITED, NN_IS_INHERITED), N_FLEX_TYPE, V_TABLENAME, V_FIELDNAME, V_FIELDVALUE, V_VALUE, N_IMAGE_LIBRARY_ID, V_COLOR);
UPDATECOUNT: = NUMBER OF ROWS SQL %;
EXCEPTION
WHILE OTHERS THEN
ERR_CODE: = SQLCODE;
ERR_MSG: = SUBSTR (SQLERRM, 1, 200);
DBMS_OUTPUT. PUT_LINE ("ERRORS" |) ERR_CODE | ' AND ' | ERR_MSG);
END;
COMMIT;
DBMS_OUTPUT. PUT_LINE ('RECORD INSERTCOUNT =' |) NVL(INSERTCOUNT,0));
DBMS_OUTPUT. PUT_LINE (' UPDATECOUNT RECORD ='|) NVL(UPDATECOUNT,0));
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR (-20001, "ID NOT FOUND REGIONAL SETTINGS");
END;
I guess that's what I was looking for. Thank you guys for your efforts.
-
Using XQuery with PL/SQL, link the Variable
I am only able to find an example of use of xquery with pl/sql.
[http://www.comp.dit.ie/btierney/oracle11gdoc/appdev.111/b28369/xdb_xquery.htm#CBAEEJDE]
Why is what they show only using bind variables? It's the only way it should be used, it provides a performance gain more simply by using the crossing clause and a passing beam a PL/SQL variable? I'm looking to implement a solution for my company using Xquery in PL/SQL. I am concerned that these procedures will be called during a flow of the user interface and performance it must be as soon as possible.A PL/SQL variable, column, or the output of another operation would be all be equivalent to a connection variable that PL/SQL compilation is concerned. Which would be bad practice would be to build in XQuery with the predicate hardcoded in the XQuery operation whenever the XQuery query has been run.
-
Not able to connect after changing the password using the VALUES ALTER clause
Hello
John explained earlier the clause VALUES below thread.
Status expired
I created a new account named SURI, and tried to use the password of the user account from the HR by using the VALUES clause. I was able to change the password but not able to connect SURI with HR password.
Please see below for details. And the SQL statements that I have tried.
Thank youSQL*Plus: Release 10.2.0.1.0 - Production on Mon Aug 13 18:44:50 2012 Copyright (c) 1982, 2005, Oracle. All rights reserved. Enter user-name: sys as sysdba Enter password: Connected to: Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production SQL> SELECT password 2 FROM dba_users 3 WHERE username = 'HR'; PASSWORD ------------------------------ 4C6D73C3E8B0F0DA SQL> ALTER USER SURI IDENTIFIED BY VALUES '4C6D73C3E8B0F0DA'; User altered. SQL> SELECT password 2 FROM dba_users 3 WHERE username='SURI'; PASSWORD ------------------------------ 4C6D73C3E8B0F0DA SQL> conn suri/hr -- HR account's password is hr only ERROR: ORA-01017: invalid username/password; logon denied Warning: You are no longer connected to ORACLE. SQL>
SuriIts because you have used a different username.
Oracle produces a hash based on the user name and the password, not only the password.Therefore, you can not use the hashed password of a user to log on to the account of another user.
You need to get the password hashed Suri and then connect you to suri by using the password hashed Suri (using the identified by the syntax of values)
-
How to use the "Order by" clause dynamically on values LOV Forms 10g r2
Hello
I have following requirement, please guide me.
1. create a list of values with 2 fields, Code and Description
2. do not use the command clause contained in the registration request Group
3. fix this LOV on a form field
4. when the user calls the user LOV will see two fields in LOV with header as Code and Description
5. when the user clicks the column header "Code" then LOV should be arranged on Code
6 and if the user clicks on the header of the column "Description" then LOV must be sorted on the Description
Thanks in advance.Please post this problem in this forum->
[Formulas Forum | http://forums.oracle.com/forums/forum.jspa?forumID=82]
And close this thread by he scored as replied. ;)
Kind regards.
LOULOU.
-
Hi all
I use under version
Connected to Oracle Database 11g Express Edition Release 11.2.0.2.0
SQL > WITH
2 EMP
3 AS
4 ("JOEL" SELECT ENAME,
DEPTNO 40 5
6 OF
DOUBLE 7
8 UNION ALL
9. SELECT ENAME "MARY."
10 50 DEPTNO
11 DOUBLE)
12. SELECT E.ENAME,
13 D.DNAME
14. TO EMP E
FULL JOIN 15
DEPT 16 D
17-HELP
18 (DEPTNO);
ENAME DNAME
----- --------------
ACCOUNTING
SEARCH
SALES
JOEL OPERATIONS
MARY
My doubt is that I use EMP as with the name of clause.
In the condition when I select of the EMP.
It is guaranteed that extracts data from request formed in the with clause, because I have a table named EMP in my diagram.
Thank you
Hello
2947022 wrote:
Hi all
I use under version
Connected to Oracle Database 11g Express Edition Release 11.2.0.2.0
SQL > WITH
2 EMP
3 AS
4 ("JOEL" SELECT ENAME,
DEPTNO 40 5
6 OF
DOUBLE 7
8 UNION ALL
9. SELECT ENAME "MARY."
10 50 DEPTNO
11 DOUBLE)
12. SELECT E.ENAME,
13 D.DNAME
14. TO EMP E
FULL JOIN 15
DEPT 16 D
17-HELP
18 (DEPTNO);
ENAME DNAME
----- --------------
ACCOUNTING
SEARCH
SALES
JOEL OPERATIONS
MARY
My doubt is that I use EMP as with the name of clause.
In the condition when I select of the EMP.
It is guaranteed that extracts data from request formed in the with clause, because I have a table named EMP in my diagram.
Thank you
Yes, if the emp is an alias and emp is also a real table, and both have a scope, then Oracle assumes you mean the alias. To avoid confusion and errors, do not use the actual table as alias names.
It goes same for columns and column aliases.
In PL/SQL, the same type of confusion can arise between the variables and the column names. When there is a choice, Oracle assumes you are talking about the variable.
-
Hi all
I'm using oracle 11.2.0.4
I m using this for the purpose of learning
Below is my table and insert statement
CREATE TABLE NUMBERS (NUMBER NUM);
INSERT A NUMBER VALUES (1);
INSERT A NUMBER VALUES (2);
INSERT A NUMBER VALUES (3);
INSERT THE 4 NUMBERS;
WITH RSFC(ITERATION,RUNNING_FACTORIAL) AS
(SELECT NUM AS ITERATION,
1 AS RUNNING_FACTORIAL
A NUMBER
WHERE NUM = 1
UNION ALL
SELECT R.ITERATION + 1,
R.RUNNING_FACTORIAL * B.NUM
RSFC R INNER JOIN NUMBERS B
ON (R.ITERATION + 1) + B.NUM
)
SELECT THE ITERATION, RUNNING_FACTORIAL
THE RSFC
I learn recursive with clause
When I am trying to run the query, I get
ORA-00920: invalid realtional operator
What's not in this query, please help me
Thanks and respect.
Guylaine
Hello
2937991 wrote:
Hi all
I'm using oracle 11.2.0.4
I m using this for the purpose of learning
Below is my table and insert statement
CREATE TABLE NUMBERS (NUMBER NUM);
INSERT A NUMBER VALUES (1);
INSERT A NUMBER VALUES (2);
INSERT A NUMBER VALUES (3);
INSERT THE 4 NUMBERS;
WITH RSFC(ITERATION,RUNNING_FACTORIAL) AS
(SELECT NUM AS ITERATION,
1 AS RUNNING_FACTORIAL
A NUMBER
WHERE NUM = 1
UNION ALL
SELECT R.ITERATION + 1,
R.RUNNING_FACTORIAL * B.NUM
RSFC R INNER JOIN NUMBERS B
ON (R.ITERATION + 1) + B.NUM
)
SELECT THE ITERATION, RUNNING_FACTORIAL
THE RSFC
I learn recursive with clause
When I am trying to run the query, I get
ORA-00920: invalid realtional operator
What's not in this query, please help me
Thanks and respect.
Guylaine
The error has actually nothing to do with the WITH clause.
Join conditions (i.e. the conditions following the keyword WE) must be expressions that are evaluated to TRUE or FALSE. The join condition, you have validated, however
(R.ITERATION + 1) + B.NUM
corresponding to a NUMBER. The following would be a valid join condition:
(R.ITERATION + 1) = B.NUM
but I don't know if it of what you wanted or not.
Maybe you are looking for
-
My second generation G motorcycle has a problem on the screen: I play at some point, and it is clear that I play a point below. You can avoid I less the status bar. To resolve I have to turn on/off the screen again. Bothers a lot. It is a software pr
-
I'm doing a single image from a folder of multiple images. Images are jpgs, which is also I wish that the final image. The final product should be a grid square with all the images edge to edge. Currently, I have acquired regarding their reorganizati
-
Magnifier and Narrator of microsoft is on the way to disable
found that my answer will try immediately, thank you very much.
-
Get the 12002 error code when trying to send emails
Original title: mistake in the AJAX request While he was trying to send mails, I get this message In the AJAX request error XMLIhttp State 12002-unknown Just a beginner with computers
-
WMV is no projection in media center
I have a file of imported videos WMC and it shows the. MP4 but does not show. WMV.If I open Media Player, it shows and plays all files.I thought that it was not last updated the file, so I added a few more. MP4 and they appear and play.Tried to conve