|
Re: Select approved/rejected for each Role if N° of roles can change [message #542588 is a reply to message #542586] |
Wed, 08 February 2012 02:49   |
 |
Michel Cadot
Messages: 68548 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
For any SQL question, Post a working Test case: create table and insert statements along with the result you want with these data then we will be able work with your table and data. Explain with words and sentences the rules that lead to this result.
In addition, this has been asked and answered many times and the answer is: it is not possible in pure SQL.
But it possible with a function that returns a ref cursor.
Regards
Michel
[Updated on: Wed, 08 February 2012 02:50] Report message to a moderator
|
|
|
|
Re: Select approved/rejected for each Role if N° of roles can change [message #542664 is a reply to message #542591] |
Wed, 08 February 2012 07:34   |
c_stenersen
Messages: 255 Registered: August 2007
|
Senior Member |
|
|
Also in Apex it's possible to build the query dynamically and return it as a varchar2 variable. When you have this requirement for it to be possible that the number/names of the columns are different at any time you will have to make sure that you pick "Use Generic Column Names (parse query at runtime only)" in the radiobutton shown below the source field. If you then have in your report attributes "Column Names (InitCap)" chosen, you could use the role name as an alias for your columns, and that would be what is shown as a column header in Apex.
|
|
|
|
|
|
|
|
Re: Select approved/rejected for each Role if N° of roles can change [message #542680 is a reply to message #542676] |
Wed, 08 February 2012 09:45   |
 |
balckbandit5
Messages: 104 Registered: December 2011
|
Senior Member |
|
|
Hi, I'm having a problem with it. I've got my item P3_QUERY with source type "SQL query (returning colon separated values)"
SELECT REPLACE(MAX(SYS_CONNECT_BY_PATH(', (select pmr.IS_APPROVED
from PMO_PROJECT_MILESTONE_REVIEW pmr
where pmr.PROJECT_MILESTONE_ID = pm.PROJECT_MILESTONE_ID
and = '||rr.ROLE_ID||' '||rr.ROLE_CODE , '*')), '*', '') conc
FROM
(SELECT rr.ROLE_ID,
rr.ROLE_CODE,
ROW_NUMBER() OVER (ORDER BY rr.ROLE_ID) R
FROM PMO_ROLE rr
) rr
START WITH r =1
CONNECT BY PRIOR r = r-1;
which is giving the result:, (select pmr.IS_APPROVED
from PMO_PROJECT_MILESTONE_REVIEW pmr
where pmr.PROJECT_MILESTONE_ID = pm.PROJECT_MILESTONE_ID
and = 1 R1, (select pmr.IS_APPROVED
from PMO_PROJECT_MILESTONE_REVIEW pmr
where pmr.PROJECT_MILESTONE_ID = pm.PROJECT_MILESTONE_ID
and = 2 R2, (select pmr.IS_APPROVED
from PMO_PROJECT_MILESTONE_REVIEW pmr
where pmr.PROJECT_MILESTONE_ID = pm.PROJECT_MILESTONE_ID
and = 3 R3
Which I think is right
And then I have my query for the report:
DECLARE
v_query varchar2(1000);
BEGIN
IF :P3_QUERY is not null THEN
v_query := 'select pm.PROJECT_MILESTONE_ID, cp.CHECKPOINT_NAME, pm.MILESTONE_DATE' ||
:P3_QUERY ||' from PMO_PROJECT_MILESTONE pm, PMO_CHECKPOINT cp where pm.PROJECT_ID = ' ||
:P3_PROJECT_ID ||' and cp.checkpoint_code = pm.checkpoint_code';
ELSE
v_query := 'SELECT 1 FROM dual WHERE 1=0';
END IF;
return(v_query);
END;
but i'm getting the error:
failed to parse SQL query:
ORA-00921: unexpected end of SQL command
where the report should be...
is there an obvious problem I'm missing orr..?
thanks
[Updated on: Thu, 09 February 2012 13:30] by Moderator Report message to a moderator
|
|
|
|
Re: Select approved/rejected for each Role if N° of roles can change [message #542699 is a reply to message #542685] |
Thu, 09 February 2012 14:45   |
c_stenersen
Messages: 255 Registered: August 2007
|
Senior Member |
|
|
What I can see immediately is that you have several opening parentheses, but no closing ones. Also you have for instance "and = 1" which would cause an error. What I normally do for these things is that I copy and paste the whole code into a pl/sql region and then wrap the return value in a htp.p instead of return (maybe also surrounded by pre tags to keep the indentation), so in your case htp.p('<pre>' || v_query || '</pre>')
|
|
|
Re: Select approved/rejected for each Role if N° of roles can change [message #542705 is a reply to message #542699] |
Thu, 09 February 2012 16:28   |
c_stenersen
Messages: 255 Registered: August 2007
|
Senior Member |
|
|
Just another comment.
where pm.PROJECT_ID = ' ||
:P3_PROJECT_ID ||' and cp.checkpoint_code = pm.checkpoint_code'
should be replaced by:
where pm.PROJECT_ID = :P3_PROJECT_ID and cp.checkpoint_code = pm.checkpoint_code'
Note that I removed the concatenation of the value of :P3_PROJECT_ID and rather just put in the variable name in the string. The real value will be substituted by apex itself when it runs your query (as a dynamic query with a bind variable).
|
|
|
|
|
|
|
Re: Select approved/rejected for each Role if N° of roles can change [message #544786 is a reply to message #544749] |
Thu, 23 February 2012 15:50   |
c_stenersen
Messages: 255 Registered: August 2007
|
Senior Member |
|
|
The size of the item shouldn't matter. That is more related to the display and to what the user can type on the screen. What can actually be held in it is not defined by you. I believe that the limit is 4000. After experimenting a bit I see that the value you return for the source of the query can anyways be max 4000 characters so even if you used two items you wouldn't be able to just concatenate them and return them like that to make the query source bigger. If you can have lots and lots and lots of these milestones I think you should go for building a pl/sql region for showing it.
|
|
|
Re: Select approved/rejected for each Role if N° of roles can change [message #544823 is a reply to message #544786] |
Fri, 24 February 2012 02:45   |
 |
balckbandit5
Messages: 104 Registered: December 2011
|
Senior Member |
|
|
I copy - pasted my query to word to see how many characters were being returned and it's already over 4000 (4594 without spaces, 5171 with) So I don't think the limit is 4000...or if it is it must be counting the "|| :P1_QUERY ||" as those 15 characters rather than the 3500 odd that the item is holding...
[UPDATE] TEST: I just created a copy of P1_QUERY (P1_QUERYY) and concatenated it in the report query source and it actually worked fine, I had 12 roles in the table (2 of each I have currently). So I think actually just having 2 or 3 items and concatenating them all would work...
[Updated on: Fri, 24 February 2012 02:55] Report message to a moderator
|
|
|
Re: Select approved/rejected for each Role if N° of roles can change [message #544832 is a reply to message #544823] |
Fri, 24 February 2012 03:27   |
c_stenersen
Messages: 255 Registered: August 2007
|
Senior Member |
|
|
Ok, but in that case you could create a varchar2 variable of length 32767 and compute the whole query in your query procedure instead of using a page item. If you want to use 3 or 4 page items you would have the problem you're mentioning where you'd have to distribute your query in such a way that you cover all checkpoints, but each of them just once. It would be a lot easier to build the query in your report source instead.
|
|
|
|
|
|
|