Year Function output
I am using this query to get a list of years greater then 2009, but the format is coming back as 2,009. Any idea how to change this format?
SELECT distinct(year(F_OPPORTUNITY.ESTIMATEDCLOSEDATE)) DT_RANGE FROM "TNS-CRM-DWH" where year(F_OPPORTUNITY.ESTIMATEDCLOSEDATE) > 2009
try this...
SELECT distinct(cast(year(F_OPPORTUNITY.ESTIMATEDCLOSEDATE) as int)) DT_RANGE FROM "TNS-CRM-DWH" where year(F_OPPORTUNITY.ESTIMATEDCLOSEDATE) > 2009
Similar Messages
-
Year function reteives different values
SELECT year(convert(date,'24-10-49',5)) --dd-mm-yy
--2049
SELECT year(convert(varchar(10),'24-10-49',5)) --dd-mm-yy
--2049
SELECT year(convert(date,'24-10-50',5)) --dd-mm-yy
--1950
SELECT year(convert(varchar(10),'24-10-50',5)) --dd-mm-yy
--1950
Do we have any range for year function or do SQL server shows values to only limited period??Hello Vishal,
That depends on the "Two Digit Year Cutoff" of the SQL Server Setting, see
http://msdn.microsoft.com/en-us/library/ms191004.aspx
Olaf Helper
[ Blog] [ Xing] [ MVP] -
Hi everybody!
I am facing strange problem in OBIEE (server version 11.1.1.6). Adding logical column to fact table, that is derived from existing column using following expression:
FILTER("TT#1"."FACT"."TICKET_NUMBER" USING EXTRACT( YEAR FROM "TT#1"."FACT"."DATEREG") = "TT#1"."FACT"."YEAR")
where data types are
"FACT"."TICKET_NUMBER" - INT
"TT#1"."FACT"."DATEREG" - DATETIME
"TT#1"."FACT"."YEAR" - DOUBLE
So, I want to compare registration date and year for every record in fact table, and if registration date is within a year, then my new logical column will contain corresponding ticket number.
It works fine in OBIEE Report until I execute consistency check in BMM. Then Oracle BI Administration Tool informs me that consistency check fixed certain objects, but no errors, warnings or best practice violations left to report. And after that my logical column is marked with "fx" and calculation expression is emptied.
If I compare YEAR function with constant instead of column - check consistency passes fine. Neither changing data type of "TT#1"."FACT"."YEAR" to integer, nor using cast function changes situation.
Where am I wrong?Hi,
My OBIEE ver 11.1.1.5, As far as i know FILTER expression can only be used on Aggregate columns and is available only in Presentation.
example : FILTER ( SALES.QUANTITY USING(ORG.ORG_NAME = 'SILICON ASIA'))
The current scenario of Ticket Number is not a aggregate column so that will not work,and in BMM im not sure if you can use the FILTER expression.Try a CASE statement as a work around.
psuedo code
CASE WHEN
Year("TT#1"."FACT"."DATEREG_SET" ) = "TT#1"."FACT"."YEAR"
THEN
"TT#1"."FACT"."TICKET_NUMBER"
END
http://rampradeeppakalapati.blogspot.in -
Formating sysdate function output
Hi Gurus,
I'm doing a POC with BPEL and XMLPublisher and need the current date in a rtf template. I found the function <?xdofx:sysdate()?>, this output is not in the correct format and I need to reformat the sysdate output.
I also found the information about date formatting, but all this information refer to the field name. How could I reformat the sysdate function output?
Thanks in advance.Hi mcarlosro,
I hope you will be using form field method to place the sysdate....
Do one thing ...in form field choose the type as a date...or choose current date.... if you r choosing current date.. hen no need to give any code... but i will suggest you to go with this code whatever you are having for this field........ and choose type as a date and type format.. whatever you want...... you can type it there....
I hope it will help you.....
Regards
Ravi -
Trigger special function output type through a custom program
Hi,
I have to trigger the special function output type from a custom program.
This custom program contains a BAPI and the output parameters of this BAPI are required as input to the second BAPI which is contained in the form routine of the special function output type.
I am not able to understand how to trigger the special function as I dont know how the nast-objky will be updated
and how the BAPI parameters will be passed.
Is this has to be done through a Idoc
Can anyone guide me on how to handle the above functionality.Hello,
I am not able to understand your requirement completely...
agree with above post....addition-
1. Transport medium would be '8 - Special Function' where one program would fire and that can be used for further processing.
2. If condition record are maintained and it is matching with parameters then output type with all transport medium would be called
Thanks -
Special function Output type failing
Hi,
I configured a special function output type and set the dispatch time to 4. The output includes a custom program that executes a function module to create reservation. Its created in Form entry. However its failing to output when I save my order. Am I missing something? Can we not use submit programs with special function output types or dispatch time of 4?No. the OSS note doesn't help. I think the issue is with using dispatch time 4 instead of 1 for special function or maybe in the program code that I have:
FORM ENTRY USING RETURN_CODE TYPE I
US_SCREEN TYPE C.
DATA: L_VBELN LIKE VBAK-VBELN,
L_RSNUM LIKE RESB-RSNUM,
L_SUBRC LIKE SY-SUBRC.
CLEAR RETCODE.
if nast-objky is not initial.
l_vbeln = nast-objky.
CALL FUNCTION 'ZSD_RESERVATION_CREATE'
EXPORTING
VBELN = L_VBELN
IMPORTING
RSNUM = L_RSNUM
SUBRC = L_SUBRC.
else.
retcode = 1.
endif.
IF RETCODE NE 0.
RETURN_CODE = 1.
ELSE.
RETURN_CODE = 0.
ENDIF.
ENDFORM. -
MONTH and YEAR functions. Please help...
Can anyone tell me why the YEAR and MONTH functions will only accept the format dd-MMM-yyyy (ex. 01-JAN-2009)
The calendar prompt will only retun the format dd/mm/yyy (ex. 01/01/2009). This renders the calender pretty useless.
I am really in need of some help on this. Does anyone know how to get the value returned from the calendar in a prompt into a format that can be used by the YEAR and MONTH functions?
Thank you in advanceHi,
Can you do those things at DB Level.. addition of YEAR and MONTH columns to Table.. because doing CAST to DATE operation will work at DB Level..
Ex: In Answers if you give YEAR(CAST('01-03-2009' AS DATE)), it is erroring out because default allowed date format of BI is different from the one specified.. Though it is issuing correct SQL which is working at DB level.. donno how to change the default format of BI..
So, what I can suggest is an alternative, which is at DB level.. if it is apt for you.. then
Following statement gives you YEAR value..
TO_NUMBER(TO_CHAR( cast('01-03-2009' as DATE), 'yyyy'), '9999')
This is the statement taken from Manage Session of BI..
-Vency -
I have a UDF that converts float data into output, howevere, it add .01 in isolated cases.
The Input is as follows
<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_AMT xmlns:ns0="http://test.bob.com">
<SSN>123456789</SSN>
<DATA>PH80.00 170915.76 AAE</DATA>
</ns0:MT_AMT>
The out is as follows
<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_AMT1 xmlns:ns0="http://test.bob.com"><SSN>123456789</SSN><DATA>PH 80.00 170915.77AAE </DATA></ns0:MT_AMT1>
The code is as follows
MappingTrace mTrace = container.getTrace();
GlobalContainer globalContainer = container.getGlobalContainer();
globalContainer.setParameter("Value"," ");
//1.Map directly the source data to target data and make changes to below lengths.
StringBuffer sBuf = new StringBuffer(a);
// Correction : Make the length of sBuf equal to 21 in order to reduce the risk of runtime exception
if (sBuf.length() < 21) {
while (sBuf.length() != 21) {
sBuf.append(' ');
//2. Schedule Hours : Format the data into "ZZ9.99" at position 3-8
String substring = sBuf.substring(2, 8);
substring = formatNumber(substring, 4, 6, 2);
sBuf.replace(2, 8, substring);
//3. Base Rate : Format the data into "ZZZZZZ9.99" at position 9-29. The target position will be 9-18
substring = null;
substring = sBuf.substring(8, 29);
substring = formatNumber(substring, 8, 10, 2);
sBuf.replace(8, 18, substring.substring(0, 10));
sBuf.delete(18, 29);
//4. Performance Rating : For now no mapping is defined
//At last append 434 spaces to the record
sBuf = appendSpaces(sBuf, 434);
return sBuf.toString();
/*MappingTrace mTrace = container.getTrace();
/* mTrace.addInfo("Exception thrown = " + ex.getMessage() + ", Legacy Invoice Number: " + globalContainer.getParameter("INVOICENUMBER").toString() + ", " + interfaceName + ", " + lookUp + ", " + lookUpTable + ", " + keyString);
The below Function is for handling Trailer Records
private String trailerRecord(String a, int count) {
//1.Map directly the source data to target data and make changes to below lengths.
StringBuffer sBuf = new StringBuffer(a);
//2.Get the number of records from Global container and fill it at position 1-6
//Subtract 1 to exclude the trailer record
count = count - 1;
Integer counter = new Integer(count);
String substring = counter.toString();
//3.Format the number to ZZZZZ9 format
substring = formatNumber(substring, 7, 6, 0);
sBuf.replace(0, 6, substring.substring(0, 6));
//At last append 449 spaces to the record
sBuf = appendSpaces(sBuf, 449);
return sBuf.toString();
The below Function is for appending trailing spaces to the output record
private StringBuffer appendSpaces(StringBuffer sub, int num) {
for (int i = 0; i < num; i++) {
sub.append(' ');
return sub;
The below Function is for formatting numbers Records
private String formatNumber(
String input,
int position,
int length,
int decPlaces)
throws NumberFormatException {
//17.08.2007 : If empty string has come, send back the same
int int1 = input.lastIndexOf(' ');
int int2 = input.length();
if (int1 == int2) {
return input;
// position = actual position of dec place (e.g.4 for ZZ9.99)
//length = actual length (e.g. 6 for ZZ9.99)
//decPlaces = (e.g. 2 for ZZ9.99)
//First get the input converted into float and back so as to add a decimal sign if it does not exist
float f;
try {
f = Float.parseFloat(input);
} catch (NumberFormatException ex) {
throw new NumberFormatException(
"Exception Occurred:" + ex.getMessage());
StringBuffer sb = new StringBuffer(length);
sb.insert(0, f);
//Identify the position of decimal sign and then shift it gradually
int index = sb.indexOf(".");
if (index < position && index != -1) {
while (index < (position - 1)) {
sb.insert(0, " ");
index = sb.indexOf(".");
/*If there is no decimal sign, put one at the desired position
if(index == -1){
int int1 = Integer.parseInt(input);
sb.ins;
sb.insert(position,".");
//Fill blank spaces after decimal sign with zero
while (sb.length() < length) {
sb.append("0");
return sb.toString();
Any suggestions as to why this occurs? The additional .01.Hi !
Check this:
/people/thorsten.nordholmsbirk/blog/2006/04/03/never-ever-use-xis-built-in-arithmetic-functions
how to Convert the STRING TO FLOAT.
Regards,
Matias
ps: please award points if helpful -
Best way to send an procedure/function output to the application
Hello,
What is the best way to send the output of a PL/SQL function / procedure to the application in Oracle 11g. I understand that it could be different for applications built in JAVA , .Net , SAP etc.
Could you please give a brief overview on all possible application makes.
Thanks,
HaiderAnyway, the answer is yes, v$version is derived from x$version :
SQL> desc x$version
Name Null? Type
ADDR RAW(8)
INDX NUMBER
INST_ID NUMBER
BANNER VARCHAR2(80)
SQL> select INDX,BANNER from x$version;
INDX
BANNER
0
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
1
PL/SQL Release 11.2.0.3.0 - Production
2
CORE 11.2.0.3.0 Production
3
TNS for Linux: Version 11.2.0.3.0 - Production
4
NLSRTL Version 11.2.0.3.0 - Production
SQL> -
Selecting Single Rows that match to a column within group function output
Trying to write a Query that will look through a data set that will return the Barcodes of CompoundNames that have a summed Quantity > 500.
So if it was ran against the sample table below the output would be
0005
0006
0007
0008
0009
0010
Barcode, CompoundName, BatchId, Quantity
0001, XE 1000, XE 1000 100, 100
0002, XE 1000, XE 1000 101, 100
0003, XE 1000, XE 1000 102, 100
0004, XE 1000, XE 1000 103, 100
0005, XE 2000, XE 2000 100, 100
0006, XE 2000, XE 2000 101, 100
0007, XE 2000, XE 2000 102, 100
0008, XE 2000, XE 2000 103, 100
0009, XE 2000, XE 2000 104, 100
0010, XE 2000, XE 2000 105, 100
0011, XE 3000, XE 3000 100, 100
I've got this far
Select CompoundName, SUM(QUANTITY) FROM Table
GROUP BY CompoundName
HAVING SUM(QUANTITY) > 500)
order by compoundname;
But I need each Barcode that corresponds to each batchid when the summed quantity of the batches is > 500.
TIAReplacing a GROUP BY Aggregate function by analytic equivalent (using PARTITION BY)
will return every ROW (limited by where clause) but will not perform
actual "aggregation operation.
So it is possible that *selected result set* could contain duplicate row. Of course it depends on columns being seected and input data.
+Ofcourse OPs sample data returns the same result with or without DISTINCT+
For example...
*WITH DISTINCT*
{code}
sudhakar@ORCL>with t1 as
2 (select 0001 barcode,'XE0000' COMPOUNDNAME, 700 quantity FROM DUAL UNION ALL
3 select 0003 ,'XE1000' , 20 FROM DUAL UNION ALL
4 select 0003 ,'XE1000' , 280 FROM DUAL UNION ALL
5 select 0003 ,'XE2000' , 50 FROM DUAL UNION ALL
6 select 0003 ,'XE2000' , 100 FROM DUAL UNION ALL
7 select 0003 ,'XE2000' , 150 FROM DUAL UNION ALL
8 select 0003 ,'XE2000' , 200 FROM DUAL UNION ALL
9 select 0003 ,'XE2000' , 750 FROM DUAL UNION ALL
10 select 0003 ,'XE2000' , 120 FROM DUAL UNION ALL
11 select 0003 ,'XE1000' , 70 FROM DUAL
12 )
13 select distinct * from
14 (
15 Select Barcode, CompoundName, SUM(QUANTITY) over (partition by CompoundName) sumqty
16 FROM t1
17 )
18 where sumqty > 500
19 order by compoundname;
BARCODE COMPOU SUMQTY
1 XE0000 700
3 XE2000 1370
sudhakar@ORCL>
{code}
*WITHOUT DISTINCT*
{code}
sudhakar@ORCL>with t1 as
2 (select 0001 barcode,'XE0000' COMPOUNDNAME, 700 quantity FROM DUAL UNION ALL
3 select 0003 ,'XE1000' , 20 FROM DUAL UNION ALL
4 select 0003 ,'XE1000' , 280 FROM DUAL UNION ALL
5 select 0003 ,'XE2000' , 50 FROM DUAL UNION ALL
6 select 0003 ,'XE2000' , 100 FROM DUAL UNION ALL
7 select 0003 ,'XE2000' , 150 FROM DUAL UNION ALL
8 select 0003 ,'XE2000' , 200 FROM DUAL UNION ALL
9 select 0003 ,'XE2000' , 750 FROM DUAL UNION ALL
10 select 0003 ,'XE2000' , 120 FROM DUAL UNION ALL
11 select 0003 ,'XE1000' , 70 FROM DUAL
12 )
13 select * from
14 (
15 Select Barcode, CompoundName, SUM(QUANTITY) over (partition by CompoundName) sumqty
16 FROM t1
17 )
18 where sumqty > 500
19 order by compoundname;
BARCODE COMPOU SUMQTY
1 XE0000 700
3 XE2000 1370
3 XE2000 1370
3 XE2000 1370
3 XE2000 1370
3 XE2000 1370
3 XE2000 1370
7 rows selected.
sudhakar@ORCL>
{code}
vr,
Sudhakar B. -
I am trying to output file in CSV format. Everything works beautifully except Fiscal_date (format yyyymm); with cutoff on Sept of each year.
I have codes that "interpret" the *:control.begin_date* (format yyyymmdd); if it's Sept, it'll be 201201. I also have variable Fiscal_date varchar(6) and if statements where if mm is (01, 02, etc) then fiscal_date will be yyyy||01, 02, etc. The output will always in a monthly basis and no overlaps of month; which means it'll always be something like 201102, 201103, etc.
if substr(to_char(:control.begin_date),5,2) = '01' then Fiscal_date := substr(to_char(:control.begin_date),1,4)||'05' ;
elsif substr(to_char(:control.begin_date),5,2) = '02' then Fiscal_date := substr(to_char(:control.begin_date),1,4)||'06';
elsif substr(to_char(:control.begin_date),5,2) = '03' then Fiscal_date := substr(to_char(:control.begin_date),1,4)||'07';
elsif substr(to_char(:control.begin_date),5,2) = '04' then Fiscal_date := substr(to_char(:control.begin_date),1,4)||'08';
elsif substr(to_char(:control.begin_date),5,2) = '05' then Fiscal_date := substr(to_char(:control.begin_date),1,4)||'09';
elsif substr(to_char(:control.begin_date),5,2) = '06' then Fiscal_date := substr(to_char(:control.begin_date),1,4)|| '10';
elsif substr(to_char(:control.begin_date),5,2) = '07' then Fiscal_date := substr(to_char(:control.begin_date),1,4)||'11';
elsif substr(to_char(:control.begin_date),5,2) = '08' then Fiscal_date := substr(to_char(:control.begin_date),1,4)||'12';
elsif substr(to_char(:control.begin_date),5,2) = '09' then Fiscal_date := substr(to_char(:control.begin_date),1,4)+1|| '01';
elsif substr(to_char(:control.begin_date),5,2) = '10' then Fiscal_date := substr(to_char(:control.begin_date),1,4)+1||'02';
elsif substr(to_char(:control.begin_date),5,2) = '11' then Fiscal_date := substr(to_char(:control.begin_date),1,4)+1||'03';
elsif substr(to_char(:control.begin_date),5,2) = '12' then Fiscal_date := substr(to_char(:control.begin_date),1,4)+1||'04';
message('Fiscal_date : '||Fiscal_date );
end if;The output message is always nothing.
Open to suggestions of better way of doing it or to resolve the problem.
Thanks.substr(to_char(:control.begin_date),5,2)Do you really want to rely on the default date format mask? Do you really think it is always the same? Better yet specify the format mask you are expecting, as I doubt the default format mask is YYYYMMDD and you are using a complete different number as you think you do:
substr(to_char(:control.begin_date, 'YYYYMMDD'),5,2)or maybe
CHE_TEST@tcp_asterix_impl> exec dbms_output.put_line(extract(month from sysdate));
11
PL/SQL procedure successfully completed.Which will return you a number (I haven't tested if extract works in forms right now, but there is no point that this cannot be a stored procedure).
This will also work for days and years:
CHE_TEST@tcp_asterix_impl> r
1 select extract(day from sysdate) day,
2 extract(month from sysdate) month,
3 extract(year from sysdate) year
4* from dual
DAY| MONTH| YEAR
----------|----------|----------
21| 11| 2011cheers -
Function output in a select statement
I have written a function(get_cols) which returns the following string (this string is created dynamically from the fuctions depending on the rows of the tables)
the output of the function is;
MAX (CASE WHEN field_code = 'test_pho' THEN VALUE END ) AS test_pho
,MAX (CASE WHEN field_code = 'ESN' THEN VALUE END ) AS ESN
,MAX (CASE WHEN field_code = 'IMSI' THEN VALUE END ) AS IMSI
,MAX (CASE WHEN field_code = 'PHONE_NO' THEN VALUE END ) AS PHONE_NO
What I need to do is to use this as it is in a another select statement like;
(1)
select
empno,
MAX (CASE WHEN field_code = 'test_pho' THEN VALUE END ) AS test_pho
,MAX (CASE WHEN field_code = 'ESN' THEN VALUE END ) AS ESN
,MAX (CASE WHEN field_code = 'IMSI' THEN VALUE END ) AS IMSI
,MAX (CASE WHEN field_code = 'PHONE_NO' THEN VALUE END ) AS PHONE_NO
from my_employee e, my_columns c
where e.emp_no = c.emp_no
and c.emp_no = '100003'
group by empno
function returns the correct output, but when i call the function in the select like below it get it as a whole string and doesn't give the correct output
(2)
select empno, get_cols('100003')
from my_employee e, my_columns c
where e.emp_no = c.emp_no
and c.emp_no = '100003'
how can i get the output of the function to the select as separate line as shown is above(1)
When I get the above output separately and give in the select as above (1) it gives the correct output I want ??
any help pleasejosleen wrote:
Hi BluShadow,
Your solution seem interesting. Can you explain how can this be used to produce the required output ? Do we need to maintain a separate my_columns table ?Not quite sure what you are asking?
As with any query, the output columns have to be defined at design time, you cannot have the number of columns dynamically generated based on the data. So, if you said you wanted to pivot data from rows to columns and the number of possible values in those rows could change, you cannot pivot those to columns unless you are expecting those values or have allowed for maximum number of values.
Basic example... Let say we have the following data:
SQL> select * from dept;
DEPTNO DNAME LOC
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTONAnd we want to pivot that data to put the departments as columns rather than rows. We can simply do something like:
SQL> ed
Wrote file afiedt.buf
1 select max(decode(deptno,10,dname)) as dname_10
2 ,max(decode(deptno,10,loc)) as loc_10
3 ,max(decode(deptno,20,dname)) as dname_20
4 ,max(decode(deptno,20,loc)) as loc_20
5 ,max(decode(deptno,30,dname)) as dname_30
6 ,max(decode(deptno,30,loc)) as loc_30
7 ,max(decode(deptno,40,dname)) as dname_40
8 ,max(decode(deptno,40,loc)) as loc_40
9* from dept
SQL> /
DNAME_10 LOC_10 DNAME_20 LOC_20 DNAME_30 LOC_30 DNAME_40 LOC_40
ACCOUNTING NEW YORK RESEARCH DALLAS SALES CHICAGO OPERATIONS BOSTON
SQL>However if a further department is added:
SQL> insert into dept values (50, 'IT SUPPORT', 'LONDON');
1 row created.
SQL> select max(decode(deptno,10,dname)) as dname_10
2 ,max(decode(deptno,10,loc)) as loc_10
3 ,max(decode(deptno,20,dname)) as dname_20
4 ,max(decode(deptno,20,loc)) as loc_20
5 ,max(decode(deptno,30,dname)) as dname_30
6 ,max(decode(deptno,30,loc)) as loc_30
7 ,max(decode(deptno,40,dname)) as dname_40
8 ,max(decode(deptno,40,loc)) as loc_40
9 from dept
10 /
DNAME_10 LOC_10 DNAME_20 LOC_20 DNAME_30 LOC_30 DNAME_40 LOC_40
ACCOUNTING NEW YORK RESEARCH DALLAS SALES CHICAGO OPERATIONS BOSTON
SQL>we obviously don't get to see the new data, unless we change our query to add this expected additional column(s) in...
SQL> ed
Wrote file afiedt.buf
1 select max(decode(deptno,10,dname)) as dname_10
2 ,max(decode(deptno,10,loc)) as loc_10
3 ,max(decode(deptno,20,dname)) as dname_20
4 ,max(decode(deptno,20,loc)) as loc_20
5 ,max(decode(deptno,30,dname)) as dname_30
6 ,max(decode(deptno,30,loc)) as loc_30
7 ,max(decode(deptno,40,dname)) as dname_40
8 ,max(decode(deptno,40,loc)) as loc_40
9 ,max(decode(deptno,50,dname)) as dname_50
10 ,max(decode(deptno,50,loc)) as loc_50
11* from dept
SQL> /
DNAME_10 LOC_10 DNAME_20 LOC_20 DNAME_30 LOC_30 DNAME_40 LOC_40 DNAME_50 LOC_50
ACCOUNTING NEW YORK RESEARCH DALLAS SALES CHICAGO OPERATIONS BOSTON IT SUPPORT LONDON
SQL>Now, rather than having a messy SQL statment with lots of max(decode... statements we can provide a pipelined function to return the same thing...
SQL> ed
Wrote file afiedt.buf
1 CREATE OR REPLACE TYPE mydepts AS OBJECT
2 ( dname_10 VARCHAR2(14),
3 loc_10 VARCHAR2(13),
4 dname_20 VARCHAR2(14),
5 loc_20 VARCHAR2(13),
6 dname_30 VARCHAR2(14),
7 loc_30 VARCHAR2(13),
8 dname_40 VARCHAR2(14),
9 loc_40 VARCHAR2(13),
10 dname_50 VARCHAR2(14),
11 loc_50 VARCHAR2(13)
12* )
13 /
Type created.
SQL> ed
Wrote file afiedt.buf
1* CREATE OR REPLACE TYPE mydepttable AS TABLE OF mydepts
SQL> /
Type created.
SQL> ed
Wrote file afiedt.buf
1 CREATE OR REPLACE FUNCTION alldepts RETURN mydepttable PIPELINED IS
2 v_obj mydepts := mydepts(NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
3 CURSOR cur_depts IS
4 select deptno, dname, loc from dept;
5 BEGIN
6 FOR i IN cur_depts
7 LOOP
8 CASE i.deptno
9 WHEN 10 THEN v_obj.dname_10 := i.dname; v_obj.loc_10 := i.loc;
10 WHEN 20 THEN v_obj.dname_20 := i.dname; v_obj.loc_20 := i.loc;
11 WHEN 30 THEN v_obj.dname_30 := i.dname; v_obj.loc_30 := i.loc;
12 WHEN 40 THEN v_obj.dname_40 := i.dname; v_obj.loc_40 := i.loc;
13 WHEN 50 THEN v_obj.dname_50 := i.dname; v_obj.loc_50 := i.loc;
14 ELSE NULL;
15 END CASE;
16 END LOOP;
17 PIPE ROW (v_obj);
18 RETURN;
19* END;
SQL> /
Function created.
SQL> select *
2 from table(alldepts());
DNAME_10 LOC_10 DNAME_20 LOC_20 DNAME_30 LOC_30 DNAME_40 LOC_40 DNAME_50 LOC_50
ACCOUNTING NEW YORK RESEARCH DALLAS SALES CHICAGO OPERATIONS BOSTON IT SUPPORT LONDON
SQL>So, now there is a single function that acts like a table and does the functionality of pivoting the data. What the function actually does to generate the data is entirely up to you whether that is obtaining data from different tables or some PL/SQL code processing to perform some complex algorithmic type thing on the data from a passed in parameter etc. The point of the pipeline function is that it can return multiple columns of data and act as if it is a table that can be queried against, however it still remains that the output columns must be known at design time. This is actually a requirement of the SQL engine, as you cannot make a dynamic function that returns X number of columns based on data.
There is however a technique that can allow you to dynamically generate a number of columns based on data, but it involves getting a little more under the hood of Oracle and interfacing with the ODCI interface, actually using a pipelined funcion technique in conjunction with, in laymans terms, stepping in at the point the query is executing and telling oracle what columns this pipelined function is going to return, but at the same time as defining the returned columns.
An example of doing this is given by AScheffer on this thread: How to pipeline a function with a dynamic number of columns?
... but you really are getting into a complex world if you try and write your queries this way, just to try and make generic queries with dynamic columns.
In essence, the actual business need to actually return a dynamic number of columns is very slim as most applications, whether that is a user facing interface or report generator etc. will be expecting certain data columns to be returned to expected columns or fields within them. If you really want to dynamically pivot data with an unknown number of columns it is usually best to let things like reporting tools deal with this area as that is what they are best at, and don't try and do it within SQL. -
Hi!
I'm trying to get output parameters from a function, (not a
return value). Does somebody know if this is posible? (an example
is posted below)
thanks in advance
var x,y,z;
x = "equis";
ff(x,y);
trace(y) // -> undefined; y is never asigned in ff
function ff(x,y){
y = x + " yy";
}There you go:
var Obj:Object = new Object();
Obj.x = "equis";
Obj.y = undefined;
Obj.z = undefined;
ff(Obj);
trace(Obj.y);
function ff(Obj:Object):Void {
Obj.y = Obj.x+" yy";
Objects and Arrays pass references to them not their values
Cheers
Gorka -
Hi all !
Is there any way(function) to find out a new year in sql / plsql ?
Pls help me with a solution ..
Thanks and Regards
user 10685325Hi !
Thanks for ur replies ..
For testing purpose, i created a procedure in sql editor. .the coding i used is
1 CREATE OR REPLACE PROCEDURE bal_up (cl IN VARCHAR2) AS
2 BEGIN
3 UPDATE bal_assign set existing_balance = 8 WHERE leavetype = cl;
4* END bal_up;
5 /
Procedure created.
SQL> call bal_up('Casual Leave');This is working.. In order to schedule the job, i tried using the following codings, which gave me the corresponding errors shown
SQL>
1 declare
2 l_job number;
3 begin
4 dbms_job.submit( l_job,
5 call bal_up('Casual Leave');,
6 add_months(trunc(sysdate,'YEAR'),0)+16.05/24);/*Here i have added '0' instead of '12' for testing*/
7* end;
8 /
call bal_up('Casual Leave');,
ERROR at line 5:
ORA-06550: line 5, column 23:
PLS-00103: Encountered the symbol "BAL_UP" when expecting one of the followin
. ( ) , * @ % & | = - + < / > at in is mod remainder not
range rem => .. <an exponent (**)> <> or != or ~= >= <= <>
and or like LIKE2_ LIKE4_ LIKEC_ between || multiset member
SUBMULTISET_
The symbol "." was substituted for "BAL_UP" to continue.
ORA-06550: line 5, column 45:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
. ( ) , * % & | = - + < / > at in is mod remainder not range
rem => .. <an exponent (**)> <> or != or ~= >= <= <> and or
like LIKE2_ LIKE4_ LIKEC_ betwee
SQL> ed
Wrote file afiedt.buf
1 declare
2 l_job number;
3 begin
4 dbms_job.submit( l_job,
5 'bal_up('Casual Leave');',
6 add_months(trunc(sysdate,'YEAR'),0)+16:20:00/24);/*Here i have added '0' instead of '12' for testing*/
7* end;
8 /
SP2-0552: Bind variable "20" not declared.
SQL> ed
Wrote file afiedt.buf
1 declare
2 l_job number;
3 begin
4 dbms_job.submit( l_job,
5 'bal_up('Casual Leave');',
6 add_months(trunc(sysdate,'YEAR'),0)+17/24);/*Here i have added '0' instead of '12' for testing*/
7* end;
8 /
'bal_up('Casual Leave');',
ERROR at line 5:
ORA-06550: line 5, column 25:
PLS-00103: Encountered the symbol "CASUAL" when expecting one of the followin
) , * & | = - + < / > at in is mod remainder not rem => ..
<an exponent (**)> <> or != or ~= >= <= <> and or like LIKE2_
LIKE4_ LIKEC_ between || multiset member SUBMULTISET_
SQL> ed
Wrote file afiedt.buf
1 declare
2 l_job number;
3 begin
4 dbms_job.submit( l_job,
5 'bal_up(Casual Leave);',
6 add_months(trunc(sysdate,'YEAR'),0)+17/24); /*Here i have added '0' instead of '12' for testing*/
7* end;
8 /
declare
ERROR at line 1:
ORA-06550: line 1, column 107:
PLS-00103: Encountered the symbol "LEAVE" when expecting one of the following
. ( ) , * @ % & | = - + < / > at in is mod remainder not
range rem => .. <an exponent (**)> <> or != or ~= >= <= <>
and or like LIKE2_ LIKE4_ LIKEC_ as between from using ||
multiset member SUBMULTISET_
The symbol "." was substituted for "LEAVE" to continue.
ORA-06512: at "SYS.DBMS_JOB", line 79
ORA-06512: at "SYS.DBMS_JOB", line 136
ORA-06512: at line 4Pls help to overcome this ..
Thanks and Regards
user 10685325 -
Function output (Return sys_refcursor) to excel sheet
Hi,
Could pls anyone let me know how to export the output of a function returning sys_refcursor to excel sheet
with headers.
Tried with file handling but no luck.
Below is my function.
create or replace function fn1 return sys_refcursor as
cv_1 SYS_REFCURSOR;
begin
open cv_1 for select * from tab;
return cv_1;
end;Small example will hlp me a lot.
Thanks in advanceunique wrote:
Hi,
Could pls anyone let me know how to export the output of a function returning sys_refcursor to excel sheet
with headers.
Tried with file handling but no luck.
Below is my function.
create or replace function fn1 return sys_refcursor as
cv_1 SYS_REFCURSOR;
begin
open cv_1 for select * from tab;
return cv_1;
end;Small example will hlp me a lot.
Thanks in advance
create or replace function fn1 return sys_refcursor as
cv_1 SYS_REFCURSOR;
begin
open cv_1 for
(select 'headings for each column' from dual
union all
select to_char(all_columns) from tab);
return cv_1;
end;
Maybe you are looking for
-
Can I get rid of FCE 1.0.1 ?
Forgive me if this is a foolish question but I was surprised when I upgraded to FCE 3.5 my FCE 1.0.1 remained in my applications folder. I doubt I will ever run that program since it's PowerPC so can I uninstall it without affecting my new version? I
-
How to know if firefox is using a master password from a some programming language?
I am working in a security check project and I need know from an programming language or open some file if firefox is using a master password.
-
SQL Loader - double quote within data
Hi, I'm putting together some SQL loader scripts to load source data into a DB. The data we are receiving is comma delimited, optionally enclosed by double quotes ("). e.g. "abc","123","this is a "test"","987" The problem I've got is that some data i
-
How to put focus into a particular TextItem ?
Hi all, I have a Form into which there are two TextFields, say name and adress. After adding a record in that screen I go to another screen. And when I return to the first screen then the cursor is at the last item. So how to put the cursor at the fi
-
What are you views on te Dual Core A5 chip?, I'm using it now ith iPad
What are your thoughts?!