Pivot a Table Records
Dear All,
Here is my Thread..
I have a one table [ABC] with Column Name [YEAR_MONTH], [RECORD_ID],[SALE],[MANAGER]
The Distinct [MANAGER]s are - [AAA],[BBB],[CCC] & [DDD]
I want to pivot a report from TABLE in this way..
Please help..
In T-SQL it can be done as follows
SELECT YEAR_MONTH,
COUNT(CASE WHEN MANAGER = 'AAA' THEN RECORD_ID END) AS [MANAGER1COUNT],
SUM(CASE WHEN MANAGER = 'AAA' THEN SALE END) AS [MANAGER1SUM],
COUNT(CASE WHEN MANAGER = 'BBB' THEN RECORD_ID END) AS [MANAGER2COUNT],
COUNT(CASE WHEN MANAGER = 'BBB' THEN SALE END) AS [MANAGER2SUM],
COUNT(CASE WHEN MANAGER = 'CCC' THEN RECORD_ID END) AS [MANAGER3COUNT],
SUM(CASE WHEN MANAGER = 'CCC' THEN SALE END) AS [MANAGER3SUM],
COUNT(CASE WHEN MANAGER = 'DDD' THEN RECORD_ID END) AS [MANAGER4COUNT],
SUM(CASE WHEN MANAGER = 'DDD' THEN SALE END) AS [MANAGER4SUM]
FROM Table
GROUP BY YEAR_MONTH
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page
Similar Messages
-
Default Max rows for pivot and table view that can display
Hi Experts,
what was the Maximum number of pivot table records,Maximum number of pivot table populated cells,Maximum number of table view rows by default in OBIEE.
If i want to see where i can found all these things in OBIEE.
If i want to change the default range of these rows is there any maximum limit for setting manually also or we can set any number of records.(i.e. if i want to display 100000 records will accept or there will be any range for setting also)
Thanks,
Edited by: RAJ.bi on Aug 5, 2012 8:12 AMCheck the below link for the same
http://docs.oracle.com/cd/E25178_01/bi.1111/e10541/answersconfigset.htm
If you are going with 100K records per view, I think there is a limit for downloading into spread sheet.
Pls mark correct or helpful -
How can I convert table object into table record format?
I need to write a store procedure to convert table object into table record. The stored procedure will have a table object IN and then pass the data into another stored procedure with a table record IN. Data passed in may contain more than one record in the table object. Is there any example I can take a look? Thanks.
I'm afraid it's a bit labourious but here's an example.
I think it's a good idea to work with SQL objects rather than PL/SQL nested tables.
SQL> CREATE OR REPLACE TYPE emp_t AS OBJECT
2 (eno NUMBER(4)
3 , ename VARCHAR2(10)
4 , job VARCHAR2(9)
5 , mgr NUMBER(4)
6 , hiredate DATE
7 , sal NUMBER(7,2)
8 , comm NUMBER(7,2)
9 , deptno NUMBER(2));
10 /
Type created.
SQL> CREATE OR REPLACE TYPE staff_nt AS TABLE OF emp_t
2 /
Type created.
SQL> Now we've got some Types let's use them. I've only implemented this as one public procedure but you can see the principles in action.
SQL> CREATE OR REPLACE PACKAGE emp_utils AS
2 TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE;
3 PROCEDURE pop_emp (p_emps in staff_nt);
4 END emp_utils;
5 /
Package created.
SQL> CREATE OR REPLACE PACKAGE BODY emp_utils AS
2 FUNCTION emp_obj_to_rows (p_emps IN staff_nt) RETURN EmpCurTyp IS
3 rc EmpCurTyp;
4 BEGIN
5 OPEN rc FOR SELECT * FROM TABLE( CAST ( p_emps AS staff_nt ));
6 RETURN rc;
7 END emp_obj_to_rows;
8 PROCEDURE pop_emp (p_emps in staff_nt) is
9 e_rec emp%ROWTYPE;
10 l_emps EmpCurTyp;
11 BEGIN
12 l_emps := emp_obj_to_rows(p_emps);
13 FETCH l_emps INTO e_rec;
14 LOOP
15 EXIT WHEN l_emps%NOTFOUND;
16 INSERT INTO emp VALUES e_rec;
17 FETCH l_emps INTO e_rec;
18 END LOOP;
19 CLOSE l_emps;
20 END pop_emp;
21 END;
22 /
Package body created.
SQL>Looks good. Let's see it in action...
SQL> DECLARE
2 newbies staff_nt := staff_nt();
3 BEGIN
4 newbies.extend(2);
5 newbies(1) := emp_t(7777, 'APC', 'CODER', 7902, sysdate, 1700, null, 40);
6 newbies(2) := emp_t(7778, 'J RANDOM', 'HACKER', 7902, sysdate, 1800, null, 40);
7 emp_utils.pop_emp(newbies);
8 END;
9 /
PL/SQL procedure successfully completed.
SQL> SELECT * FROM emp WHERE deptno = 40
2 /
EMPNO ENAME JOB MGR HIREDATE SAL COMM
DEPTNO
7777 APC CODER 7902 17-NOV-05 1700
40
7778 J RANDOM HACKER 7902 17-NOV-05 1800
40
SQL> Cheers, APC -
Shell Script For Export And Import Of Table Records
Hello,
We have production and test instances and for constant testing we need to copy data from production to test or development environment.
At the moment what we do is manually doing export and import table records. At times this could be very tedious as we may need
to do this exercise a couple of times in a day.
Is it a good idea to do this exercise using shell script? If so how could I do this? If this is not a good idea what are the best alternatives?
Any input is highly appreciated.
ThanksAh I see, your company prefers stupidity over efficiency. It would be possible to do it in a controlled environment, wouldn't it? Also the test database would be allowed to select only.
So the non-allowance is just plain stupid.
To the second question: do you use hard-coded passwords in shell scripts?
Don't you think that poses a security risk?
Don't you think that is a bigger risk than a database link, properly set up?
In my book it is!
Sybrand Bakker
Senior Oracle DBA -
Unable to read E$ table records into excel file in linux machine
Hi
I am using below code in ODI procedure to read E$ table record and store it in excel file
ODI Procedure: Technology=Java Beanshall and Command on Target I written below code and placed it in CKM Oracle KM
<@
String OS = System.getProperty("os.name").toLowerCase();
String v_path="";
if((OS.indexOf("win") >= 0))
v_path="D:\Unload_Dir\<%=snpRef.getSession("SESS_NO")%>.xlsx";
else if (OS.indexOf("mac") >= 0)
v_path="path details";
else if (OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") > 0 )
v_path="/odi_a/oracle/Middleware/logs/wcds/odi_logs/<%=snpRef.getSession("SESS_NO")%>.xlsx";
else if (OS.indexOf("sunos") >= 0)
v_path="soliaris path";
@>
OdiSqlUnload "-FILE=<@=v_path@>" "-DRIVER=<%=odiRef.getInfo("DEST_JAVA_DRIVER")%>" "-URL=<%=odiRef.getInfo("DEST_JAVA_URL")%>" "-USER=<%=odiRef.getInfo("DEST_USER_NAME")%>" "-PASS=<%=odiRef.getInfo("DEST_ENCODED_PASS")%>" "-FILE_FORMAT=VARIABLE" "-ROW_SEP=\r\n" "-DATE_FORMAT=yyyy/MM/dd HH:mm:ss" "-CHARSET_ENCODING=ISO8859_1" "-XML_CHARSET_ENCODING=ISO-8859-1"
select * from <%=odiRef.getTable("L","ERR_NAME", "W")%>
But is not reading the data into .xlsx file ,
Please help me it is very urgent
Can I use below code
String os = "";
if (System.getProperty("os.name").toLowerCase().indexOf("windows") > -1) {
os = "windows";
} else if (System.getProperty("os.name").toLowerCase().indexOf("linux") > -1) {
os = "linux";
} else if (System.getProperty("os.name").toLowerCase().indexOf("mac") > -1) {
os = "mac";
T
his is high priority, please help me urgent
Regards,
Phanikanth
Edited by: Phanikanth on Feb 28, 2013 5:43 AM
Edited by: Phanikanth on Feb 28, 2013 6:00 AM
Edited by: Phanikanth on Feb 28, 2013 7:42 AMHi,
can you describe what is happening when you run the ODI procedure described below:
- Does the procedure fail with an error, if yes, which error(full details)?
- Does the procedure pass but no xslx file is been created?
- Does the procedure pass and an xslx file is been created, but Excel can't read it? If yes, what is the structure of the xslx file when read in an editor?
What I can see from your code below is that you have choosen -FILE_FORMAT=VARIABLE, but the XSLX format is supposed to be XML.
Regards,
Alex -
Refresh internal table records in web dynpro
Hi Guru's
I am facing an issue in web dynpro abap.
in my application there is a button called OPEN.
when i click on open button internal table records should be refreshed.
so i have written code like this
DATA lo_COMPONENTCONTROLLER TYPE REF TO IG_COMPONENTCONTROLLER .
lo_COMPONENTCONTROLLER = wd_this->get_componentcontroller_ctr( ).
lo_componentcontroller->clear_info_refresh_visible( ).
but iam getting an error message Method "CLEAR_INFO_REFRESH_VISIBLE" is unknown or PROTECTED or PRIVATE
Could you please help me to how do i activate and refresh the things.
Thanks
Rajuewd.rajue wrote:
Hi Guru's
>
> I am facing an issue in web dynpro abap.
> in my application there is a button called OPEN.
> when i click on open button internal table records should be refreshed.
> so i have written code like this
>
> DATA lo_COMPONENTCONTROLLER TYPE REF TO IG_COMPONENTCONTROLLER .
>
> lo_COMPONENTCONTROLLER = wd_this->get_componentcontroller_ctr( ).
>
> lo_componentcontroller->clear_info_refresh_visible( ).
>
>
>
> but iam getting an error message Method "CLEAR_INFO_REFRESH_VISIBLE" is unknown or PROTECTED or PRIVATE
>
>
> Could you please help me to how do i activate and refresh the things.
>
> Thanks
> Rajue
Raju,
Please clarify this.
Do you have a method clear_info_refresh_visible in your component controller. I think not.
I am not able to relate your request and coding.
You can simply clear the internal table like this
clear lt_intern_tab[].
If it is a context node then you can bind a empty table to the node to make it empty.
lo_nd_data->bind_table(
new_items = lt_intern_tab
set_initial_elements = abap_true ). -
Hi i am new to OAF. Please someone help me in how to create a Pivot report table in OAF?
The table structure should be like
_______________________________________Column1________________________Column2____________________Column3
_______________________________________Part1 __________________________ Part2______________________Part3
_______________________________________Part 1.a_____Part1.b____________ Part2.a_______ part2.b_________Part3.a_______ part3.c
Row1__Organization name1 Manager Name1 count of employees
Row2__Organization name2 Manager Name2 count of employees
Edited by: 847828 on Mar 28, 2011 1:27 AM
Edited by: 847828 on Mar 28, 2011 1:33 AM
Edited by: 847828 on Mar 28, 2011 1:39 AMHi,
Kindly elaborate your requirement.
Thanks,
Gaurav -
Hi,
Need help in pivot the table.
Table data
NAME
LINE_TYPE_REF_ID
Class
CreateShipmentServiceAdapterImpl
Method
getContactsAndSitesForAccount
User
skkond
Node Name
PB15CKY
Num Contacts
3
Class
CreateShipmentServiceAdapterImpl
Method
getContactsAndSitesForAccount
User
drcoul
Node Name
C4F6JJ1
Num Contacts
21
Class
CreateShipmentServiceAdapterImpl
Method
getContactsAndSitesForAccount
User
drcoul
Node Name
C4F6JJ1
Num Contacts
21
Required
Class
Method
Node Name
Num Contacts
User
CreateShipmentServiceAdapterImpl
getContactsAndSitesForAccount
PB15CKY
3
skkond
CreateShipmentServiceAdapterImpl
getContactsAndSitesForAccount
C4F6JJ1
21
drcoul
CreateShipmentServiceAdapterImpl
getContactsAndSitesForAccount
C4F6JJ1
21
drcoul
Thanks,
Tiru.Using PIVOT function ( for versions >= 11g ):
with table_x as
select 'class' name, 'CreateShipmentServiceAdapterImpl' rid from dual UNION ALL
select 'method' name, 'getContactsAndSitesForAccount' rid from dual UNION ALL
select 'user' name, 'skkond' rid from dual UNION ALL
select 'node_name' name, 'PB15CKY' rid from dual UNION ALL
select 'num' name, '3' rid from dual
UNION ALL
select 'class' name, 'CreateShipmentServiceAdapterImpl' rid from dual UNION ALL
select 'method' name, 'getContactsAndSitesForAccount' rid from dual UNION ALL
select 'user' name, 'drcoul' rid from dual UNION ALL
select 'node_name' name, 'C4F6JJ1' rid from dual UNION ALL
select 'num' name, '21' rid from dual
UNION ALL
select 'class' name, 'CreateShipmentServiceAdapterImpl' rid from dual UNION ALL
select 'method' name, 'getContactsAndSitesForAccount' rid from dual UNION ALL
select 'user' name, 'drcoul' rid from dual UNION ALL
select 'node_name' name, 'C4F6JJ1' rid from dual UNION ALL
select 'num' name, '21' rid from dual
---- Sample data ends here
SELECT * FROM (select
Trunc((ROWNUM-1)/5) id, name, rid
from table_x)
PIVOT(
MIN(rid)
FOR
name IN ('class','method','user','node_name','num')
ORDER BY id;
OUTPUT :
ID
'class'
'method'
'user'
'node_name'
'num'
0
CreateShipmentServiceAdapterImpl
getContactsAndSitesForAccount
skkond
PB15CKY
3
1
CreateShipmentServiceAdapterImpl
getContactsAndSitesForAccount
drcoul
C4F6JJ1
21
2
CreateShipmentServiceAdapterImpl
getContactsAndSitesForAccount
drcoul
C4F6JJ1
21
The Trunc((ROWNUM-1)/5) is added as an ID column... This has a very important role to play.
ROWNUM values = {1, 2, 3, 4, ... n}
where
n = total no of rows fetched by the query
Division-by-5
Since there are 5 column (in this scenario), so we need to group each set of 5 consecutive rows.
So, Group-1 : rows {1,2,3,4,5} , Group-2 : rows {6,7,8,9,10} and so on...
Now, if you Divide each value by 5 and then do TRUNC, you'll get an Id (or say "Group-id") with each group of 5 consecutive rows.
This so-called "Group-id" generated will help to do a GROUP BY operation which is mandatory for the Aggregate operation in PIVOT function.
Hope that helps,
-- Ranit -
Document attachment to custom tables / records
Good morning,
do you know if it is possible to attach external documents to custom tables / records, in the same way as it is possible for standard transactions (Services for Object)?
If yes, can you please advise me on some reference documetns about how to customize this functionality?
Thanks in advance
ASHi ,
Displaying attachments is not available in the Interaction record view.You need custom development to enable the attachemnts there.
usually the process would be to create a followup activity from the interaction record and attch documents there.
Thanks,
Rajiv. -
How to display the Internal table records in table format?
Hi Gurus,
I want to display my print prg internal table records in d appropriate form in a table format, give some solution
with regards
ThambeThere are lot many options to do that
one way is create template in the maikn window and define the line types according to your data cretae text and put your data in the text and go to output options and give the line type to be used . You can also select details option to have lines in your output.
similarly YOU CAN CREATE TABLE IN THE MAIN WINDOW FOR THIS YOU DONT NEED TO DEFINE THE LINE TYPES .
WHEN YOU ARE IN MAIN WINDOW RIGHT CLICK ON TABLE AND GO TO PATH
CREATE -> TABLE
-> TEMPLATE
REWARD IF USEFUL
Regards,
Nageswar -
Function module for move internal table records into MSexcel file
Hi all,
Tell me the function module which is used to
move internal table records in to MSexcel file.
Give the sample program...Please search the forum for FM "GUI_DOWNLOAD" You will get tons of threads with sample code.
Also take a look into SAP_CONVERT_TO_XLS_FORMAT
Thanks -
How to setup DRILL/PIVOT in table region :
plzz tell me how to setup DRILL/PIVOT in table region in Oracle Daily Business Intelligence Dashboard.
what is the setting? to show drill/pivot option in table region [first column]Hi Sai Krishna,
There is a very small difference between these two when you will create dependent LOV in Table or Advanced table the all the FormValue items to store ids which will be used as crieteria map or return items should be created inside table/Advanced table region.
Hope this will help.
Regards,
Reetesh Sharma -
KNA1 table records not downloading to excel correctly
Folks,
Im trying to download KNA1 table records into excel sheet. I can see total number of records in table as 22513, but when i download them into excel sheet then total records are coming to 22521.
When i dig the excel sheet for 4 customers record is present in 2 lines(where because of special characters data truncated to next line). However rest all customers are downloaded in single line.
What steps i need to follow to download that 4 records also into single line along with the special characters.
will be waiting for your valuable answers.
Regards
VEnk@No i checked in table all four records are unique no duplicates present.
-
We are upgrading from 8.3 to 9.2. How can i get the table(record) structure changes between these 2 versions. I am not able to find it in Oracle support.
My guess is you want to upgrade HR8.3 to 9.2 - and that is not one jump upgrade. You will need to go HRMS 83 to 90
(PeopleSoft Enterprise HRMS 8.3x to 9.0 Upgrade (Doc ID 747333.1) and then 90 to 92 (PeopleSoft Human Capital Management 9.0 to 9.2 Upgrade Home Page (Doc ID 1536087.1)
Each these MOS pages contains the Demo to Demo Compare Reports that show the data structures changes between the releases.
Hope it helps. -
PipeLine Function Taking time to return Table record
Hi,
I want to use a function in join clause. so i go for pipelined function(using for loop to get record & 1 more loop to fetch in table type variable). i achieved what i required. but problem is it takes much time to fetch data. is there any other approach which returns table records without pipelined function.
please suggest me a better approach as soon as possible.Hi,
Thanks all for the quick response.
I am using oracle 10g
this is the table details & the entire function.
Create object & table type to use in the function
CREATE OR REPLACE TYPE SYSADM.STR_TYPE AS OBJECT(COLUMNVALUE VARCHAR2(8),FromNo Int,ToNo Int)
CREATE OR REPLACE TYPE SYSADM.STR_ARRAY AS TABLE OF STR_TYPE
table involved
View : VesselType
column : Code varchar2(5)
Table : T065_SHIP
column : SKIPS_KODE varchar2(4)
CODE_SHIPTYPE varchar2(5)
Table : SelsKap
column : SELSKAPSKODE varchar2(4)
Table : t041_shiptypeusers
column : Code_ShipType varchar2(5)
USERID varchar2(8)
View : PositionBook
column : VesselCode varchar2(8)
VoyageNo integer
Company varchar2(4)
Table : T62_BRUKER_SELSKAP
column : SELSKAPSKODE varchar2(4)
BRUKER varchar2(8)
Pipelined function
CREATE OR REPLACE FUNCTION SYSADM.TF_ShiporShipTypeByUser
In_UserName IN VARCHAR2,
In_Type IN VARCHAR2,
In_VesselCode IN VARCHAR2,
In_CompanyHistory IN NUMBER DEFAULT 0
RETURN str_array PIPELINED AS
l_ShipTypeUser NUMBER(10,0);
l_CompanyUser NUMBER(10,0);
l_UseCompanyHistory NUMBER(1,0);
l_Snicsacct NUMBER(1,0);
BEGIN
BEGIN
SELECT shiptype_user,
company_user
INTO l_ShipTypeUser,
l_CompanyUser
FROM User_Segregation;
EXCEPTION
WHEN OTHERS THEN
l_ShipTypeUser := NULL;
l_CompanyUser := NULL;
END;
BEGIN
SELECT 1 INTO l_Snicsacct
FROM DUAL
WHERE NOT EXISTS ( SELECT 1 FROM sn_user_cfg WHERE UserID='SNICS' and CfgID='ACCTSYS');
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
IF In_CompanyHistory = 1
THEN
BEGIN
SELECT CfgData
INTO l_UseCompanyHistory
FROM SN_User_Cfg
WHERE CfgID = 'USE COMPANY HISTORY'
AND UserID = 'SNICS';
EXCEPTION
WHEN OTHERS THEN
l_UseCompanyHistory := 0;
END;
END IF;
IF In_UserName = 'SYSADM' OR (l_CompanyUser = 0 AND l_ShipTypeUser = 0)
OR (l_CompanyUser = 1 and l_Snicsacct =1 ) or (In_CompanyHistory = 0 and l_CompanyUser = 1 and In_Type ='ShipType')
OR (l_ShipTypeUser = 1 and In_Type = 'Company')
THEN
BEGIN
IF In_Type = 'ShipType'
THEN
BEGIN
FOR cur IN (SELECT Code ShipCode
, 1 VoyageFrom
, 999999999 VoyageTo
FROM VesselType )
LOOP
PIPE ROW(str_type(cur.ShipCode,cur.VoyageFrom,cur.VoyageTo));
END LOOP;
RETURN;
END;
ELSIF In_Type = 'Ship'
THEN
BEGIN
FOR cur IN (SELECT SKIPS_KODE ShipCode
, 1 VoyageFrom
, 999999999 VoyageTo
FROM T065_SHIP
WHERE SKIPS_KODE = NVL(In_VesselCode,SKIPS_KODE ))
LOOP
PIPE ROW(str_type(cur.ShipCode,cur.VoyageFrom,cur.VoyageTo));
END LOOP;
RETURN;
END;
ELSIF In_Type = 'Company'
THEN
BEGIN
FOR cur IN (SELECT SELSKAPSKODE ShipCode
, NULL VoyageFrom
, NULL VoyageTo
FROM SelsKap)
LOOP
PIPE ROW(str_type(cur.ShipCode,cur.VoyageFrom,cur.VoyageTo));
END LOOP;
RETURN;
END;
END IF;
END;
ELSE
IF In_Type = 'Ship'
THEN
BEGIN
IF l_ShipTypeUser =1
THEN
BEGIN
FOR cur IN (SELECT S.SKIPS_KODE ShipCode
, 1 FromVoyage
, 999999999 ToVoyage
FROM T065_SHIP S
JOIN t041_shiptypeusers U
ON S.CODE_SHIPTYPE = U.Code_ShipType
AND USERID = In_UserName
WHERE S.SKIPS_KODE = NVL(In_VesselCode, S.SKIPS_KODE)
GROUP BY S.SKIPS_KODE)
LOOP
PIPE ROW(str_type(cur.ShipCode,cur.FromVoyage,cur.ToVoyage));
END LOOP;
RETURN;
END;
ELSIF l_CompanyUser = 1
THEN
BEGIN
IF l_UseCompanyHistory = 1 AND In_CompanyHistory = 1
THEN
FOR cur IN (SELECT a.VesselCode ShipCode
, a.VoyageNo VoyageFrom
, a.VoyageNo VoyageTo
FROM PositionBook a
JOIN T62_BRUKER_SELSKAP b
ON a.Company = b.SELSKAPSKODE
AND b.BRUKER = In_UserName
WHERE a.VesselCode = NVL(In_VesselCode, a.VesselCode)
UNION
SELECT a.VesselCode ShipCode
, a.VoyageNo VoyageFrom
, a.VoyageNo VoyageTo
FROM PositionBook a
LEFT JOIN T62_BRUKER_SELSKAP b
ON a.company = b.SELSKAPSKODE
WHERE a.VesselCode = NVL(In_VesselCode, a.VesselCode)
AND b.SELSKAPSKODE IS NULL
GROUP BY a.VesselCode,
a.VoyageNo,
a.VoyageNo)
LOOP
PIPE ROW(str_type(cur.ShipCode,cur.VoyageFrom,cur.VoyageTo));
END LOOP;
RETURN;
ELSE
FOR cur IN (SELECT a.SKIPS_KODE ShipCode
, 1 VoyageFrom
, 999999999 VoyageTo
FROM T065_SHIP a
JOIN T62_BRUKER_SELSKAP b
ON a.Company = b.SELSKAPSKODE
AND b.BRUKER = In_UserName
WHERE a.SKIPS_KODE = NVL(In_VesselCode, a.SKIPS_KODE)
AND NVL(l_UseCompanyHistory,0) = 0
UNION
SELECT a.SKIPS_KODE ShipCode
, 1 VoyageFrom
, 999999999 VoyageTo
FROM T065_SHIP a
LEFT JOIN T62_BRUKER_SELSKAP b
ON a.company = b.SELSKAPSKODE
WHERE a.SKIPS_KODE = NVL(In_VesselCode, a.SKIPS_KODE)
AND b.SELSKAPSKODE IS NULL
GROUP BY a.SKIPS_KODE)
LOOP
PIPE ROW(str_type(cur.ShipCode,cur.VoyageFrom,cur.VoyageTo));
END LOOP;
RETURN;
END IF;
END;
END IF;
END;
ELSIF In_Type = 'ShipType'
THEN
IF l_ShipTypeUser = 1
THEN
BEGIN
FOR cur IN (SELECT S.CODE_SHIPTYPE ShipCode
, 1 VoyageFrom
, 999999999 VoyageTo
FROM T065_SHIP S
JOIN t041_shiptypeusers U
ON S.CODE_SHIPTYPE = U.Code_ShipType
AND USERID = In_UserName
WHERE S.SKIPS_KODE = NVL(In_VesselCode, S.SKIPS_KODE)
GROUP BY S.CODE_SHIPTYPE)
LOOP
PIPE ROW(str_type(cur.ShipCode,cur.VoyageFrom,cur.VoyageTo));
END LOOP;
RETURN;
END;
ELSIF l_CompanyUser = 1
THEN
IF l_UseCompanyHistory = 1 AND In_CompanyHistory = 1
THEN
BEGIN
FOR cur IN (SELECT a.VesselType ShipCode
, a.VoyageNo VoyageFrom
, a.VoyageNo VoyageTo
FROM PositionBook a
JOIN T62_BRUKER_SELSKAP b
ON a.COMPANY = b.SELSKAPSKODE
AND b.BRUKER = In_UserName
WHERE a.VesselCode = NVL(In_VesselCode,a.VesselCode)
UNION
SELECT a.VesselType ShipCode
, a.VoyageNo VoyageFrom
, a.VoyageNo VoyageTo
FROM PositionBook a
LEFT JOIN T62_BRUKER_SELSKAP b
ON a.company = b.SELSKAPSKODE
WHERE a.VesselCode = NVL(In_VesselCode, a.VesselCode)
AND b.SELSKAPSKODE IS NULL
GROUP BY a.VesselType,
a.VoyageNo,
a.VoyageNo)
LOOP
PIPE ROW(str_type(cur.ShipCode,cur.VoyageFrom,cur.VoyageTo));
END LOOP;
RETURN;
END;
ELSE
BEGIN
FOR cur IN (SELECT S.CODE_SHIPTYPE ShipCode
, 1 VoyageFrom
, 999999999 VoyageTo
FROM T065_SHIP S
JOIN T62_BRUKER_SELSKAP b
ON S.company = b.SELSKAPSKODE
AND B.BRUKER = In_UserName
WHERE S.SKIPS_KODE = NVL(In_VesselCode, S.SKIPS_KODE)
AND NVL(l_UseCompanyHistory,0) = 0
UNION
SELECT S.CODE_SHIPTYPE ShipCode
, 1 VoyageFrom
, 999999999 VoyageTo
FROM T065_SHIP S
LEFT JOIN T62_BRUKER_SELSKAP b
ON S.company = b.SELSKAPSKODE
WHERE S.SKIPS_KODE = NVL(In_VesselCode, S.SKIPS_KODE)
AND b.SELSKAPSKODE IS NULL)
LOOP
PIPE ROW(str_type(cur.ShipCode,cur.VoyageFrom,cur.VoyageTo));
END LOOP;
RETURN;
END;
END IF;
END IF;
ELSIF In_Type = 'Company'
THEN
BEGIN
FOR cur IN (SELECT a.SELSKAPSKODE ShipCode
, NULL VoyageFrom
, NULL VoyageTo
FROM Selskap a
JOIN T62_BRUKER_SELSKAP b
ON a.SELSKAPSKODE = b.SELSKAPSKODE
WHERE b.BRUKER = In_UserName
Union All
Select a.SELSKAPSKODE ShipCode
, NULL VoyageFrom
, NULL VoyageTo
From Selskap a
LEFT JOIN T62_BRUKER_SELSKAP b
ON a.SELSKAPSKODE = b.SELSKAPSKODE
Where b.SELSKAPSKODE IS NULL
GROUP BY a.SELSKAPSKODE)
LOOP
PIPE ROW(str_type(cur.ShipCode,cur.VoyageFrom,cur.VoyageTo));
END LOOP;
RETURN;
END;
END IF;
END IF;
END;
select statement which i call the function it takes minimum 6 seconds to execute. It gives 8339 records
WITH deftbl AS ( SELECT /*+ CACHE(deftbl) */
/*+ result_cache */
a.VesselCode,
a.VoyageNo,
CASE a.BallastLeg When 0
THEN MIN(a.ArrivalDate)
ELSE NVL(( SELECT MAX(DepartureDate)
FROM PositionBook b
WHERE b.VesselCode = a.VesselCode
AND b.VoyageNo = (Select MAX(VoyageNo) From PositionBook c Where c.VesselCode = a.VesselCode and c.VoyageNo<a.VoyageNo)
),MIN(a.ArrivalDate))
END AS StartOfVoyage,
MAX(DepartureDate) EndOfVoyage
FROM PositionBook a
JOIN TABLE(*TF_ShiporShipTypeByUser*('BKA', 'Ship', NULL, 1)) D /*Calling the function*/
ON D.ColumnValue = a.VesselCode
AND a.VoyageNo BETWEEN D.FromVoyageNo AND D.ToVoyageNo
GROUP BY VesselCode,VoyageNo,a.BallastLeg )
SELECT /*+ result_cache */
ROW_NUMBER() OVER(PARTITION BY a.VesselCode ORDER BY a.VoyageNo DESC) as "Row"
,a.VesselCode
,v.Name AS VesselName
,a.VoyageNo
,c.StartOfVoyage AS FromPort
,c.EndOfVoyage AS ToPort
/*,a.FROMPORT
,a.TOPORT*/
, CASE
WHEN ( SELECT PortName
FROM PositionBook b
WHERE b.VesselCode = a.VesselCode
AND b.VoyageNo = a.VoyageNo
AND SYSDATE BETWEEN ArrivalDate AND DepartureDate ) IS NOT NULL
THEN ( SELECT FIRST_VALUE(PortName) OVER(PARTITION BY b.vesselcode,b.VoyageNo ORDER BY b.vesselcode,b.VoyageNo,b.ArrivalDate,b.secondarytime)
FROM PositionBook b
WHERE b.VesselCode = a.VesselCode
AND b.VoyageNo = a.VoyageNo
AND SYSDATE BETWEEN ArrivalDate AND DepartureDate
AND ROWNUM=1
WHEN SYSDATE BETWEEN c.StartOfVoyage AND c.EndOfVoyage
THEN ( SELECT 'Steam From '||FIRST_VALUE(UPPER(PortName)) OVER(PARTITION BY b.vesselcode,b.VoyageNo ORDER BY b.vesselcode,b.VoyageNo,b.ArrivalDate desc,b.secondarytime desc)
FROM POSITIONBOOK b
WHERE b.VesselCode = a.VesselCode AND b.VoyageNo = a.VoyageNo
AND b.ArrivalDate<SYSDATE
AND ROWNUM=1
WHEN (c.StartOfVoyage-SYSDATE)>0
THEN 'Voyage Not Started'
WHEN (c.EndOfVoyage-SYSDATE)<0
THEN 'Voyage Completed'
ELSE Null
END "Location"
,( SELECT MIN(b.PortName) KEEP(DENSE_RANK FIRST ORDER BY b.ArrivalDate,b.secondarytime) OVER(PARTITION BY b.VesselCode,b.VoyageNo)
FROM POSITIONBOOK b
WHERE b.VesselCode = a.VesselCode AND b.VoyageNo = a.VoyageNo
AND b.ArrivalDate>SYSDATE
AND ROWNUM=1
) AS NextPort
, ( SELECT MIN(b.ArrivalDate) KEEP(DENSE_RANK FIRST ORDER BY b.ArrivalDate,b.secondarytime) OVER(PARTITION BY b.VesselCode,b.VoyageNo)
FROM POSITIONBOOK b
where b.VesselCode = a.VesselCode AND b.VoyageNo = a.VoyageNo
AND b.ArrivalDate>SYSDATE
AND ROWNUM=1
) AS NextETA
,a.STATUS VoyageStatus
,a.Trade
,UFN_MyVoyConcatinate_Values('FIXNOTE', a.VesselCode, a.VoyageNo) FixNote
,UFN_MyVoyConcatinate_Values('CHARTERER', a.VesselCode, a.VoyageNo) Charterer
,CASE WHEN st.CurrentStatus=0
THEN 1
WHEN st.CurrentStatus=1
THEN 0
ELSE st.CurrentStatus
END AS CurrentStatus
FROM Positionbook a
JOIN deftbl c
ON a.VesselCode = c.VesselCode
AND a.VoyageNo = c.VoyageNo
JOIN Vessel v
ON v.Code = c.VesselCode
LEFT JOIN GTT_VOYAGESTATUS st
ON st.VesselCode = c.Vesselcode
AND st.VoyageNo = c.VoyageNo
GROUP BY a.VesselCode
, v.Name
, a.VoyageNo
, c.StartOfVoyage
, c.EndOfVoyage
/*, a.FROMPORT
, a.TOPORT*/
, a.Status
, a.Trade
, st.CurrentStatus;
Note:
i changed the function without pipelined also. but it doesnt show much difference
non pipelined function
CREATE OR REPLACE FUNCTION TF_ShiporShipTypeByUser_nonp
In_UserName IN VARCHAR2,
In_Type IN VARCHAR2,
In_VesselCode IN VARCHAR2,
In_CompanyHistory IN NUMBER DEFAULT 0
RETURN str_array AS
l_ShipTypeUser NUMBER(10,0);
l_CompanyUser NUMBER(10,0);
l_UseCompanyHistory NUMBER(1,0);
l_Snicsacct NUMBER(1,0);
l_str_array str_array:=str_array();
BEGIN
BEGIN
SELECT shiptype_user,
company_user
INTO l_ShipTypeUser,
l_CompanyUser
FROM User_Segregation;
EXCEPTION
WHEN OTHERS THEN
l_ShipTypeUser := NULL;
l_CompanyUser := NULL;
END;
BEGIN
SELECT 1 INTO l_Snicsacct
FROM DUAL
WHERE NOT EXISTS ( SELECT 1 FROM sn_user_cfg WHERE UserID='SNICS' and CfgID='ACCTSYS');
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
IF In_CompanyHistory = 1
THEN
BEGIN
SELECT CfgData
INTO l_UseCompanyHistory
FROM SN_User_Cfg
WHERE CfgID = 'USE COMPANY HISTORY'
AND UserID = 'SNICS';
EXCEPTION
WHEN OTHERS THEN
l_UseCompanyHistory := 0;
END;
END IF;
IF In_UserName = 'SYSADM' OR (l_CompanyUser = 0 AND l_ShipTypeUser = 0)
OR (l_CompanyUser = 1 and l_Snicsacct =1 ) or (In_CompanyHistory = 0 and l_CompanyUser = 1 and In_Type ='ShipType')
OR (l_ShipTypeUser = 1 and In_Type = 'Company')
THEN
BEGIN
IF In_Type = 'ShipType'
THEN
BEGIN
SELECT STR_TYPE(Code,1,999999999)
BULK COLLECT INTO l_str_array
FROM VesselType;
RETURN l_str_array;
END;
ELSIF In_Type = 'Ship'
THEN
BEGIN
SELECT STR_TYPE(SKIPS_KODE,1,999999999)
BULK COLLECT INTO l_str_array
FROM T065_SHIP
WHERE SKIPS_KODE = NVL(In_VesselCode,SKIPS_KODE);
RETURN l_str_array;
END;
ELSIF In_Type = 'Company'
THEN
BEGIN
SELECT STR_TYPE(SELSKAPSKODE,NULL,NULL)
BULK COLLECT INTO l_str_array
FROM SelsKap;
RETURN l_str_array;
END;
END IF;
END;
ELSE
IF In_Type = 'Ship'
THEN
BEGIN
IF l_ShipTypeUser =1
THEN
BEGIN
SELECT STR_TYPE(S.SKIPS_KODE,1,999999999)
BULK COLLECT INTO l_str_array
FROM T065_SHIP S
JOIN t041_shiptypeusers U
ON S.CODE_SHIPTYPE = U.Code_ShipType
AND USERID = In_UserName
WHERE S.SKIPS_KODE = NVL(In_VesselCode, S.SKIPS_KODE)
GROUP BY S.SKIPS_KODE;
RETURN l_str_array;
END;
ELSIF l_CompanyUser = 1
THEN
BEGIN
IF l_UseCompanyHistory = 1 AND In_CompanyHistory = 1
THEN
SELECT STR_TYPE(ShipCode,VoyageFrom,VoyageTo)
BULK COLLECT INTO l_str_array
FROM ( SELECT a.VesselCode ShipCode
, a.VoyageNo VoyageFrom
, a.VoyageNo VoyageTo
FROM PositionBook a
JOIN T62_BRUKER_SELSKAP b
ON a.Company = b.SELSKAPSKODE
AND b.BRUKER = In_UserName
WHERE a.VesselCode = NVL(In_VesselCode, a.VesselCode)
UNION
SELECT a.VesselCode ShipCode
, a.VoyageNo VoyageFrom
, a.VoyageNo VoyageTo
FROM PositionBook a
LEFT JOIN T62_BRUKER_SELSKAP b
ON a.company = b.SELSKAPSKODE
WHERE a.VesselCode = NVL(In_VesselCode, a.VesselCode)
AND b.SELSKAPSKODE IS NULL
GROUP BY a.VesselCode,
a.VoyageNo,
a.VoyageNo);
RETURN l_str_array;
ELSE
SELECT STR_TYPE(ShipCode,VoyageFrom,VoyageTo)
BULK COLLECT INTO l_str_array
FROM (SELECT a.SKIPS_KODE ShipCode
, 1 VoyageFrom
, 999999999 VoyageTo
FROM T065_SHIP a
JOIN T62_BRUKER_SELSKAP b
ON a.Company = b.SELSKAPSKODE
AND b.BRUKER = In_UserName
WHERE a.SKIPS_KODE = NVL(In_VesselCode, a.SKIPS_KODE)
AND NVL(l_UseCompanyHistory,0) = 0
UNION
SELECT a.SKIPS_KODE ShipCode
, 1 VoyageFrom
, 999999999 VoyageTo
FROM T065_SHIP a
LEFT JOIN T62_BRUKER_SELSKAP b
ON a.company = b.SELSKAPSKODE
WHERE a.SKIPS_KODE = NVL(In_VesselCode, a.SKIPS_KODE)
AND b.SELSKAPSKODE IS NULL
GROUP BY a.SKIPS_KODE);
RETURN l_str_array;
END IF;
END;
END IF;
END;
ELSIF In_Type = 'ShipType'
THEN
IF l_ShipTypeUser = 1
THEN
BEGIN
SELECT STR_TYPE(ShipCode,VoyageFrom,VoyageTo)
BULK COLLECT INTO l_str_array
FROM (SELECT S.CODE_SHIPTYPE ShipCode
, 1 VoyageFrom
, 999999999 VoyageTo
FROM T065_SHIP S
JOIN t041_shiptypeusers U
ON S.CODE_SHIPTYPE = U.Code_ShipType
AND USERID = In_UserName
WHERE S.SKIPS_KODE = NVL(In_VesselCode, S.SKIPS_KODE)
GROUP BY S.CODE_SHIPTYPE);
RETURN l_str_array;
END;
ELSIF l_CompanyUser = 1
THEN
IF l_UseCompanyHistory = 1 AND In_CompanyHistory = 1
THEN
BEGIN
SELECT STR_TYPE(ShipCode,VoyageFrom,VoyageTo)
BULK COLLECT INTO l_str_array
FROM ( SELECT a.VesselType ShipCode
, a.VoyageNo VoyageFrom
, a.VoyageNo VoyageTo
FROM PositionBook a
JOIN T62_BRUKER_SELSKAP b
ON a.COMPANY = b.SELSKAPSKODE
AND b.BRUKER = In_UserName
WHERE a.VesselCode = NVL(In_VesselCode,a.VesselCode)
UNION
SELECT a.VesselType ShipCode
, a.VoyageNo VoyageFrom
, a.VoyageNo VoyageTo
FROM PositionBook a
LEFT JOIN T62_BRUKER_SELSKAP b
ON a.company = b.SELSKAPSKODE
WHERE a.VesselCode = NVL(In_VesselCode, a.VesselCode)
AND b.SELSKAPSKODE IS NULL
GROUP BY a.VesselType,
a.VoyageNo,
a.VoyageNo);
RETURN l_str_array;
END;
ELSE
BEGIN
SELECT STR_TYPE(ShipCode,VoyageFrom,VoyageTo)
BULK COLLECT INTO l_str_array
FROM ( SELECT S.CODE_SHIPTYPE ShipCode
, 1 VoyageFrom
, 999999999 VoyageTo
FROM T065_SHIP S
JOIN T62_BRUKER_SELSKAP b
ON S.company = b.SELSKAPSKODE
AND B.BRUKER = In_UserName
WHERE S.SKIPS_KODE = NVL(In_VesselCode, S.SKIPS_KODE)
AND NVL(l_UseCompanyHistory,0) = 0
UNION
SELECT S.CODE_SHIPTYPE ShipCode
, 1 VoyageFrom
, 999999999 VoyageTo
FROM T065_SHIP S
LEFT JOIN T62_BRUKER_SELSKAP b
ON S.company = b.SELSKAPSKODE
WHERE S.SKIPS_KODE = NVL(In_VesselCode, S.SKIPS_KODE)
AND b.SELSKAPSKODE IS NULL);
RETURN l_str_array;
END;
END IF;
END IF;
ELSIF In_Type = 'Company'
THEN
BEGIN
SELECT STR_TYPE(ShipCode,VoyageFrom,VoyageTo)
BULK COLLECT INTO l_str_array
FROM ( SELECT a.SELSKAPSKODE ShipCode
, NULL VoyageFrom
, NULL VoyageTo
FROM Selskap a
JOIN T62_BRUKER_SELSKAP b
ON a.SELSKAPSKODE = b.SELSKAPSKODE
WHERE b.BRUKER = In_UserName
Union All
Select a.SELSKAPSKODE ShipCode
, NULL VoyageFrom
, NULL VoyageTo
From Selskap a
LEFT JOIN T62_BRUKER_SELSKAP b
ON a.SELSKAPSKODE = b.SELSKAPSKODE
Where b.SELSKAPSKODE IS NULL
GROUP BY a.SELSKAPSKODE);
RETURN l_str_array;
END;
END IF;
END IF;
END;please kindly provide me your valuable suggestions
Edited by: ganex27lin on Mar 16, 2011 1:54 AM
Maybe you are looking for
-
How do I make New window open maximized the way it used to?
How do I make New window open maximized the way it used to?
-
MI424WR - DNS Host Name Resolution
I have added several DNS entries in the DNS Server section of the MI424WR. These are for my network printer, and I have renamed several Android devices to give them names. When I try to ping any host name that I added to the DNS Server section it doe
-
Script issue,Java install from script, push out to servers.
this is a non standard install for Java that has to be installed from a script. basically this script will run against a given amount of servers, stop the required services ( pertains to the application that requires Java on the server), uninstall j
-
On E series Card with 2 counters I want to generate a fixed length pulse train and want to continuously monitor it.
-
We upgraded from CS5.5 to CS 6. Whenever we click on a file to open, it asks to "Open With." The desired program is not an option, so we browse to locate it. Nevertheless, the file still can not be opened with the right program. To open it, I have