¶m lexical variable in SELECT clause
Is there a way to get Oracle*Reports to accept a lexical variable in the SELECT clause? The example is:
SELECT
table.column1,
table.column2,
&PARAM as column3
FROM
table
I am already using lexical variables in the WHERE clause, but getting one to work in the SELECT clause has thus far failed.
The SQL is accepted if :PARAM is used in place of &PARAM, but I am unable to actually vary the selected column this way.
The bind variable PARAM has the following code behind it in a BeforeReport trigger:
IF :ANOTHER_PARAM := 'ALL' THEN
:PARAM = 'ALL'
ELSE
:PARAM = 'table.column3'
When using :PARAM in the SELECT clause, the literals 'table.column3' are returned, not the contents of table.column3.
Sorry for the wasted bandwidth. I found a solution. Here it is:
SELECT
table.column1,
table.column2,
CASE :P_USER
WHEN 'ALL' THEN 'ALL'
ELSE table.column3
END as column3
Similar Messages
-
Dynamic SELECT clause using lexical param
Aloha all.
I've been working with Report 6i for a while now, but was
wondering if anyone had success using lexical parameters in the
SELECT clause. I've done it in the WHERE clause many times.
Here's what I want to do:
select &column_list from &table_list where &cond_list
where &column_list will be a dynamic number of columns. I know
you can do this, but how do you display the dynamic columns back
to the report?
Thanks in advance.
Floyd CasemYou can pass each column as a parameter:
select
&p_column1 column1,
&p_column2 column2,
from &p_table table
&p_where
You will of course have to find a way of hiding the not needed
columns, but I think it can work with a little bit of work. -
How to use a lexical variable in a WHERE clause and as a function argument.
Hello,
My report has a lexical variable which has values like 'and id in (1,3,4)'. I want to use this variable in two separate queries. In the first, it is used in the WHERE clause, something like:
.. where date is not null &var;
In the second query, the variable is used in a function call, something like:
select * from table (my_function(&var));
The trouble is that the first query works when the value of the variable is unquoted, but for the second query the value should be quoted.
Does anyone have an idea how I could solve this problem?
Thanks in advance,
Frans
Message was edited by:
fransiehttp://tkyte.blogspot.com/2006/06/varying-in-lists.html
Presents many options. -
Merge can't accept a variable in the select clause?
oracle 10.2
I have a stored procedure.
I have a variable, vseq, which I set a sequence variable. With all other sql statements I can do
insert into table a
select vseq
from dual;
Apparently a merge can't handle variables in the select clause. I get an error. I can get it to work when I hard code a value.
this is ridiculous...merge can't handle variables in the select clauseCare to prove?
sql> DECLARE
2 v_first_name varchar2(20) := 'BOSS';
3 BEGIN
4 MERGE INTO sun_employees se
5 USING (SELECT * FROM employees WHERE department_id = 20) e
6 ON (e.employee_id = se.employee_id)
7 WHEN MATCHED THEN
8 UPDATE SET salary = e.salary
9 WHEN NOT MATCHED THEN
10 INSERT(employee_id, first_name, last_name, department_id)
11 VALUES (e.employee_id, v_first_name, e.last_name, e.department_id);
12 END;
13 /
PL/SQL procedure successfully completed.
sql> select first_name from sun_employees;
FIRST_NAME
BOSS
BOSS -
Using bind variable with IN clause
My application runs a limited number of straight up queries (no stored procs) using ODP.NET. For the most part, I'm able to use bind variables to help with query caching, etc... but I'm at a loss as to how to use bind variables with IN clauses. Basically, I'm looking for something like this:
int objectId = 123;
string[] listOfValues = { "a", "b", "c"};
OracleCommand command = new OracleCommand();
command.Connection = conn;
command.BindByName = true;
command.CommandText = @"select blah from mytable where objectId = :objectId and somevalue in (:listOfValues)";
command.Parameters.Add("objectId", objectId);
command.Parameters.Add("listOfValues", listOfValues);
I haven't had much luck yet using an array as a bind variable. Do I need to pass it in as a PL/SQL associative array? Cast the values to a TABLE?
Thanks,
NickNevermind, found this
How to use OracleParameter whith the IN Operator of select statement
which contained this, which is a brilliant solution
http://oradim.blogspot.com/2007/12/dynamically-creating-variable-in-list.html -
Variable in where clause of the logical table
Hi,
is it possible to define a variable in "where" clause of rpd's physical table (table type - select)? If yes, pls elaborate the steps including how to refresh it with every end user's request?
Thanks and Regards,
Igor
P.S.
If not, is there any workaround?Nico
thanks, but I am afraid that is not my case. I need to refresh variable value interactively with every query by a dashboard prompt. To illustrate my need just imagine a recursive SQL (defined as a view/logical table in rpd):
SELECT ....
FROM ...
WHERE ...
START WITH .... columnA=variable1
CONNECT BY PRIOR .... and columnB=varariable2;
or
SELECT c1,c2,c3,c4 from tabA where c1='A' and c2=variable1
union
SELECT c1,c2,c3,c4 from tabA where c1='A" and c2='D' and c1 NOT IN ( SELECT c1 FROM tabA where c1='A' and c2=variable1 );
So, what I want to do is to pass value(s) to my variable(s) every time when respective select (view) is executed. I see above selects are not typical ones the OBI EE is intended for but nevertheless I wonder if such kind of reports are possible to do in OBI EE.
Thanks and Regards,
Igor -
On Lexical variables: Are they always treated as user parameters???
Hi
Report Developer 10g, Winodws XP platform, local client
I have a dynamic where clause in my report query with a lexical variable &p_where which holds the where clause. This where clause is determined at runtime, depending on the user parameter value that was entered.
My problem is, the lexical variable &p_where is automatically added to the list of my user parameters and does show up in my parameter form, when the report is run. This will cause lot of confusion to the user, as it is not part of user input.
It is not a user parameter, but should be treated as a regular variable. How do I work around this?
Thanks
SumaI understand. The lexical variable was automatically added to the user parameters list upon it having appeared in a query.
This is expected. The lexical variable must be defined. Since it is not a system parameter, Oracle*Reports added it to the user parameter list.
But if it is also showing up on your user parameter FORM (the form which solicits input from the user prior to running the report), it can simply be deleted from that form without affecting its use in the query.
Regards,
Steve -
Boolean variable in where clause
Hello,
Does anyone know if it possible to include
BOOLEAN variable in where clause as following:
is_in_group BOOLEAN;
begin
is_in_group :=
portal30.wwsec_api.is_user_in_group (
p_person_id => portal30.wwctx_api.get_user_id,
p_group_id => portal30.wwsec_api.group_id('GROUPNAME')
for x in(select start_time,title
from ec_reservations
where
start_time >= '2004-JAN-01'
and rv_target_type='PU'
and is_in_group = true
Thank You,
HelenaWell, let's try it, eh?
SQL> conn scott/tiger
Connected.
SQL> CREATE OR REPLACE FUNCTION sal_test ( p_sal IN NUMBER) RETURN BOOLEAN IS
2 BEGIN
3 RETURN p_sal > 1500;
4 END;
5 /
Function created.
SQL> SELECT ename, sal
2 FROM emp
3 WHERE sal_test(sal) = TRUE;
WHERE sal_test(sal) = TRUE
ERROR at line 3:
ORA-00904: "TRUE": invalid identifier
SQL> So this is what we find. BOOLEAN is not a vlid SQL datatype, at least for Oracle. This is a source of much wailing and gnashing ot teeth. I believe there are enhancement requests for it, but no signs on the horizon.
In the example you give you need it. You would be better off doing this...
is_in_group BOOLEAN;
begin
is_in_group :=
portal30.wwsec_api.is_user_in_group (
p_person_id => portal30.wwctx_api.get_user_id,
p_group_id => portal30.wwsec_api.group_id('GROUPNAME')
IF is_in_group = true THEN
FOR x IN (select start_time,title
from ec_reservations
where start_time >= '2004-JAN-01'
and rv_target_type='PU' )
...Otherwise you have to recast your function so it returns VARCHAR2 with values of 'TRUE' and 'FALSE' (or NUMBER returning 0 and 1, whatever).
Cheers, APC -
I want to add some predicate in select clause. Alike we can add some predicate in where close using FGAC. Is it possible in oracle ? I want to retrieve some more columns in result. It doesn't matter if those columns are there in select clause or not those should come when i query particular table.
It doesn't matter if those columns are there in select clause or not those
should come when i query particular table. There is no mechanism for doing it. The main reason is because the client has to have a variable to hold the result set which has the same signature as the query. If you tack columns on to the SELECT clause then you will break the client. unless the client is dynamic.
But if the client doesn't specifically ask for those columns then it is going to ignore them . So what is the point? This is a peculiar requirement, I would like to know what the business requirement is (just to satisfy my curiosity).
Cheers, APC
Blog : http://radiofreetooting.blogspot.com/ -
Decimal Separator in SELECT Clause
Hi
I have the following decimal format parameters:
SQL> select value
2 from v$nls_parameters
3 where parameter = 'NLS_NUMERIC_CHARACTERS';
VALUE
If I show a number with decimal I get a comma as the decimal separator
SQL> select 10/100 from dual;
10/100
,1
But if I use a decimal separator in the SELECT clause I get:
SQL> select 100 * 1,1 from dual;
100*1 1
100 1
It doesn't work. But using a period as the decimal separator works:
SQL> select 1.1 * 100 from dual;
1.1*100
110
Maybe this is something I've never had to deal with before but I thought that the numeric format applied to the sql results and also the numbers that you used in the sql clauses.
Regards,
Néstor BoscánHi,Néstor,
user594312 wrote:
... I thought that the numeric format applied to the sql results and also the numbers that you used in the sql clauses.No; it applies to results, and it can affect implicit conversions, but it doesn't apply to SQL code.
The period (or dot, '.') is always the decimal separator in numeric literals. There is no way to change that.
Think how confusing it would be if it did apply to SQL code! For example:
WHERE num_col IN (1,2)Are we comparing num_col to 1 value or 2 values? Whichever it is, what if we wanted to do the opposite?
If you really wanted to use comma as the decimal separator, you could have to use strings, not numbers, and that could be a lot less efficient.
For example:
SELECT 100 * TO_NUMBER ('1,1') -- This assumes your NLS settings are correct
FROM dual;Of course, efficiency won't be an issue when you're selecting 1 row from dual. -
Need to know the column names in my dynamic select clause
Dear All,
Please go through the following code. While executing the following code i am getting an error saying that dbms_sql.describe_columns overflow, col_name_len=35. Use describe_columns2.
Please guide me how to proceed further. Or please help me, how can i get the column names when i issue a dynamic select clause.
DECLARE
CUR INTEGER;
COL_CNT INTEGER ;
A INTEGER;
SEL_CLAUSE VARCHAR2(2000);
DESC_T DBMS_SQL.DESC_TAB;
REC DBMS_SQL.DESC_REC;
b number;
BEGIN
SEL_CLAUSE := 'SELECT 1,2,DECODE(1,1,''ONE'',2,''TWO'',3,''THREE'') FROM DUAL';
--'SELECT ROWID,PARA_SUB_CODE,DECODE('||''''||'ENG'||''''||','||''''||'ENG'||''''||',PARA_NAME,PARA_BL_NAME),NULL,NULL FROM PCOM_APP_PARAMETER';
--'SELECT 1,2,DECODE(1,1,''ONE'',2,''TWO'') FROM DUAL';
DBMS_OUTPUT.PUT_LINE( SEL_CLAUSE );
CUR := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(CUR,SEL_CLAUSE,DBMS_SQL.NATIVE);
DBMS_SQL.DESCRIBE_COLUMNS(CUR,COL_CNT,DESC_T);
B := desc_t.first;
FOR J IN 1..COL_CNT
LOOP
DBMS_OUTPUT.PUT_LINE('J := '||J || ' COL CNT ' || COL_CNT);
END LOOP;
BEGIN
A := DBMS_SQL.EXECUTE(CUR);
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
END;
Regards,
BalajiIs there any way can i have it directly??It does not work with static SQL either. Dynamic SQL is no different.
SQL> select 1 x from dual where x = 1 ;
select 1 x from dual where x = 1
ERROR at line 1:
ORA-00904: "X": invalid identifier
SQL>As suggested already, you will need to use alias if you want your select expression to be referred in the where clause.
SQL> BEGIN
2 FOR rec IN (SELECT *
3 FROM (SELECT 1,
4 2,
5 DECODE(1, 1, 'ONE', 2, 'TWO', 3, 'THREE') "DECODE(1, 1, 'ONE', 2, 'TWO', "
6 FROM DUAL)
7 WHERE "DECODE(1, 1, 'ONE', 2, 'TWO', " = 'ONE')
8 LOOP
9 NULL;
10 END LOOP;
11 END;
12 /
PL/SQL procedure successfully completed.
SQL>Message was edited by:
Kamal Kishore -
Bind Variable in SELECT statement and get the value in PL/SQL block
Hi All,
I would like pass bind variable in SELECT statement and get the value of the column in Dynamic SQL
Please seee below
I want to get the below value
Expected result:
select distinct empno ,pr.dept from emp pr, dept ps where ps.dept like '%IT' and pr.empno =100
100, HR
select distinct ename ,pr.dept from emp pr, dept ps where ps.dept like '%IT' and pr.empno =100
TEST, HR
select distinct loc ,pr.dept from emp pr, dept ps where ps.dept like '%IT' and pr.empno =100
NYC, HR
Using the below block I am getting column names only not the value of the column. I need to pass that value(TEST,NYC..) into l_col_val variable
Please suggest
----- TABLE LIST
CREATE TABLE EMP(
EMPNO NUMBER,
ENAME VARCHAR2(255),
DEPT VARCHAR2(255),
LOC VARCHAR2(255)
INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (100,'TEST','HR','NYC');
INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (200,'TEST1','IT','NYC');
INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (300,'TEST2','MR','NYC');
INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (400,'TEST3','HR','DTR');
INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (500,'TEST4','HR','DAL');
INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (600,'TEST5','IT','ATL');
INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (700,'TEST6','IT','BOS');
INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (800,'TEST7','HR','NYC');
COMMIT;
CREATE TABLE COLUMNAMES(
COLUMNAME VARCHAR2(255)
INSERT INTO COLUMNAMES(COLUMNAME) VALUES ('EMPNO');
INSERT INTO COLUMNAMES(COLUMNAME) VALUES ('ENAME');
INSERT INTO COLUMNAMES(COLUMNAME) VALUES ('DEPT');
INSERT INTO COLUMNAMES(COLUMNAME) VALUES ('LOC');
COMMIT;
CREATE TABLE DEPT(
DEPT VARCHAR2(255),
DNAME VARCHAR2(255)
INSERT INTO DEPT(DEPT,DNAME) VALUES ('IT','INFORMATION TECH');
INSERT INTO DEPT(DEPT,DNAME) VALUES ('HR','HUMAN RESOURCE');
INSERT INTO DEPT(DEPT,DNAME) VALUES ('MR','MARKETING');
INSERT INTO DEPT(DEPT,DNAME) VALUES ('IT','INFORMATION TECH');
COMMIT;
PL/SQL BLOCK
DECLARE
TYPE EMPCurTyp IS REF CURSOR;
v_EMP_cursor EMPCurTyp;
l_col_val EMP.ENAME%type;
l_ENAME_val EMP.ENAME%type;
l_col_ddl varchar2(4000);
l_col_name varchar2(60);
l_tab_name varchar2(60);
l_empno number ;
b_l_col_name VARCHAR2(255);
b_l_empno NUMBER;
begin
for rec00 in (
select EMPNO aa from EMP
loop
l_empno := rec00.aa;
for rec in (select COLUMNAME as column_name from columnames
loop
l_col_name := rec.column_name;
begin
l_col_val :=null;
l_col_ddl := 'select distinct :b_l_col_name ,pr.dept ' ||' from emp pr, dept ps where ps.dept like ''%IT'' '||' and pr.empno =:b_l_empno';
dbms_output.put_line('DDL ...'||l_col_ddl);
OPEN v_EMP_cursor FOR l_col_ddl USING l_col_name, l_empno;
LOOP
l_col_val :=null;
FETCH v_EMP_cursor INTO l_col_val,l_ename_val;
EXIT WHEN v_EMP_cursor%NOTFOUND;
dbms_output.put_line('l_col_name='||l_col_name ||' empno ='||l_empno);
END LOOP;
CLOSE v_EMP_cursor;
END;
END LOOP;
END LOOP;
END;user1758353 wrote:
Thanks Billy, Would you be able to suggest any other faster method to load the data into table. Thanks,
As Mark responded - it all depends on the actual data to load, structure and source/origin. On my busiest database, I am loading on average 30,000 rows every second from data in external files.
However, the data structures are just that - structured. Logical.
Having a data structure with 100's of fields (columns in a SQL table), raise all kinds of questions about how sane that structure is, and what impact it will have on a physical data model implementation.
There is a gross misunderstanding by many when it comes to performance and scalability. The prime factor that determines performance is not how well you code, what tools/language you use, the h/w your c ode runs on, or anything like that. The prime factor that determines perform is the design of the data model - as it determines the complexity/ease to use the data model, and the amount of I/O (the slowest of all db operations) needed to effectively use the data model. -
Using @Prompt in the SELECT clause (?)
Post Author: faltinowski
CA Forum: Semantic Layer and Data Connectivity
Product: Business Objects
Version: 6.5 SP3
Patches Applied: MHF11 and CHF48
Operating System(s): Windows
Database(s): Oracle
Error Messages: "Parse failed: Exception: DBD, ORA-00903 invalid table name State N/A"
Hi! I'm bewildered -- we have an object that parses but when I try to reproduce this object, it does not.
We have a universe that's been in production for several years using an object developed by another designer who's no longer with the company. This object is a dimension, datatype is character, and there's no LOV associated. The SELECT statement in this object is
decode(@Prompt('Select Snapshot Month','A','Object Definitions\CY Month Snapshot',MONO,CONSTRAINED),'00-Previous Month',to_number(to_char(add_months(sysdate,-1),'MM')),'01-Current Month',to_number(to_char(add_months(sysdate,0),'MM')),'01-January','1','02-February','2','03-March','3','04-April','4','05-May','5','06-June','6','07-July','7','08-August','8','09-September','9','10-October','10','11-November','11','12-December','12')
This object parses. The client uses the object in the select clause to capture the "month of interest" for the report. So the report may be for the entire year's data which is graphed to show trends, but there's a table below the graph which is filtered to show just the month of interest. Typically they use the value "00-Previous Month" so they can schedule the report and it will always show the last month's data.
Problem
The original object parses.
If I copy the object within the same universe, it parses.
If I copy the code into a new object in the same universe, it doesn't parse
If I copy the code into a new object in a different universe, it doesn't parse
If I copy the object to a different universe, then edit the LOV reference, it doesn't parse
If I create any new object having @Prompt in the SELECT statement, it doesn't parse.
If another designer tries - they get the same thing.
What am I missing? Obviously someone was able to create this successfully.
On the brighter side
The object I created in a new universe (which doesn't parse in the universe) seems to work fine in the report.Seems that, the prompt syntax is correct.
But the condition is not correct.
You are taking the prompt value and not doing anything. That could be one issue for this error.
I believe that, you just want to capture the prompt value use it in report level and do not want to apply as a filter.
So, use the condition as follows.
@Prompt('Select Grouping','A',{'A','B','C'},mono,constrained) = @Prompt('Select Grouping','A',{'A','B','C'},mono,constrained)
Hope this helps! -
How to append new field in select clause of dynamic VO through CO
I have dynamic VO "FaoWorkPerObjPerfRatingsVO" in controlloer below:
public class FaoWorkApprObjectivesCO extends ApprObjectivesCO
public void processRequest(OAPageContext oapagecontext, OAWebBean oawebbean)
super.processRequest(oapagecontext, oawebbean);
OAApplicationModule oam = oapagecontext.getApplicationModule(oawebbean);
oracle.apps.fnd.framework.server.OADBTransaction oadbtransaction = oam.getOADBTransaction();
OAViewObject oav = (OAViewObject)oam.findViewObject("FaoWorkPerObjPerfRatingsVO");
if(oav != null)
System.out.println("FAO Found VO PerObjPerfRatingsVO for ObjectivesAM. This means we have re-entered the page");
} else
oav = (OAViewObject)oam.createViewObject("FaoWorkPerObjPerfRatingsVO", "oracle.apps.per.selfservice.objectives.server.PerObjPerfRatingsVO");
How can I append 2 new fields are MULTIRATERS_AVERAGE and COUNT_MULTIRATERS as statement below in select clause of dynamic VO above (FaoWorkPerObjPerfRatingsVO)
fao_pems_utility.AVG_STEP_VALUE(fao_pems_utility.GET_APPRAISAL_ID(PCE.ASSESSMENT_ID),
'MULTIRATER',
Null,
PCE.COMPETENCE_ID) MULTIRATERS_AVERAGE,
fao_pems_utility.COUNT_RATINGS(Null,
Null,
fao_pems_utility.GET_APPRAISAL_ID(PCE.ASSESSMENT_ID),
PCE.COMPETENCE_ID,
Null,
'MULTIRATER',
Null) || ' out of ' ||
(fao_pems_utility.HOW_MANY_RATING(fao_pems_utility.GET_APPRAISAL_ID(PCE.ASSESSMENT_ID),
'GROUPAPPRAISER') +
fao_pems_utility.HOW_MANY_RATING(fao_pems_utility.GET_APPRAISAL_ID(PCE.ASSESSMENT_ID),
'REVIEWER')) COUNT_MULTIRATERS
Thank you very much.Hi
My VO is VO Extension below. In the seeded VO (oracle.apps.per.selfservice.objectives.server.PerObjPerfRatingsVO) doesn't include 2 fields that I want to add in VO.
oav = (OAViewObject)oam.createViewObject("FaoWorkPerObjPerfRatingsVO", "oracle.apps.per.selfservice.objectives.server.PerObjPerfRatingsVO");
Could you please provide me the coding to append 2 new fields in VO Extension approach. I would like to append them in select clause.
Thank you. -
Using a select clause in the column formula in an Analysis
Hi all,
Is there a function or syntax that I can use to simulate a "SELECT" clause in the column formula of an Analysis? What I am trying to achieve is displaying a measure from a specific fact record into the current record. For example, if the current record displays "Region","position", and "salary", I would like to add an additional column called "compared to" in which I can display the "salary" measure from another specific fact record whose attributes I know.
Is there a function/statement that I can use to achieve this?
ThanksHi,
U can't do it in Edit formula column..it's possible below one
Add SQL filter in that column then follow blow steps
Convert this filter to SQL
i.e : add more option to sql here u can write SQL query in that column
Thanks
Deva
Maybe you are looking for
-
Restore using TSPITR Results Dead lock error
This is the step is followed but i am getting deadlock error .please give your valuable suggestion . Product Used:oracle 11g in linux environmnet 1)Before taking backup get SCN number for restore. Command applied: Select current_scn from v$database;
-
Document Flow not updated using BAPI_GOODSMVT_CREATE
Hi Experts, I am using BAPI_GOODSMVT_CREATE for doing PGR of an inbound delivery. Material Document(mblnr) is getting populated but Document Flow of that inbound delivery is not getting updated.Its status is Open. Can anyone knows how Document Flow c
-
Same Ipod recognized twice by iTunes, crashes when deleting songs off iPod.
I know that others have had this issue but there was never an answer and it was awhile back so I figured I'd post a new message. Everytime I sync my iPod it is recognized twice by iTunes. What I mean by this is that it looks as if I am syncing two iP
-
How not to receive a certain MobileMe calendar on iPhone
I just updated from version 3.0.1 of the iPhone OS to version 3.1.3, and the handling of subscribed calendars is quite different. My wife authors a calendar on my MobileMe account, but because it is over 1 MB in size, I only subscribed to it on my Ma
-
How can I get my iTunes music playlist exported out to a file format that Bento 3 will be able to import into a new database?