Query for matrix table
Hello,
Is it possible to make a query thats create a matrix table.
select * from TCOLUMN
ID NAME
== ====
1 A
2 B
select * from TROW
ID NAME
== ====
1 X
2 Y
select * from TMATRIX
TCOLUMN_ID TROW_ID VAL
========== ======== ==
1 1 k
1 2 m
2 1 l
2 2 n
The query have to display:
null X Y
A k m
B l n
Thanks.
Like this?
SQL> column name format a4 heading "null"
SQL> column x format a4 heading "X"
SQL> column y format a4 heading "Y"
SQL> create table tcolumn
2 as
3 select 1 id, 'A' name from dual union all
4 select 2, 'B' from dual
5 /
Tabel is aangemaakt.
SQL> create table trow
2 as
3 select 1 id, 'X' name from dual union all
4 select 2, 'Y' from dual
5 /
Tabel is aangemaakt.
SQL> create table tmatrix
2 as
3 select 1 tcolumn_id, 1 trow_id, 'k' val from dual union all
4 select 1, 2, 'm' from dual union all
5 select 2, 1, 'l' from dual union all
6 select 2, 2, 'n' from dual
7 /
Tabel is aangemaakt.
SQL> select c.name
2 , max(decode(r.name,'X',m.val)) x
3 , max(decode(r.name,'Y',m.val)) y
4 from tmatrix m
5 , tcolumn c
6 , trow r
7 where m.tcolumn_id = c.id
8 and m.trow_id = r.id
9 group by c.name
10 /
null X Y
A k m
B l n
2 rijen zijn geselecteerd.Groet,
Rob.
Similar Messages
-
Hi,
I have this problem, How can query a two table?
Table A -> Table B
id table-a_id
name table_b_name
the relationship is one-to-many
How can I get the result?
Hope my question make sense
cheers.
thanks a lot.I bet you have more luck looking for an answer in a SQL forum.
-
Tuning SQL Query for base tables
Hi,
Can any please help me to tune the below query...... there is full table scan for po_action_history table
SELECT DISTINCT
DECODE(hr.full_name,'Default Buyer, Purchasing','PCH',
'Default Buyer, Travel','TRV',
'Purchase Order, Rapid','RPO',
'Data Interchange, Electronic','EDI',fuser1.user_name) BUYER_ID,
poa.attribute1 BUYER_GROUP,
poa.attribute2 BUYER_SUBGROUP
FROM po.po_action_history ac1,
po.po_headers_all ph,
po.po_agents poa,
hr.per_all_people_f hr,
applsys.fnd_user fuser1
WHERE ph.po_header_id = ac1.object_id
AND ac1.object_type_code = 'PO'
AND ac1.action_code = 'APPROVE'
AND sequence_num =(SELECT MIN(ac2.sequence_num)
FROM po.po_action_history ac2,
applsys.fnd_user fuser2
WHERE ph.po_header_id = ac2.object_id
AND ac2.object_type_code = 'PO'
AND ac2.action_code = 'APPROVE'
AND ac2.last_updated_by = fuser2.user_id)
--AND ac1.last_updated_by = fuser1.user_id
AND ph.agent_id = poa.agent_id
AND ph.agent_id = hr.person_id
AND hr.person_id = fuser1.employee_id
AND hr.effective_end_date > sysdate
AND trunc(ac1.last_update_date) between '01-JAN-08' and '07-JAN-08'
ORDER BY poa.attribute1
Explain Plan
PLAN_TABLE_OUTPUT
Plan hash value: 3325319312
Id Operation Name Rows
Bytes Cost (%CPU) Time
PLAN_TABLE_OUTPUT
| 0 | SELECT STATEMENT | | 27 |
2754 | 38963 (3) | 00:07:48 |
| 1 | SORT UNIQUE | | 27 |
2754 | 38962 (3) | 00:07:48 |
|* 2 | FILTER | | |
| | |
|* 3 | HASH JOIN | | 37 |
3774 | 36308 (3) | 00:07:16 |
PLAN_TABLE_OUTPUT
| 4 | TABLE ACCESS BY INDEX ROWID | FND_USER | 1 |
13 | 2 (0) | 00:00:01 |
| 5 | NESTED LOOPS | | 37 |
3293 | 36303 (3) | 00:07:16 |
| 6 | NESTED LOOPS | | 88 |
6688 | 36180 (3) | 00:07:15 |
| 7 | NESTED LOOPS | | 88 |
PLAN_TABLE_OUTPUT
3960 | 35916 (3) | 00:07:11 |
|* 8 | TABLE ACCESS FULL | PO_ACTION_HISTORY | 2110 |
71740 | 32478 (3) | 00:06:30 |
| 9 | TABLE ACCESS BY INDEX ROWID | PO_HEADERS_ALL | 1 |
11 | 2 (0) | 00:00:01 |
|* 10 | INDEX UNIQUE SCAN | PO_HEADERS_U1 | 1 |
| 1 (0) | 00:00:01 |
PLAN_TABLE_OUTPUT
| 11 | SORT AGGREGATE | | 1 |
36 | | |
| 12 | NESTED LOOPS | | 1 |
36 | 6 (0) | 00:00:01 |
|* 13 | TABLE ACCESS BY INDEX ROWID| PO_ACTION_HISTORY | 1 |
31 | 6 (0) | 00:00:01 |
|* 14 | INDEX RANGE SCAN | PO_ACTION_HISTORY_N1 | 5 |
| 3 (0) | 00:00:01 |
PLAN_TABLE_OUTPUT
|* 15 | INDEX UNIQUE SCAN | FND_USER_U1 | 1 |
5 | 0 (0) | 00:00:01 |
| 16 | TABLE ACCESS BY INDEX ROWID | PER_ALL_PEOPLE_F | 1 |
31 | 3 (0) | 00:00:01 |
|* 17 | INDEX RANGE SCAN | PER_PEOPLE_F_PK | 1 |
| 2 (0) | 00:00:01 |
|* 18 | INDEX RANGE SCAN | FND_USER_N1 | 1 |
PLAN_TABLE_OUTPUT
| 1 (0) | 00:00:01 |
| 19 | TABLE ACCESS FULL | PO_AGENTS | 183 |
2379 | 4 (0) | 00:00:01 |
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
2 - filter(TO_DATE('01-JAN-08')<=TO_DATE('07-JAN-08'))
3 - access("PH"."AGENT_ID"="POA"."AGENT_ID")
8 - filter("AC1"."ACTION_CODE"='APPROVE' AND "AC1"."OBJECT_TYPE_CODE"='PO'AND
TRUNC(INTERNAL_FUNCTION("AC1"."LAST_UPDATE_DATE"))>='01-JAN-08' AND
TRUNC(INTERNAL_FUNCTION("AC1"."LAST_UPDATE_DATE"))<='07-JAN-08')
10 - access("PH"."PO_HEADER_ID"="AC1"."OBJECT_ID")
PLAN_TABLE_OUTPUT
filter("SEQUENCE_NUM"= (SELECT MIN("AC2"."SEQUENCE_NUM") FROM "APPLSYS"."FND_USER"
"FUSER2","PO"."PO_ACTION_HISTORY" "AC2" WHERE "AC2"."OBJECT_ID"=:B1 AND "AC2"."ACTION_CODE"='APPROVE'
AND "AC2"."OBJECT_TYPE_CODE"='PO' AND "AC2"."LAST_UPDATED_BY"="FUSER2"."USER_ID"))
13 - filter("AC2"."ACTION_CODE"='APPROVE' AND "AC2"."OBJECT_TYPE_CODE"='PO')
14 - access("AC2"."OBJECT_ID"=:B1)
PLAN_TABLE_OUTPUT
15 - access("AC2"."LAST_UPDATED_BY"="FUSER2"."USER_ID")
17 - access("PH"."AGENT_ID"="PERSON_ID" AND "EFFECTIVE_END_DATE">SYSDATE@!)
filter("EFFECTIVE_END_DATE">SYSDATE@!)
18 - access("PERSON_ID"="FUSER1"."EMPLOYEE_ID")
ThanksHi,
any help for the above issue. -
Hi i have got this query that is a join of two tables but i need join for three tables i need the extended query
select aauthlname aauthlnam aauthfname aauthfnam aisbn btitle
from ( bsauthors as a inner join bsbook as b on aisbn = bisbn )
into corresponding fields of table books
where aauthlname like authorlname or aauthfname like authorfname
order by aauthlname aauthfname a~isbn.Hi pavan
Plz try the following querry for joins on three tables :
" Customize it to ur requirements and tablenames
Parameters : b type mara-matnr.
select xmatnr xmtart xmatkl ywerks ylgort zmaktx
into corresponding fields of table itab
from ( ( mara as x inner join mard as y on xmatnr = ymatnr )
inner join makt as z on xmatnr = zmatnr ) where x~matnr = a and
y~werks
= b .
Plz see that there is atleast one field common between the three tables u want to use.
Regards
Pankaj -
Need a query for export table data .....
Hi,
I need a query for exporting the data in a table to a file.
Can anyone help me ?
Thanking You
JeneeshSQL> spool dept.txt
SQL> select * from dept;
DEPTNO DNAME LOC
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SQL> spool off
SQL> ed dept.txt -
How to use dynamic query for Result table
Hello Experts,
I want to use dynamic query and then display the result in the assignment block.
Using dynamic query BTQAct and BTQRAct and base on some search criteria i want tofilter and then append the result in the result table of that custom context node, and then it should display the result in the view in UI.
SO can you please provide me the samplle code on how to use the dynamic query and append in the result table.
Regards.Hi,
Please find below sample code:
data: query TYPE REF TO cl_crm_bol_dquery_service,
result TYPE REF TO if_bol_bo_col.
DATA: lt_params TYPE crmt_name_value_pair_tab,
lwa_params TYPE crmt_name_value_pair.
query = cl_crm_bol_dquery_service=>get_instance( 'BTQAct' ). " Get instance of dynamic query
Set general query parameter for maximum number of hits
lwa_params-name = 'MAX_HITS' .
lwa_params-value = '50'.
APPEND lwa_params TO lt_params.
query->set_query_parameters( it_parameters = lt_params ).
query->add_selection_param( iv_attr_name = 'OBJECT_ID'
iv_sign = 'I'
iv_option = 'EQ'
iv_low = <lv_objectid>
iv_high = '' ). " Set your search criteria. Repeat this code if you have multiple parameters
"You can find possible search options for a query object in GENIL_BOL_BROWSER
result ?= query->get_query_result( ). " Get result from your search query
me->typed_context-> <your result context node>->set_collection( result ).
Here you will have to create a context node in your view which would refer to query result object like for BTQAct its BTQRAct
Hope this helps.
e Regards,
Bhushan -
Hi,
I need to write a SELECT statement that returns one row for each customer that has orders with the following columns:
======================================================================
Email addresses from Customers Table
Sum of the Item Price in the OrdersItems table multiplied by the quantity in the
OrderItems table
Sum of the discount amount column in the OrderItems table multiplied by the quantity in the OrderItems Table.
Sort the results set in the descending sequence by the item price total for each customer.
===================================================================
Customers table has no connection with Orderitems table, so it has to go through ORDERS table. I have written the following query. Can someone check and give me a feed back? It is not giving me the correct output. This should be the output:
Email address
ItemPriceTotal DiscountAmountTotal
[email protected] 4131.00
1830.30
etc, etc........
My code is not adding the above columns correctly. I have tried SUM for Total columns but gives me errors:
SELECT EmailAddress, ItemPrice * Quantity AS ItemPriceTotal, DiscountAmount * Quantity AS DiscountAmountTotal
FROM
Customers
JOIN ORDERS
ON CUSTOMERS.CustomerID = Orders.CustomerID ----Joins Orders with Customers
JOIN OrderItems
ON Orders.OrderID = OrderItems.OrderID; ------ Joins Orders with OrderItems
----ORDER BY EmailAddress,ItemPriceTotal; ( tried Order by, but output is not correct)Thank you for your help. I really appreciate it. My output should look like this, but my query is not adding the ItemPriceTotal and DiscountAmountTotal:
Results:
EmailAddress
ItemPriceTotal
DiscountAmountTotal
[email protected]
4131.00
1830.39
[email protected]
2398.00
719.40
[email protected]
2198.98
659.70
[email protected]
998.00
209.70
[email protected]
799.99
120.00
[email protected]
489.99
186.20
[email protected]
299.00
0.00 -
Oracle ADF - Refresh quick query for a table in the pop up.
Hi,
I am using Oracle jDev 11.1.1.4.0
In my application I have a Find button in jspx.
Onclick of Find button, a popup opens.
When I search for a record by name in QuickQuery, suppose - I entered name as jon.
It gives me the correct result.
Now when I close the pop up and again click on Find button, that previous search remains as it is in the pop up
and also the previous criteria in quick query search region as "jon".
I have changed the refresh property of iterator(of table in popup) in pageDef
But still not working...
How to refresh that search region for every subsequent Find click.
Appreciate your help.
Thanks,
Madhavdo u changed refresh > ifneeded or always.
user.
r u luking for partially page rendering.
by using ppr. we can refresh.
if so.
http://www.adftips.com/2010/10/adf-ui-refreshing-page-or-region.html
http://biemond.blogspot.com/2007/11/how-to-refresh-region-in-jdeveloper-11g.html
Re: ADF Region Interaction
Edited by: Erp on Sep 27, 2011 4:37 AM
Edited by: Erp on Sep 27, 2011 4:42 AM -
HI experts, Im about to create a Sap query using SQVI tcode. I want to have listing of certain master data created in customizing(SPRO) like the catalogs and list of code groups and task codes in Service Notification. What is the best data source or the table should I use to capture this data? Or is this possible? If not, can you give me some ways how to have listing report for those information.
Hi,
Have you checked with t-code QS42 ?
Tables - QPGR, TQ15.
Regards,
Vivek -
Query for Empty Tables.
Hi All,
Can someone tell me a Query to find out "EMPTY TABLES i.e. Tables having no Rows" in Oracle 8i ?
I tried on Google, but results are not satisfactory, may be due to 8i version.
Please guide me.
Regards.982164 wrote:
Hi Hoek,
Actually we upgraded our database to 11g.
We imported our data from 8i to 11gr2 by the utility IMP successfully.
It imported our data 100% i.e. when we import 8i dmp data into 11g, there is never problem.
Problem is arises now when we further use IMP/EXP utility in 11g.So everything in Oracle 8 is working the way you expect. The fact that you also have an Oracle 8 database has nothing to do with this problem. Is that what you're saying?
When we run EXP utlity in 11g, it doesn't export empty tables.If the problem is entirely in Oracle 11, then you should be able to use something like XMLQUERY to find the 0-row tables, if you really need to. (I think you don't.)
EXP can export tables with 0 rows. I just tried it in Oracle 11, and part of the feedback I got was:
. . exporting table ZIPCODES 0 rows exported
. . exporting table ZONEORDER_TBL 5 rows exported
. . exporting table ZONE_TBL 6 rows exported
. . exporting table ZOO 2 rows exported
. . exporting table Z_HIERARCHY 3 rows exported
. . exporting table Z_TEST 3 rows exported
. . exporting table Z_TEST4 0 rows exportedIf it's not exporting 0-row tables for you, find out why, and fix that problem. Post your exp control file.
Someone told me to insert atleast 1 row in the empty tables, then they will be exported.And then, after importing them, TRUNCATE those tables? That's a lot of work.
That's why I m searching of the Empty Tables.
Am I going right way ?I don't think so.
Find and fix the problem with exp.
If you can't get exp to work, then look into data pump. -
Update Query For Hierarchy Table
Hi All
I have a Hierarchy table that has news categories. I want use a query than when user deactivate a category, all child category has been deactivated. For example
1- Politics
1-1- National Politics
1-2- International Politics
1-2-1- Asia
1-2-2- Africa
2- Economic
If Politics has been deactivated, all child must be deactivate. (1-1, 1-2, 1-2-1, 1-2-2)
Please help me
With Best RegardsThis is table structure script:
SET NUMERIC_ROUNDABORT OFF
GO
SET ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, ARITHABORT, QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE id=OBJECT_ID('tempdb..#tmpErrors')) DROP TABLE #tmpErrors
GO
CREATE TABLE #tmpErrors (Error int)
GO
SET XACT_ABORT ON
GO
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
GO
BEGIN TRANSACTION
GO
PRINT N'Creating schemata'
GO
PRINT N'Creating [dbo].[Modules]'
GO
CREATE TABLE [dbo].[Modules]
[Module_ID] [int] NOT NULL,
[ModuleName] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ModuleTitle] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Status] [int] NULL
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating primary key [PK_Modules] on [dbo].[Modules]'
GO
ALTER TABLE [dbo].[Modules] ADD CONSTRAINT [PK_Modules] PRIMARY KEY CLUSTERED ([Module_ID])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating [dbo].[Categories]'
GO
CREATE TABLE [dbo].[Categories]
[Category_ID] [int] NOT NULL IDENTITY(1, 1),
[Module_ID] [int] NOT NULL,
[ParentID] [int] NULL,
[Name] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Title] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Priority] [int] NULL,
[ThumbnailImage] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Status] [int] NULL
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating primary key [PK_Categories] on [dbo].[Categories]'
GO
ALTER TABLE [dbo].[Categories] ADD CONSTRAINT [PK_Categories] PRIMARY KEY CLUSTERED ([Category_ID])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Adding foreign keys to [dbo].[Categories]'
GO
ALTER TABLE [dbo].[Categories] ADD CONSTRAINT [FK_Categories_Modules] FOREIGN KEY ([Module_ID]) REFERENCES [dbo].[Modules] ([Module_ID])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
IF EXISTS (SELECT * FROM #tmpErrors) ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT>0 BEGIN
PRINT 'The database update succeeded'
COMMIT TRANSACTION
END
ELSE PRINT 'The database update failed'
GO
DROP TABLE #tmpErrors
GO
This is table data
SET NUMERIC_ROUNDABORT OFF
GO
SET ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, ARITHABORT, QUOTED_IDENTIFIER, ANSI_NULLS, NOCOUNT ON
GO
SET DATEFORMAT YMD
GO
SET XACT_ABORT ON
GO
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
GO
BEGIN TRANSACTION
-- Pointer used for text / image updates. This might not be needed, but is declared here just in case
DECLARE @pv binary(16)
PRINT(N'Drop constraints from [dbo].[Categories]')
GO
ALTER TABLE [dbo].[Categories] DROP CONSTRAINT [FK_Categories_Modules]
PRINT(N'Add 14 rows to [dbo].[Categories]')
GO
SET IDENTITY_INSERT [dbo].[Categories] ON
INSERT INTO [dbo].[Categories] ([Category_ID], [Module_ID], [ParentID], [Name], [Title], [Priority], [ThumbnailImage], [Status]) VALUES (1, 1, NULL, 'News', N'اخبار', 1, NULL, 1)
INSERT INTO [dbo].[Categories] ([Category_ID], [Module_ID], [ParentID], [Name], [Title], [Priority], [ThumbnailImage], [Status]) VALUES (2, 2, NULL, 'Article', N'مقالات', 2, NULL, 1)
INSERT INTO [dbo].[Categories] ([Category_ID], [Module_ID], [ParentID], [Name], [Title], [Priority], [ThumbnailImage], [Status]) VALUES (3, 3, NULL, 'Galleries', N'گالری', 3, NULL, 1)
INSERT INTO [dbo].[Categories] ([Category_ID], [Module_ID], [ParentID], [Name], [Title], [Priority], [ThumbnailImage], [Status]) VALUES (4, 1, 1, 'Politics', N'سیاسی', 1, NULL, 1)
INSERT INTO [dbo].[Categories] ([Category_ID], [Module_ID], [ParentID], [Name], [Title], [Priority], [ThumbnailImage], [Status]) VALUES (5, 1, 1, 'Economic', N'اقتصادی', 2, '', 1)
INSERT INTO [dbo].[Categories] ([Category_ID], [Module_ID], [ParentID], [Name], [Title], [Priority], [ThumbnailImage], [Status]) VALUES (6, 1, 4, 'NationalPilitics', N'سیاست داخلی', 1, '', 1)
INSERT INTO [dbo].[Categories] ([Category_ID], [Module_ID], [ParentID], [Name], [Title], [Priority], [ThumbnailImage], [Status]) VALUES (7, 1, 4, 'InternationalPolitics', N'سیاست خارجی', 2, NULL, 1)
INSERT INTO [dbo].[Categories] ([Category_ID], [Module_ID], [ParentID], [Name], [Title], [Priority], [ThumbnailImage], [Status]) VALUES (8, 1, 7, 'Asia', N'آسیا', 1, '', 1)
INSERT INTO [dbo].[Categories] ([Category_ID], [Module_ID], [ParentID], [Name], [Title], [Priority], [ThumbnailImage], [Status]) VALUES (9, 1, 7, 'Europe', N'اروپا', 2, NULL, 1)
INSERT INTO [dbo].[Categories] ([Category_ID], [Module_ID], [ParentID], [Name], [Title], [Priority], [ThumbnailImage], [Status]) VALUES (10, 1, 7, 'Africa', N'آفریقا', 3, NULL, 1)
INSERT INTO [dbo].[Categories] ([Category_ID], [Module_ID], [ParentID], [Name], [Title], [Priority], [ThumbnailImage], [Status]) VALUES (11, 2, 2, 'Scientic', N'علمی', 1, NULL, 1)
INSERT INTO [dbo].[Categories] ([Category_ID], [Module_ID], [ParentID], [Name], [Title], [Priority], [ThumbnailImage], [Status]) VALUES (12, 2, 2, 'Art', N'هنری', 2, NULL, 1)
INSERT INTO [dbo].[Categories] ([Category_ID], [Module_ID], [ParentID], [Name], [Title], [Priority], [ThumbnailImage], [Status]) VALUES (13, 3, 3, 'Culture', N'فرهنگی', 1, NULL, 1)
INSERT INTO [dbo].[Categories] ([Category_ID], [Module_ID], [ParentID], [Name], [Title], [Priority], [ThumbnailImage], [Status]) VALUES (14, 3, 3, 'Religion', N'مذهبی', 2, NULL, 1)
SET IDENTITY_INSERT [dbo].[Categories] OFF
PRINT(N'Add constraints to [dbo].[Categories]')
GO
ALTER TABLE [dbo].[Categories] ADD CONSTRAINT [FK_Categories_Modules] FOREIGN KEY ([Module_ID]) REFERENCES [dbo].[Modules] ([Module_ID])
COMMIT TRANSACTION
GO
Thanks for your help -
Update query for Advanced table.
Hi,
I am an newbie to OAF so need help for a simple task.
I have an advanced table that has been created using expert mode query of VO. (as it contains data from more than one table).
Now, i want to update the data for any row that is changed in the table,
i followed the advanced table example in the tutorial and reached till the update method of AM. Now I am not able to update the table. When I searched the forum it said that I need to have a simple EO on the table to update it, but I want to update more than one table ( foreign key relationship), so can I do it using the same VO ? I have both the VO (one based on custom select query of Expert mode and other normal VO based on EO).
Can someone please give me the query to update the table ?
Thanks,
VKThanks Reetesh for your reply.
As this is a simple task I wan't to do it via OAF query rather than writing PL/SQL procedure.
I have two tables , say error table and interface table, (there is a foreign key relation ship between these tables, ie. i have to show the interface name present in the interface table via the foreign key in the error table). I used the following query to get the data
SELECT xxgblErrorMasterEO1.ERROR_ID_NO,
xxgblErrorMasterEO1.ERROR_CODE,
xxgblErrorMasterEO1.ERROR_MESSAGE,
xxgblErrorMasterEO1.CREATED_BY,
xxgblErrorMasterEO1.CREATION_DATE,
xxgblErrorMasterEO1.LAST_UPDATED_BY,
xxgblErrorMasterEO1.LAST_UPDATE_DATE,
xxgblIntfProgramMaster.INTERFACE_NAME,
xxgblErrorMasterEO1.ERROR_TYPE
FROM XXEEG.XXGBL_ERROR_MASTER xxgblErrorMasterEO1,
XXEEG.XXGBL_INTF_PROGRAM_MASTER xxgblIntfProgramMaster
where xxgblErrorMasterEO1.INTERFACE_ID_NO =
xxgblIntfProgramMaster.INTERFACE_ID_NO
I like the idea of Advanced table while going through the tutorial (example 2) and would want to show certain fields by expanding on the + mark ( just like in the explorer)
now i want to update any of the fields that i show to the user (except the WHO fields). Say for example if the user updates the error_message and Interface_name, so how should i write the update method in the AM ?
Pardon me if this sounds simple :( -
Design
Table Name Field Name Data Type Allow Null Reference
Employee
ID Int No
Name Varchar(20) No
ID_Department Int No Department.ID
ID_Manager Int Yes Employee.ID
Salary Int No
Bonus Numeric(6,2) Yes
Department
ID Int No
Name Varchar(20) No
Awards
ID_Employee Int No Employee.ID
ID_Manager Int No Employee.ID
NoOfAwards TinyInt No
Data
Employee
ID Name ID_Department ID_Manager Salary Bonus
1 Mohan 3 NULL 25000 0
2 Chintan 3 1 15000 0
3 Ajay 2 2 10000 0
4 Vipul 2 3 7500 0
5 Rohini 1 2 5000 0
Department
ID Name
1 Computer
2 Account
3 Sales
4 HR
Awards
ID_Employee ID_Manager NoOfAwards
2 1 4
3 2 5
5 3 2
4 3 2
3 1 3
Note:
1 Manager of any employee is also an employee of a company.
2 Employee with ID_Manager = NULL is a BOSS/OWNER. (e.g. Mohan)
3 "[Awards] table represents No.of Awards won by an employee with combination of other employee as a manager which could be other than his actual manager also.
e.g. Rohini(as an employee) has won 2 awards while working with Ajay(as a Manager)
e.g. Mohan as an employee can not win award with other employee as a Manager but he can win award as a Manager with other employee"
1 "Update the bonus of all employees => (total salary of all employees of that employee's department) x (Number of employees under that employee)%
Note: Employee who is not a Manager should get 0.5% of total salary of all employees of his department"
"e.g. Chintan should get (total of his Department)*(Chintan is manager of 2 employees)% => 40000*2% = 800.
e.g. Rohini is not a manager of any employee so he should get (total of his Department)*0.5% => 5000 * 0.5% = 25"
2 List out all employee names and Total Number of Awards won as an Employee and Total Number of Awards won as a Manager.Hi,
in any case assuming that you have the following structure under Oracle:
CREATE TABLE department
id INT NOT NULL
, name VARCHAR (50) NOT NULL
, CONSTRAINT pk_department PRIMARY KEY (id)
CREATE TABLE employee
id INT NOT NULL
, name VARCHAR (50) NOT NULL
, id_department INT NOT NULL
, id_manager INT NULL
, salary INT NOT NULL
, bonus NUMERIC (6, 2) NOT NULL
, CONSTRAINT pk_employee PRIMARY KEY (id)
, CONSTRAINT fk_departmentno FOREIGN KEY
(id_department)
REFERENCES department (id)
CREATE TABLE awards
id_employee INT NOT NULL
, id_manager INT NOT NULL
, noofawards INT NOT NULL
);To get the bonus as you want calculated you can do:
MERGE INTO employee emp
USING (SELECT id
, salary
, (SELECT COUNT (*)
FROM employee
WHERE id_manager = e.id) cnt
, (SELECT SUM (salary)
FROM employee
WHERE id_department = e.id_department) dept_tot_sal
FROM employee e) src
ON (emp.id = src.id)
WHEN MATCHED
THEN
UPDATE SET bonus = src.dept_tot_sal * DECODE (cnt, 0, 0.5, cnt) / 100;
SELECT * FROM employee;
ID NAME ID_DEPARTMENT ID_MANAGER SALARY BONUS
1 Mohan 3 25000 400
2 Chintan 3 1 15000 800
3 Ajay 2 2 10000 175
4 Vipul 2 3 7500 87.5
5 Rohini 1 2 5000 25However I see a contradiction in your calculation. Mohan is getting a lower bonus than Chintan if we are considering only employees under him at first level. If you want to consider all employees under him (considering the whole hierarchy) then you could modify the part which is calculating the count of employees in this way:
, ( SELECT COUNT (*)
FROM employee
START WITH id_manager = e.id
CONNECT BY PRIOR id = id_manager) cntFor what is regarding question number 2 here the query you could use:
SELECT e.id, e.name, NVL (SUM (awe.noofawards), 0) awards_as_employee
, NVL (SUM (awm.noofawards), 0) awards_as_manager
FROM employee e
LEFT OUTER JOIN awards awe
ON (e.id = awe.id_employee)
LEFT OUTER JOIN awards awm
ON (e.id = awm.id_manager)
GROUP BY e.id, e.name;
ID NAME AWARDS_AS_EMPLOYEE AWARDS_AS_MANAGER
2 Chintan 4 5
4 Vipul 2 0
5 Rohini 2 0
3 Ajay 16 8
1 Mohan 0 7As you haven't posted the expected result for this second query I don't know if you want to consider only one level as manager or walk through the whole tree.
Regards.
Al -
Need a query for access tables
Hi
I need a query , help please:
table1:
id description serial
1 des1 ser1
2 des2 ser2
3 des3 ser3
table2:
id id1(id of table1) date
stat
1 1
2001 A
2 1
2008 N
3 2
2010 A
4 1
2012 F
==============
i need this data structure: (stat column must return for maximum date of id1 from table2)
id(from table1) serial(from table1) stat(from table2)
1 ser1
2012
2 ser2
2010
3 ser3
Nullmaybe you can try this.
declare @t1 table
(id int,[description] varchar(50),serial varchar(10))
declare @t2 table
(id int,id1 int,[date] char(4),stat char(10))
insert into @t1 values
(1,'des1','ser1'),
(2,'des2','ser2'),
(3,'des3','ser3')
insert into @t2 values
(1,1,'2001','A'),
(2,1,'2008','N'),
(3,2,'2010','A'),
(4,1,'2012','F')
select a.id,a.serial,max(b.date)
from @t1 a
left join @t2 b
on a.id = b.id1
group by a.id,a.serial
| SQL PASS Taiwan Page |
SQL PASS Taiwan Group
|
My Blog -
Hi All,
I have table column defined as user defined data type. That User defined data type contains many columns.
My requirement is i want to update one particular column of that User defined data type column.
How should i update.
Pls help me.
I am using Oracle 10g.
I have listed below one table and its associated columns.
PERSON_ID VARCHAR2(20)
PHIN_NO VARCHAR2(20)
SSN_NO VARCHAR2(20)
PERSON_NAME XPN
That XPN data type consists of
FAMILY_NAME FN
GIVEN_NAME VARCHAR2(30)
MIDDLE_NAME VARCHAR2(30)
SUFFIX VARCHAR2(20)
PREFIX VARCHAR2(20)
DEGREE VARCHAR2(6)
For example If i want to update prefix column value. how should i do?
Cheers
Moorthy.GSHi,
In My XPN Object type contains
Structure:-(FAMILY_NAME(FN),GIVEN_NAME,MIDDLE_NAME,SUFFIX,PREFIX,
DEGREE,NAME_TYPE_CODE,NAME_REPRESENTATION_CODE,
NAME_VALIDITY_START_DATE,NAME_VALIDITY_END_DATE,
NAME_ASSEMBLY_ORDER,EFFECT_DATE,EXPIRATION_DATE,
PROFESSIONAL_SUFFIX,NAME_CONTEXT)
Sample Values:- XPN(FN('BALU','','','',''), 'NAVEEN','G','', 'DOM000327','','','','12-JUL-06 11.57.57.854000 AM','12-JUL-06 11.57.57.854000 AM','','12-JUL-06 11.57.57.854000 AM', '12-JUL-06 11.57.57.854000 AM','','')
I want to update the value for Prefix compent, then how should?
Pls help me
Cheers
Moorthy.GS
Maybe you are looking for
-
Syndication Search Using Remote System
Is there a way to use the Key Mapping's remote system as part of the search criteria for syndication? I am not referring to the map property that allows you to suppress records that do not have a remote key. For example, only send records when "remot
-
Can I new a script in SQL Developer?
I select "new", but the SQL File is grey. My version is 1.0.14.67, OS is Windowxp Thx
-
Node addElement or ChangeElement....
Hello , I have a senario that user enters some values and later if he wishes he can change the values he entred last time.... So right now I have doing something like: wdContext.nodeAddress_Tmp().addElement(wdContext.currentContextElement().getRowNr(
-
Dear sir, i finished loading process of raster into oracle database and trying to retrieve image in mapviwer. but nothing comes out even no any error message. would you please let me know what could be the reason following is my parametes in mapviewe
-
Having problems with elementAt()
I am relatively new to java and I am creating this program as an exercise. I have a problem with my elementAt() method and I cannot figure out what is wrong. I want to call the second element in my vector and convert it to an integer from a string. I