GROUP BY clause diff in Sybase and Oracle
HelloI am migrating from Sybase to Oracle code and came across a strange problem which is widely known to others :)
In Sybase, you can use columns or calculations in SELECTION expressions that do not appear
in the GROUP BY clause from the query. As
SELECT order.custid, customer.name, MAX (payments)
-> IN the order, customer
-> WHERE order.custid = customer.custid
-> GROUP BY order.custid;
works fine but for SQL, we must add customer.name to the customer of the GROUP BY clause.
In the same spirit, here is my SQL query
INSERT INTO GTT_CTRT_recalc_proc
(id_fin_rec,
id_imnt,
id_instr_opn,
dt_instr_opn,
dt_opn,
dt_cls_loanet,
dt_prcss,
am_invst)
SELECT t1.id_fin_rec,
T1.id_imnt,
T1.id_instr_opn,
T1.dt_instr_opn,
T1.dt_opn,
NVL (t1.dt_cls_loanet, l_dt_to),
T1.dt_prcss,
Sum (T2.am_invst) + (0.123 * (1 - abs (sign (0 - SUM (t2.am_invst)))))
OF GTT_CTRT_TEMP_recalc_process t1, GTT_CTRT_TEMP_recalc_process t2
WHERE t2.id < = t1.id
AND t2.id_imnt = t1.id_imnt
AND t2.id_instr_opn = t1.id_instr_opn
AND t2.dt_instr_opn = t1.dt_instr_opn
T1.id_imnt GROUP,
T1.id_instr_opn,
T1.dt_instr_opn,
T1.dt_opn,
T1.dt_cls_loanet,
T1.dt_prcss;
Has no t1.id_fin_rec in GROUP BY it fails in SQL.
I know that if I add this column in GROUP BY, it will work fine, but told me to keep the feature because it is as the result before and after the addition of the column is different, of course.
If please guide me what we can do in this situation and should work around that?
Thank you
Aashish
Use the PARTITION MORE rtaher than GROUP BY
INSERT INTO GTT_CTRT_recalc_proc
(id_fin_rec, id_imnt, id_instr_opn, dt_instr_opn, dt_opn, dt_cls_loanet, dt_prcss, am_invst)
SELECT t1.id_fin_rec, t1.id_imnt, t1.id_instr_opn, t1.dt_instr_opn, t1.dt_opn, NVL(t1.dt_cls_loanet, l_dt_to),
t1.dt_prcss,
SUM(t2.am_invst) OVER(PARTITION BY t1.id_imnt, t1.id_instr_opn, t1.dt_instr_opn, t1.dt_opn, t1.dt_cls_loanet, t1.dt_prcss)
+ (0.123 * (1 - ABS(SIGN(
0 - SUM(t2.am_invst) OVER(PARTITION BY t1.id_imnt, t1.id_instr_opn, t1.dt_instr_opn, t1.dt_opn, t1.dt_cls_loanet, t1.dt_prcss)))))
FROM GTT_CTRT_TEMP_recalc_process t1, GTT_CTRT_TEMP_recalc_process t2
WHERE t2.ID <= t1.ID
AND t2.id_imnt = t1.id_imnt
AND t2.id_instr_opn = t1.id_instr_opn
AND t2.dt_instr_opn = t1.dt_instr_opn
Tags: Database
Similar Questions
-
-SQL - GROUP BY clause: fields of nonaggregate mandate
Hello
I study data (especially data recovery) and found something interesting.
When you use an aggregate function in the SELECT clause, it is mandatory to have all fields that are not aggregated in the SELECT clause to be there in the GROUP BY clause.
For example,.
SELECT dept_no, Salary
The EMPLOYEE
GROUP BY dept_no;
The SQL above works fine.
But what happens if the user forgets the dept_no in the GROUP BY clause or the clause GROUP BY itself is missing?
Certainly, it is a mistake.
Why this error is not handled by the database. I mean, the database must be smart/pretty smart to add the GROUP BY clause by itself. So let's assume that, if I miss the GROUP BY clause or miss a field no aggregated from the SELECT clause when I get at least an aggregate function on a field with at least a no aggregated field in the SELECT clause, the database should check the GROUP BY clause at compile time and add mandate missed the fields in the GROUP BY clause.
Example,
SQL1:_
SELECT dept_no, Salary
The EMPLOYEE
GROUP BY dept_no;
SQL2:_
SELECT dept_no, Salary
The EMPLOYEE;
Here, the SQL1 and SQL2, both should give me same output without error.
I can't understand why this is handled?Hello
998478 wrote:
... If we mix the aggregated and non-aggregated values, then there must be a GROUP BY clause that contains all non-aggregated values. Why this is handled by the database/compiler itself?It IS managed by the compiler itself. The compiler manages to trigger an error. The compiler has no way of knowing if you want to remove something from the SELECT clause, or add something to the GROUP BY clause, or not to use the aggregate functions or use several aggregate functions, or a combination of the above. If the compiler re-writes your code and none of these things done automatically, it would be wrong more often that he was right, and you would (rightly) complain about his behavior.
For example, it is clearly wrong:
SELECT deptno , job , SUM (sal) FROM scott.emp GROUP BY deptno ;
What is the right way to fix it?
1. remove something from the SELECT clause
SELECT deptno , SUM (sal) FROM scott.emp GROUP BY deptno ;
2. add something to the GROUP BY clause
SELECT deptno , job , SUM (sal) FROM scott.emp GROUP BY deptno , job ;
3. do not use aggregate functions
SELECT deptno , job , sal FROM scott.emp ;
4. use several aggregate functions
SELECT deptno , MIN (job) , SUM (sal) FROM scott.emp GROUP BY deptno ;
What are all the options, either. For example, the correct solution would be to use analytical functions instead of aggregate functions.
How can anyone tell which of them is right? They all have the right answer for some problem.Moreover, by saying that everying in the SELECT clause must be an aggregate or in the GROUP BY clause is a bit oversimplified.
Fuller, here's the ABC of GROUP BY:
When you use a GROUP BY clause or in an aggregate function, then all in the SELECT clause must be:
(A) a ggregate function,
(B) one of the expressions "group By."
(C) adding to C, or
(D) something that Depends on the foregoing. (For example, if you "GROUP BY TRUNC (dt)", you can SELECT "TO_CHAR (TRUNC (dt), 'Mon - DD')").Published by: Frank Kulash on April 13, 2013 13:44
Additional code examples. -
Group By clause in oracle 10g need help
Hello
We have a requirement that get the AR details of aging at the customer level. I wrote the following query to retrieve the correct rows at the invoice level. But now I need calculate the sum of the amounts and I show you the invoice and customer level. Could you please help me how can I group by the client.
Here's the query I used
Select ps.org_id
sobbed. SET_OF_BOOKS_ID
sobbed. CHART_OF_ACCOUNTS_ID
gcc. Company of SEGMENT1
gcc. SEGMENT2 location
gcc. Department of SEGMENT3
gcc. SEGMENT4 account
gcc. Future_1 SEGMENT5
gcc. SEGMENT6 Future_2
gcc. SEGMENT7 Future_3
gcc. CONCATENATED_SEGMENTS gl_cc_concat_kff
ps.trx_number
ps.trx_date
ps.due_date
ps.invoice_currency_code
sob.currency_code SOB_Currency_Code
ps.class
ps.amount_due_original
, ps.amount_due_original * nvl (ps.exchange_rate, 1) acctd_amount_due_original
ps.amount_due_remaining
ps.acctd_amount_due_remaining
ps.status
ps.cust_trx_type_id
ps.customer_site_use_id
ps.customer_trx_id
ps.cash_receipt_id
ps.gl_date
rctlda. CODE_COMBINATION_ID
ps.customer_id
nvl (ATCM. ATTRIBUTE5, ps. CUSTOMER_ID) End_Customer_Id
rc.customer_number
rc2. CUSTOMER_NUMBER Brand_Cust_no
, round ((sysdate-ps.due_date))
of gl_sets_of_books ob
, hr_operating_units or
ar_payment_schedules_all ps
ra_customers rc
ra_cust_trx_line_gl_dist_all rctlda
gl_code_combinations_kfv gcc
ra_customer_trx_all ATCM
ra_customers rc2
where sob.set_of_books_id = ou.set_of_books_id
and ou.organization_id = ps.org_id
and ps.status = 'OP '.
and ps.org_id is not null
and ps. CUSTOMER_ID = rc. CUSTOMER_ID
and ps. CUSTOMER_TRX_ID = rctlda. CUSTOMER_TRX_ID
and rctlda. ACCOUNT_CLASS = "REC".
and rctlda.latest_rec_flag = 'Y '.
and rctlda. CODE_COMBINATION_ID = gcc. CODE_COMBINATION_ID
and ps. CUSTOMER_TRX_ID = ATCM. CUSTOMER_TRX_ID
and gcc. CODE_COMBINATION_ID = 39446
- and ps.trx_number = 1-15O0A8O'
- and rc. CUSTOMER_NUMBER = 1-10PA5KX'
and nvl (ATCM. ATTRIBUTE5, ps. CUSTOMER_ID) = rc2. CUSTOMER_ID
Could someone help me how to recover the same columns with sum (ps.amount_due_original) for each client. I tried to use the group by clause, but it gives to new level of the invoice.
But my req's for each customer the amount of the invoice must be added and it should give the total
Thank you
THEREIf you need to have the amount of the invoice for each customer may also need to check the
CUBE
http://download.Oracle.com/docs/CD/B28359_01/server.111/b28286/statements_10002.htm#sthref9448
and example here
http://download.Oracle.com/docs/CD/B28359_01/server.111/b28286/statements_10002.htm#i2066443and ROLLUP
http://download.Oracle.com/docs/CD/B28359_01/server.111/b28286/statements_10002.htm#sthref9445I couldn't keep up with all your SQL statement, or I could rewrite for you once again
Thank youPublished by: user9532576 on July 21, 2009 09:24
-
Dear all,
Kindly advise on below 2 doubts which have been daunting for quiet some time. The bottom has forced our requests to take alternative routes to receive solutions.
Doubt 1) is it possible for us to use 'select (*)' with a group and a join clause, if we have at least 2/3 tables with minimum 15-20 columns... given the constraint of having to add all the names column in the group by clause.
Question 2) is it possible to use "select" (*) with the exception of a single column of the table?
That is to say, I hate the output of a statement select (*) to have the entire field except a field in a tableAsk your advisor for the same thing. Excuse me because I have no examples to illustrate this point in time. A successful idea will do.
Thank you and best regards,
Séverine Suresh
Hey, Sebastian,
Séverine Suresh - 3035408 wrote:
Dear all,
Kindly advise on below 2 doubts which have been daunting for quiet some time. The bottom has forced our requests to take alternative routes to receive solutions.
Doubt 1) is it possible for us to use 'select (*)' with a group and a join clause, if we have at least 2/3 tables with minimum 15-20 columns... given the constraint of having to add all the names column in the group by clause.
Sure. If you had problems, you did it wrong. Your postal code, examples of data (CREATE TABLE and INSERT statements) and the results desired from these data.
Check out the Forum FAQ: Re: 2. How can I ask a question on the forums?
Normally, you don't want to ' SELECT *...» "in a join. Are most joins are equijoins, ' SELECT *...» "produced 2 copies of / columns used for Assembly. In addition, many tables have columns (for example, modified_date) that are not necessary in most applications.
All columns must be included explicitly in a GROUP BY clause. You cannot use * it.
You can not have parentheses around the * in ' SELECT *...» ». You might think 'SELECT COUNT (*) '
Question 2) is it possible to use "select" (*) with the exception of a single column of the table?
That is to say, I hate the output of a statement select (*) to have the entire field except a field in a table...
No.; If you don't want a particular column in the result set, you cannot use "SELECT *...» ».
Your front end can have so as not to display a column in the result set. For example, in SQL * more:
COLUMN modified_date NOPRINT
means that you won't see any column called modified_date.
-
Teradata Database, sybase ASE and oracle database
Hello
What are the differences between the teradata database and oracle db architecture?
I have experience working on the oracle database, but none on teradata and sybase ASE.
(1) as stated I know oracle schema is a user is the same in teradata and sybase ASE?
(2) what is the architecture and sybase ASE teredata follows as oracle doesn't.who have more beneficial to architecture?
Teradata 3) following a transact sql (I guess) what?
(4) teradata have backup archiving and recovery feature is it identical to oracle RMAN?
etc.
Kind regardsyou,
You probably meant to ask [url http://forums.teradata.com/forum] here and [url http://www.sybase.co.uk/support/community-forums] here
me
-
By the way where and group by clause Cursor
I'm working on a procedure that generates a where clause clause and needs of a group by clause to return the correct results. I'm moving the two where and group variables in the cursor.
The variables are is filled correctly, but when the cursor is created, variables are not in the cursor.
Here's the code I'm working with. It is part of a package, but does no appeal to other parts of the package.
PROCEDURE createFollowUpTask_Exposure (psUppgkedjetyp IN tis.tial.uppgkedjetyp%TYPE NULL by default,
psAlarmtyp IN tis.tial.alarmtyp%TYPE by default NULL,
psSubtyp IN tis.tial.subtyp%TYPE by default NULL,
pnDays in NUMBER NULL by default,
psKampkod IN tis.tiin.kampkod%TYPE by default NULL,
psKatnr IN tis.tiin.katnr%TYPE by default NULL,
psUtgava IN tis.tiin.utgava%TYPE by default NULL,
psKatslag IN tis.tikg.katslag%TYPE by default NULL,
psProdsyst IN tis.tikg.prodsyst%TYPE by default NULL,
psUppgtyp IN tis.tiin.uppgtyp%TYPE by default NULL,
psProdkod IN tis.tiin.prodkod%TYPE by default NULL,
psStatus IN tis.tiin.status%TYPE by default NULL
) AS
--
cTIAL tis.tial%ROWTYPE;
vLopnr tis.tial.lopnr%TYPE;
vSqlWhere VARCHAR2 (4000);
vGroupBy VARCHAR2 (1000): = "tiin.kampkod, tiin.abnr, tiko.fordsalj;
cSelectCursor SYS_REFCURSOR;
vSqlSelect VARCHAR2 (4000);
psDays VARCHAR2 (50);
cRec T_TIAL_REC;
nCount number: = 0;
--
CURSOR cSqlSelect (SqlWhere IN VARCHAR2, GroupBy IN VARCHAR2) IS
SELECT tiin.kampkod, tiin.abnr, tiko.fordsalj, MAX (tici.regdat) ALARMDATE
OF tis.tiin
JOIN tis.tiko ON tiin.kampkod = tiko.kampkod AND tiin.abnr = tiko.abnr
JOIN core.tici ON tiin.kampkod = tici.kampkod AND tiin.abnr = tici.abnr AND tici.inplnr = tiin.inplnr
WHERE 1 = 1 | SqlWhere
GroupBy GROUP;
--
BEGIN
-If these parameters are null, trigger the error
IF psUppgkedjetyp IS NULL and psSubtyp IS NULL THEN
raise_application_error (-20001,
"String from the event or events must be assigned");
END IF;
-Fill the TIAL values
IF psUppgkedjetyp IS NOT NULL THEN
cTIAL.Uppgkedjetyp: = psUppgkedjetyp;
END IF;
--
IF psAlarmtyp IS NOT NULL THEN
cTIAL.Alarmtyp: = psAlarmtyp;
END IF;
--
cTIAL.Handklass: = 't';
cTIAL.Blobid: = 0;
--
IF pnDays IS NOT NULL THEN
psDays: = '+' | pnDays;
END IF;
IF psSubtyp IS NOT NULL THEN
cTIAL.Subtyp: = psSubtyp;
END IF;
-Create Where clause for cursor
vSqlWhere: = ";
IF psKampkod IS NOT NULL THEN
vSqlWhere: = vSqlWhere | "AND tiin.kampkod ="' | psKampkod | " ' ;
END IF;
--
IF psKatnr IS NOT NULL THEN
vSqlWhere: = vSqlWhere | "AND tiin.katnr ="' | psKatnr | " ' ;
END IF;
--
IF psUtgava IS NOT NULL THEN
vSqlWhere: = vSqlWhere | "AND tiin.utgava ="' | psUtgava | " ' ;
END IF;
--
IF psKatslag IS NOT NULL THEN
vSqlWhere: = vSqlWhere | "AND tikg.katslag ="' | psKatslag | " ' ;
END IF;
--
IF psProdsyst IS NOT NULL THEN
vSqlWhere: = vSqlWhere | "AND tikg.prodsyst ="' | psProdsyst | " ' ;
END IF;
--
IF psUppgtyp IS NOT NULL THEN
vSqlWhere: = vSqlWhere | "AND tiin.uppgtyp ="' | psUppgtyp | " ' ;
END IF;
--
IF psProdkod IS NOT NULL THEN
vSqlWhere: = vSqlWhere | "AND tiin.prodkod ="' | psProdkod | " ' ;
END IF;
--
IF psStatus IS NOT NULL THEN
vSqlWhere: = vSqlWhere | "AND tiin.status ="' | psStatus | " ' ;
END IF;
-Browse all records in input parameters of the meeting and set values required TIAL.
I'm IN cSqlSelect (vSqlWhere, vGroupBy)
--
LOOP
-EXTRACT cSelectCursor INTO cRec;
cTIAL.Kampkod: = ";
cTIAL.Abnr: = ";
cTIAL.Sign: = ";
cTIAL.Alarmdate: = ";
cTIAL.Kampkod: = i.Kampkod;
cTIAL.Abnr: = i.Abnr;
cTIAL.Sign: = i.fordsalj;
cTIAL.Alarmdate: = i.alarmdate;
--
nCount: = nCount + 1;
--
IF vLopnr = - 1 THEN
raise_application_error (-20002,
"Error creating task for: ' | '. cTIAL.Kampkod |' '|| cTIAL.Abnr |' Sales representative: ' | cTIAL.Alarmdate);
END IF;
END LOOP;
DBMS_OUTPUT. Put_line (' I created ' | nCount |) "documents.");
END createFollowUpTask_Exposure;
Thanks in advance for any help.Hello
Welcome to the forum!
Try this (untested) example:
PROCEDURE createFollowUpTask_Exposure(psUppgkedjetyp IN tis.tial.uppgkedjetyp%TYPE DEFAULT NULL, psAlarmtyp IN tis.tial.alarmtyp%TYPE DEFAULT NULL, psSubtyp IN tis.tial.subtyp%TYPE DEFAULT NULL, pnDays IN NUMBER DEFAULT NULL, psKampkod IN tis.tiin.kampkod%TYPE DEFAULT NULL, psKatnr IN tis.tiin.katnr%TYPE DEFAULT NULL, psUtgava IN tis.tiin.utgava%TYPE DEFAULT NULL, psKatslag IN tis.tikg.katslag%TYPE DEFAULT NULL, psProdsyst IN tis.tikg.prodsyst%TYPE DEFAULT NULL, psUppgtyp IN tis.tiin.uppgtyp%TYPE DEFAULT NULL, psProdkod IN tis.tiin.prodkod%TYPE DEFAULT NULL, psStatus IN tis.tiin.status%TYPE DEFAULT NULL) AS -- cTIAL tis.tial%ROWTYPE; vLopnr tis.tial.lopnr%TYPE; vSqlWhere VARCHAR2(4000); vGroupBy VARCHAR2(1000) := ' tiin.kampkod, tiin.abnr, tiko.fordsalj'; cSelectCursor SYS_REFCURSOR; vSqlSelect VARCHAR2(4000); psDays VARCHAR2(50); cRec T_TIAL_REC; nCount NUMBER := 0; FUNCTION fnc_cSqlSelect(SqlWhere IN VARCHAR2, GroupBy IN VARCHAR2) RETURN VARCHAR2 IS BEGIN RETURN 'SELECT tiin.kampkod, tiin.abnr, tiko.fordsalj, MAX(tici.regdat) ALARMDATE FROM tis.tiin JOIN tis.tiko ON tiin.kampkod = tiko.kampkod AND tiin.abnr = tiko.abnr JOIN core.tici ON tiin.kampkod = tici.kampkod AND tiin.abnr = tici.abnr AND tici.inplnr = tiin.inplnr WHERE 1 = 1 ' || SqlWhere || ' GROUP BY ' || GroupBy; END fnc_cSqlSelect; BEGIN -- If these parameters are null, raise error IF psUppgkedjetyp IS NULL AND psSubtyp IS NULL THEN raise_application_error(-20001, 'Either Event Chain or Starting Event must be assigned'); END IF; -- Populate TIAL values IF psUppgkedjetyp IS NOT NULL THEN cTIAL.Uppgkedjetyp := psUppgkedjetyp; END IF; -- IF psAlarmtyp IS NOT NULL THEN cTIAL.Alarmtyp := psAlarmtyp; END IF; -- cTIAL.Handklass := 'T'; cTIAL.Blobid := 0; -- IF pnDays IS NOT NULL THEN psDays := '+ ' || pnDays; END IF; IF psSubtyp IS NOT NULL THEN cTIAL.Subtyp := psSubtyp; END IF; -- Create Where clause for cursor vSqlWhere := ''; IF psKampkod IS NOT NULL THEN vSqlWhere := vSqlWhere || ' AND tiin.kampkod = ''' || psKampkod || ''''; END IF; -- IF psKatnr IS NOT NULL THEN vSqlWhere := vSqlWhere || ' AND tiin.katnr = ''' || psKatnr || ''''; END IF; -- IF psUtgava IS NOT NULL THEN vSqlWhere := vSqlWhere || ' AND tiin.utgava = ''' || psUtgava || ''''; END IF; -- IF psKatslag IS NOT NULL THEN vSqlWhere := vSqlWhere || ' AND tikg.katslag = ''' || psKatslag || ''''; END IF; -- IF psProdsyst IS NOT NULL THEN vSqlWhere := vSqlWhere || ' AND tikg.prodsyst = ''' || psProdsyst || ''''; END IF; -- IF psUppgtyp IS NOT NULL THEN vSqlWhere := vSqlWhere || ' AND tiin.uppgtyp = ''' || psUppgtyp || ''''; END IF; -- IF psProdkod IS NOT NULL THEN vSqlWhere := vSqlWhere || ' AND tiin.prodkod = ''' || psProdkod || ''''; END IF; -- IF psStatus IS NOT NULL THEN vSqlWhere := vSqlWhere || ' AND tiin.status = ''' || psStatus || ''''; END IF;ç -- Loop through all records meeting input parameters and set required TIAL values. OPEN cSelectCursor FOR fnc_cSqlSelect(vSqlWhere, vGroupBy); LOOP FETCH cSelectCursor INTO v; -- You must define a variable 'v' to hold the data of cursor EXIT WHEN cSelectCursor%NOTFOUND; --FETCH cSelectCursor INTO cRec; cTIAL.Kampkod := ''; cTIAL.Abnr := ''; cTIAL.Sign := ''; cTIAL.Alarmdate := ''; cTIAL.Kampkod := i.Kampkod; cTIAL.Abnr := i.Abnr; cTIAL.Sign := i.fordsalj; cTIAL.Alarmdate := i.alarmdate; -- nCount := nCount + 1; -- IF vLopnr = -1 THEN raise_application_error(-20002, 'Error Creating task for: ' || cTIAL.Kampkod || ' ' || cTIAL.Abnr || ' Sales Rep: ' || cTIAL.Alarmdate); END IF; END LOOP; CLOSE cSelectCursor; DBMS_OUTPUT.PUT_LINE('I created ' || nCount || ' records.'); END createFollowUpTask_Exposure; /
Kind regards
-
How to INSERT a SELECT statement with a GROUP BY clause on a table with an IDENTITY column?
n an application, I intend to truncate and insertion on a 12 c Oracle database, but have found this problem with a
IDENTITY
column. Even if theINSERT... SELECT
statement works on mostSELECT
uses I tried, if this statement was also aGROUP BY
clause, it does not work, delivering a "ORA-00979: not aGROUP BY
expression ' complaint. Some examples of code:create table aux ( owner_name varchar2(20), pet varchar2(20) );
insert into aux values ('Scott', 'dog');
insert into aux values ('Mike', 'dog');
insert into aux values ('Mike', 'cat');
insert into aux values ('John', 'turtle');
create table T1 (
id number generated always as identity,
owner_name varchar2(20),
pet_count number );
select owner_name, count(*) as pet_count from aux group by owner_name; -- works just fine
insert into T1 (owner_name, pet_count) select owner_name, count(*) as pet_count from aux group by owner_name; -- doesn't work
The select statement works by itself, but it fails as an INSERT... SELECT statement.
Appreciate the help!
Looks like a bug. You must open the SR with Oracle. Meanwhile, you could materialize select:
SQL > insert into T1 (owner_name, pet_count)
2 with t as (select / * + materialize * / owner_name, count (*) as pet_count to the owner_name group)
3. Select owner_name, pet_count t
4.3 lines were created.
SQL > select * from t1;
ID OWNER_NAME PET_COUNT
---------- -------------------- ----------
1 John 1
Scott 2 1
3 Mike 2SQL >
Keep in mind index THAT MATERIALIZE is undocumented.
SY.
-
How transform the trailing spaces &; AREAS of data from sybase to oracle
Helllo,
We are the migration of data from sybase to Oracle using goldengate... Source Sybase with SPACES (single / Multiple) as data to CHAR/VARCHAR that will be migrated to the VARCHAR2 data type in Oracle. I'm having trouble trying to implement under two conditions to transform the data
1) Remove SPACES during the IPL for CHAR/VARCHAR
example: Data Source: "TRAILING SPACE.
Given target expected - remove the spaces of trailinging: "TRAILING SPACE.
2) If the data with SPACES like a value (single or Multiple) will be loaded as a single SPACE in Oracle.
example : Source data : " "
Expected data from target - unique space:
Map: dbo. Target TEST_TABLE DEV01. Table_test, COLMAP (USEDEFAULTS, CRE_ID = @IF (@STRRTRIM (CRE_ID) = @NULL AND CRE_ID <>@NULL, ' ', @STRRTRIM (CRE_ID)));
I tried above mapping in the settings file, but it returns error like below, guidance on the highest implementation requirement will be useful.
... RIM (CRE_ID) = @NULL AND CRE_ID...
^
Error in the COLMAP clause. Invalid function or argument.
Under column mapping is worked :-)
Map: dbo. Target TEST_TABLE DEV01. TABLE_TEST, COLMAP (USEDEFAULTS, CRE_ID = @IF (@STRLEN (@STRTRIM (CRE_ID)) = 0, ' ', @STRRTRIM (CRE_ID)));
-
Reg - search form for a VO in group by clause
Hello
I have a bar chart that displays data based on the query below.
SELECT THE STATE. BATCH AS STATUSID, STATUS. STATUS, COUNTY (SR. SERVICEREQUEST_ID) AS SRCOUNT
OF SR, SERVICEREQUESTSTATUS STATE SERVICE_REQUEST
WHERE SR. BATCH = STATUS. BATCH
GROUP STATUS. BATCH, STATUS. STATUS, SR. BATCH
It displays the number of SRs against a particular status.
Now, I need to add a search form to this graph with the customer and the date range.
So you need to add the following line to the place where clause.
SR. "CUSTOMER_ID =: customerId AND SR. "BETWEEN REQUESTED_ON: fromDate and: to this day.
But the SR columns. CUSTOMER_ID, SR. REQUESTED_ON also needs to be added to the select clause to create criteria for the search panel view.
The two columns should also be added to the group by clause if you want to add in the select clause.
This would not produce the expected results.
How to create a search with the criteria only form in the where clause. Help, please.
With respect,
Guna[Url http://docs.oracle.com/cd/E16162_01/apirefs.1112/e17483/oracle/jbo/server/ViewObjectImpl.html] ViewObjectImpl has methods to do this programmatically (setQuery, defineNamedWhereClauseParam, setNamedWhereClauseParam) that you can use to manipulate the query variables bind expected and the values of the lie.
John
-
Understanding of the multiple GROUP BY clause column
Hi all
Suppose I have the HR schema example, what is the difference between these two codes?
andselect department_id, job_id, count(*) from employees GROUP BY department_id, job_id ORDER BY 1,2;
I do not see the difference when I run these queries.select department_id, job_id, count(*) from employees GROUP BY job_id,department_id ORDER BY 1,2;
Best regards
ValerieWell, semantically there is no difference: the two queries are equivalent, they return the same result as the value of lines.
The order of columns in a GROUP BY clause is unrelated to the result set of a query. You group by this "group of columns.
And since you order two games using the exact same ORDER BY clause, the order in which Oracle returns the bag of lines is the same too in your case.
-
CFQUERYPARAM tag does not work in the GROUP BY clause
I get an error whenever I put a CFQUERYPARAM tag in a GROUP BY clause. I saw on another forum, someone had a similar problem with the ORDER BY clause
Here's a sample of what might look like my code
Select x, y, z of ABC
Group of < cfqueryparam value = 'x' cfsqltype = "cf_sql_float" >
Here is the error I get.
Run database query error.
[Macromedia] [Oracle JDBC Driver] [Oracle] ORA-00979: not a GROUP BY expression
Any idea?Cachedwithin and cachedafter functions store the query results in the RAM of the server. This means that, even if it is cached, when you run it, you get the cached result instead of going to the database to run again. This increases the speed of course, but if the data is changed during the period of cover, you have accuracy problems.
It creates no memory problems. In the administrator you book a certain amount of memory for the query cache. If you exceed this amount, the last request to shoot the first query on, or something like that.
In regards to what you're trying to do on the binding of variables to your group by clause, this isn't what cfqueryparam has been designed for. It has been designed to
where clauses (where it =
or insert queries (insert in my values in the table (field) ())
and things like that.You try to use it for anything other than what it was designed for, which explains why it does not work for you.
-
A question about the analytical function used with the GROUP BY clause in SHORT
Hi all
I created the following table named myenterprise
If I want to find which is the total sales by city? I'll run the following queryCITY STOREID MONTH_NAME TOTAL_SALES ---------- ---------- ---------- ---------------------- paris id1 January 1000 paris id1 March 7000 paris id1 April 2000 paris id2 November 2000 paris id3 January 5000 london id4 Janaury 3000 london id4 August 6000 london id5 September 500 london id5 November 1000
that works very well and produces the expected result, i.e.SELECT city, SUM(total_sales) AS TOTAL_SALES_PER_CITY FROM myenterprise GROUP BY city ORDER BY city, TOTAL_SALES_PER_CITY;
Now in one of my books SQL (Mastering Oracle SQL) I found another method by using the SUM, but this time as an analytic function. Here's what the method of the book suggests as an alternative to the problem:CITY TOTAL_SALES_PER_CITY ---------- ---------------------- london 10500 paris 17000
I know that the analytic functions are executed after the GROUP BY clause has been transformed completely and Unlike regular aggregate functions, they return their result for each line belonging to the partitions specified in the partition clause (if there is a defined partition clause).SELECT city, SUM(SUM(total_sales)) OVER (PARTITION BY city) AS TOTAL_SALES_PER_CITY FROM myenterprise GROUP BY city ORDER BY city, TOTAL_SALES_PER_CITY;
Now my problem is that I do not understand what we have to use two functions SUM? If we only use one only, i.e.
This generates the following error:SELECT city, SUM(total_sales) OVER (PARTITION BY city) AS TOTAL_SALES_PER_CITY FROM myenterprise GROUP BY city ORDER BY city, TOTAL_SALES_PER_CITY;
The error is generated for the line 2 column 11 which is, for the expression SUM (total_sales), well it's true that total_sales does not appear in the GROUP BY clause, but this should not be a problem, it has been used in an analytical function, so it is evaluated after the GROUP BY clause.Error starting at line 2 in command: SELECT city, SUM(total_sales) OVER (PARTITION BY city) AS TOTAL_SALES_PER_CITY FROM myenterprise GROUP BY city ORDER BY city, TOTAL_SALES_PER_CITY Error at Command Line:2 Column:11 Error report: SQL Error: ORA-00979: not a GROUP BY expression 00979. 00000 - "not a GROUP BY expression" *Cause: *Action:
So here's my question:
Why use SUM (SUM (total_sales)) instead of SUM (total_sales)?
Thanks in advance!
:)
In case you are interested, that's my definition of the table:
Edited by: dariyoosh on April 9, 2009 04:51DROP TABLE myenterprise; CREATE TABLE myenterprise( city VARCHAR2(10), storeid VARCHAR2(10), month_name VARCHAR2(10), total_sales NUMBER); INSERT INTO myenterprise(city, storeid, month_name, total_sales) VALUES ('paris', 'id1', 'January', 1000); INSERT INTO myenterprise(city, storeid, month_name, total_sales) VALUES ('paris', 'id1', 'March', 7000); INSERT INTO myenterprise(city, storeid, month_name, total_sales) VALUES ('paris', 'id1', 'April', 2000); INSERT INTO myenterprise(city, storeid, month_name, total_sales) VALUES ('paris', 'id2', 'November', 2000); INSERT INTO myenterprise(city, storeid, month_name, total_sales) VALUES ('paris', 'id3', 'January', 5000); INSERT INTO myenterprise(city, storeid, month_name, total_sales) VALUES ('london', 'id4', 'Janaury', 3000); INSERT INTO myenterprise(city, storeid, month_name, total_sales) VALUES ('london', 'id4', 'August', 6000); INSERT INTO myenterprise(city, storeid, month_name, total_sales) VALUES ('london', 'id5', 'September', 500); INSERT INTO myenterprise(city, storeid, month_name, total_sales) VALUES ('london', 'id5', 'November', 1000);
It is clear that thet Analytics is reduntant here...
You can even use AVG or any analytic function...SQL> SELECT city, 2 avg(SUM(total_sales)) OVER (PARTITION BY city) AS TOTAL_SALES_PER_CITY 3 FROM myenterprise 4 GROUP BY city 5 ORDER BY city, TOTAL_SALES_PER_CITY; CITY TOTAL_SALES_PER_CITY ---------- -------------------- london 10500 paris 17000
-
Hi all
I'm doing some tests on a Windows 2008 (64-bit) R2 two-node failover Cluster.
I installed and configured successfully bone and the Failover Cluster feature.
So I followed Oracle Doc-ID 1916391.1 to perform the installation and configuration of Oracle 11.2.0.4 database and Oracle Fail Safe 4.1.1
After a successful (via Fail Safe Manager) validation of cluster and group, now I'm trying to validate the stand-alone database, but I'm stuck with this error (output in verbose mode of PowerShell):
PS C:\Users\demo > Test-OracleClusterAvailableDatabase TESTDB - SysPwd (Read-Host-AsSecureString-Prompt "SYS Password ')-verbose
SYS password: *.
DETAILES: FS-10915: NODE1: from verification of autonomous resources TESTDB
DETAILES: FS-10371: NODE1: run the initialization processing
DETAILES: FS-10371: NODE2: run the initialization processing
DETAILES: FS-10372: NODE1: resource owner information collection
DETAILES: FS-10372: NODE2: resource owner information collection
DETAILES: FS-10373: NODE1: determine the owner of the TESTDB resource node
DETAILES: FS-10374: NODE1: collection of cluster information required to perform the specified operation
DETAILES: FS-10374: NODE2: collection of cluster information required to perform the specified operation
DETAILES: FS-10375: NODE1: analysis of the cluster information required to perform the specified operation
DETAILES: FS-10378: NODE1: preparation for the configuration of resource TESTDB
TH: FS-10349: database TESTDB instance is not alive. You want to stop and restart the database instance?
Confirmation
Operation does?
Running dell' operation sulla "Test-OracleClusterAvailableDatabase' likelihood 'TESTDB '.
[S] Sì Sì [T] a [N] no [U] tutti a tutti [O] Sospendi [?] Guida (he valore predefinito e "S"):
DETAILES: FS-10350: from the TESTDB database
Test-OracleClusterAvailableDatabase: OCIEnvNlsCreate failed
Riga: 1 car: 1
+ Test-OracleClusterAvailableDatabase - SysPwd TESTDB (Read-Host - AsSecureString - P...)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo: DeviceError: (TESTDB:ResourceDatabase) [Test-OracleClusterAvailableDatabase], PowerShell
Exception
+ FullyQualifiedErrorId: Process, Oracle.FailSafe.PowerShell.TestOracleClusterAvailableDatabase
Test-OracleClusterAvailableDatabase: FS-10999: an internal programming error
Riga: 1 car: 1
+ Test-OracleClusterAvailableDatabase - SysPwd TESTDB (Read-Host - AsSecureString - P...)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo: DeviceError: (TESTDB:ResourceDatabase) [Test-OracleClusterAvailableDatabase], PowerShell
Exception
+ FullyQualifiedErrorId: Process, Oracle.FailSafe.PowerShell.TestOracleClusterAvailableDatabase
Test-OracleClusterAvailableDatabase: FS-10160: impossible to verify the Oracle of standalone TESTDB database
Riga: 1 car: 1
+ Test-OracleClusterAvailableDatabase - SysPwd TESTDB (Read-Host - AsSecureString - P...)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo: DeviceError: (TESTDB:ResourceDatabase) [Test-OracleClusterAvailableDatabase], PowerShell
Exception
+ FullyQualifiedErrorId: Process, Oracle.FailSafe.PowerShell.TestOracleClusterAvailableDatabase
Test-OracleClusterAvailableDatabase: FS-10818: provider of resources of the database Oracle failed in preparing for
treatment for TESTDB resource configuration
Riga: 1 car: 1
+ Test-OracleClusterAvailableDatabase - SysPwd TESTDB (Read-Host - AsSecureString - P...)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo: DeviceError: (TESTDB:ResourceDatabase) [Test-OracleClusterAvailableDatabase], PowerShell
Exception
+ FullyQualifiedErrorId: Process, Oracle.FailSafe.PowerShell.TestOracleClusterAvailableDatabase
Test-OracleClusterAvailableDatabase: FS-10890: Oracle Services for MSCS failed during the verifyStandalone operation
Riga: 1 car: 1
+ Test-OracleClusterAvailableDatabase - SysPwd TESTDB (Read-Host - AsSecureString - P...)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo: DeviceError: (TESTDB:ResourceDatabase) [Test-OracleClusterAvailableDatabase], PowerShell
Exception
+ FullyQualifiedErrorId: Process, Oracle.FailSafe.PowerShell.TestOracleClusterAvailableDatabase
Attached is the log of the OFS Cluster Dump (no error in my opinion).
I surfed around but I can't find anything to solve the problem.
I think something about the language of the (Italian) OS and Oracle NLS settings (AMERICAN. AMERICA), but obviolsly I'm not sure about this.
Thanks in advance for any suggestion,
Alessandro
Message modificato da 1d457339-524e-4aa5-94aa-fd7d1ae98732 updated: attached is also output trace of the fss.
Hello Alessandro.
Solution to the issue is:
Patch 20744940: 4.1.1.1: ORACLE FAIL SAFE VERSION 4.1.1 PATCH SET 1
-
Hello
You can use group by clause with COUNT function...
In the reports, I have to count the stattus data_set group... If I use COUNT (data_set), it gives me 2 different ranks
1 for the race and the other to succeed.
Please help me...
Thank you
RS
I'm able to do. I used the formula below:
COUNT (CASE WHEN "Status". ("Employment status" = 'Succeed' THEN 1 END)
even for running status and on the other and it works very well...
-
Disable the Tunning &; diagnostic packs in oracle 10g and oracle 9i
Hello
According to the license agreement, our organization asked to disable the packs tuning & diag on Oracle databases.
We use versions diff of databases oracle (oracle 9i, 10g, 11g)
In oracle 11g, we can disable tuning & diag packs using the control_management_pack_access parameter to none.
How to disable the setting & diag packs in Oracle 10 g and oracle 9i?
Thank you
AWR did not exist up to 10g, so I don't think that the diagnosis of EM or Tuning Packs are a problem with 9i. As mentioned statspack is free and available always in 11g, so it is available for use. -Mark-
Maybe you are looking for
-
I want to just use the copy/paste with my mouse.Why you don't get just a gimbal in Firefox?Why should I enter the resume of someone else in my user.js file?It makes even LESS sense. For Firefox: Quit Firefox. If you have Quick Launch running (in Wind
-
My G5 iMac froze and I had to force him to stop. Now when I tried to restart it, it is stuck on the white screen with the logo and the spinning of apple week. I tried to reboot in safe mode, but the volume is all the way down, so I'm only guessing
-
I have a HP Pavilionn (windows 8) and I can't for the life of figure me out how to put bluetooth. Can anyone help?
-
ZIRE 21 hot sync is not compatible with vista 64-bit program
ZIRE 21 hot sync is not compatible with vista 64-bit program - apparently it will work with 32-bit vista. Is there a way to create a 32-bit only for the Zire 21 program without compromising the rest of my 64 bit OS computer? That's what Microsoft se
-
Request a quote for a spare part
Hello, if it is still available, I need a quote for the follow-up of the riser card. Dell Server PowerEdge 1850 PCI - E W1888 0HJ858 PWB Board riser I have it on a server PowerEdge 1850 (serial number 9ZZ5N1J) Thank you Antonio