Dividing the SELECT clause to understand
Hi All,
I am given a code which has very complicated SELECT clause which I am not able to break in understandable form.
Its like this:
for i in (select 'select ROWIDTOCHAR(rowid) rid, studyid, '''||db_link||''' db_link, rowid || '':'' || studyid || '':'' || '''||db_link||''' as text from consolidated.cp_queue_tbl'||decode(db_link,null,null,'@'|| db_link|| ' where process_start_time is null') stat from (select distinct db_link from cp_study_metadata_tbl))
I am not able to understand which are actual column and which are aliases among this. Neither I can understand where oen query ends and other begins.
Please help
Aashish S.
Are you sure that the parenthesis that stands immediatly before "stat" is well placed?
You're adding the where clause only if selecting through database link, seems strange...
Maybe it should be
FOR i IN
(SELECT 'select ROWIDTOCHAR(rowid) rid, studyid, '''||
db_link||''' db_link, rowid || '':'' || studyid || '':'' || '''||
db_link||''' as text from consolidated.cp_queue_tbl'||
DECODE(db_link,null,null,'@'||db_link)||' where process_start_time is null' stat
FROM (SELECT DISTINCT db_link
FROM cp_study_metadata_tbl)
)Max
[My Italian Oracle blog|http://oracleitalia.wordpress.com/2009/12/29/estrarre-i-dati-in-formato-xml-da-sql/]
Similar Messages
-
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 @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! -
Problems with query with more than 20 values in the select clause
I have a region based on a function returning a SQL query. It needs to have more than 20 values in the select clause. When I run the page I get a no data found error in the region. I managed to reproduce this behavior with just the following as the select returned by the function:
select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21
from dual
I am running the 1.3.9.00.15 release of Marvel on 9.2.0.2 of the db on Solaris.Hello Raju,
I will email you the connection settings when I return to the office.
One thing I should have mentioned: The sql string is returned from a package in the db, so the query region text I originally posted isn't quite correct.
it is something like:
declare
begin
return my_pkg.my_fnc;
end;
the stored package is nothing more than:
package my_pks is
funtion my_fnc(i_test_param in varchar2) is
begin
return 'select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, 21 from dual';
end;
end;
Sorry for the inaccurate info in the first post, but I am away from the server in question right now. -
In a SQL statement, the SELECT clause is used to
In a SQL statement, the SELECT clause is used to select
(a) columns
(b) rows
(c) tables
(d) none of the above
can any one help ImmediatelyIs used to select rows of specified column...
SELECT column_name(s) FROM table_name -
Can a subquery in the select clause return more than one field?
Something like this:
select ename,
(select dname, loc from dept where e.deptno = deptno) as (dname,loc)
from emp eA simple way to find out is to test it. In my tests below, the original query produces an error that says it didn't find FROM where it expected. Eliminating "as (dname,loc)" produces an error about too many values. Putting only one value in the subquery in the select clause works, whether it is dname or loc. Concatenating the two columns as dname || ' ' || loc to produce one value in the subquery in the select clause works. Using two separate subqueries, one for dname and one for loc works. And, lastly, a cursor statement with both values works, although the output is a little hard to read. This may be different in newer versions. I am using Oracle 8.1.7. It may be different in 9i. I was unable to locate any documentation on the cursor statement or cursor operator which I have also heard it called. I only knew to try it because I have seen it used. I looked up the SELECT syntax in the 9i SQL Reference and there was no mention of cursor in the select clause. Can anyone provide a link to some documentation on this? I vaguely recall reading something that said that, other than outputting from SQL*Plus as below, it wasn't yet compatible with anything else, like you can't use it in PL/SQL, but I can't remember where I read it.
SQL> -- 2 values in subquery in select clause:
SQL> select ename,
2 (select dname, loc from dept where e.deptno = deptno) as (dname,loc)
3 from emp e
4 /
(select dname, loc from dept where e.deptno = deptno) as (dname,loc)
ERROR at line 2:
ORA-00923: FROM keyword not found where expected
SQL> select ename,
2 (select dname, loc from dept where e.deptno = deptno)
3 from emp e
4 /
(select dname, loc from dept where e.deptno = deptno)
ERROR at line 2:
ORA-00913: too many values
SQL> -- 1 value in subquery in select clause:
SQL> select ename,
2 (select dname from dept where e.deptno = deptno)
3 from emp e
4 /
ENAME (SELECTDNAMEFR
SMITH RESEARCH
ALLEN SALES
WARD SALES
JONES RESEARCH
MARTIN SALES
BLAKE SALES
CLARK ACCOUNTING
SCOTT RESEARCH
KING ACCOUNTING
TURNER SALES
ADAMS RESEARCH
JAMES SALES
FORD RESEARCH
MILLER ACCOUNTING
14 rows selected.
SQL> select ename,
2 (select loc from dept where e.deptno = deptno)
3 from emp e
4 /
ENAME (SELECTLOCFRO
SMITH DALLAS
ALLEN CHICAGO
WARD CHICAGO
JONES DALLAS
MARTIN CHICAGO
BLAKE CHICAGO
CLARK NEW YORK
SCOTT DALLAS
KING NEW YORK
TURNER CHICAGO
ADAMS DALLAS
JAMES CHICAGO
FORD DALLAS
MILLER NEW YORK
14 rows selected.
SQL> select ename,
2 (select dname || ' ' || loc from dept where e.deptno = deptno)
3 from emp e
4 /
ENAME (SELECTDNAME||''||LOCFROMDEP
SMITH RESEARCH DALLAS
ALLEN SALES CHICAGO
WARD SALES CHICAGO
JONES RESEARCH DALLAS
MARTIN SALES CHICAGO
BLAKE SALES CHICAGO
CLARK ACCOUNTING NEW YORK
SCOTT RESEARCH DALLAS
KING ACCOUNTING NEW YORK
TURNER SALES CHICAGO
ADAMS RESEARCH DALLAS
JAMES SALES CHICAGO
FORD RESEARCH DALLAS
MILLER ACCOUNTING NEW YORK
14 rows selected.
SQL> select ename,
2 (select dname from dept where e.deptno = deptno),
3 (select loc from dept where e.deptno = deptno)
4 from emp e
5 /
ENAME (SELECTDNAMEFR (SELECTLOCFRO
SMITH RESEARCH DALLAS
ALLEN SALES CHICAGO
WARD SALES CHICAGO
JONES RESEARCH DALLAS
MARTIN SALES CHICAGO
BLAKE SALES CHICAGO
CLARK ACCOUNTING NEW YORK
SCOTT RESEARCH DALLAS
KING ACCOUNTING NEW YORK
TURNER SALES CHICAGO
ADAMS RESEARCH DALLAS
JAMES SALES CHICAGO
FORD RESEARCH DALLAS
MILLER ACCOUNTING NEW YORK
14 rows selected.
SQL> -- cursor statement:
SQL> select ename,
2 cursor (select dname, loc from dept where e.deptno = deptno)
3 from emp e
4 /
ENAME CURSOR(SELECTDNAME,L
SMITH CURSOR STATEMENT : 2
CURSOR STATEMENT : 2
DNAME LOC
RESEARCH DALLAS
1 row selected.
ALLEN CURSOR STATEMENT : 2
CURSOR STATEMENT : 2
DNAME LOC
SALES CHICAGO
1 row selected.
WARD CURSOR STATEMENT : 2
CURSOR STATEMENT : 2
DNAME LOC
SALES CHICAGO
1 row selected.
JONES CURSOR STATEMENT : 2
CURSOR STATEMENT : 2
DNAME LOC
RESEARCH DALLAS
1 row selected.
MARTIN CURSOR STATEMENT : 2
CURSOR STATEMENT : 2
DNAME LOC
SALES CHICAGO
1 row selected.
BLAKE CURSOR STATEMENT : 2
CURSOR STATEMENT : 2
DNAME LOC
SALES CHICAGO
1 row selected.
CLARK CURSOR STATEMENT : 2
CURSOR STATEMENT : 2
DNAME LOC
ACCOUNTING NEW YORK
1 row selected.
SCOTT CURSOR STATEMENT : 2
CURSOR STATEMENT : 2
DNAME LOC
RESEARCH DALLAS
1 row selected.
KING CURSOR STATEMENT : 2
CURSOR STATEMENT : 2
DNAME LOC
ACCOUNTING NEW YORK
1 row selected.
TURNER CURSOR STATEMENT : 2
CURSOR STATEMENT : 2
DNAME LOC
SALES CHICAGO
1 row selected.
ADAMS CURSOR STATEMENT : 2
CURSOR STATEMENT : 2
DNAME LOC
RESEARCH DALLAS
1 row selected.
JAMES CURSOR STATEMENT : 2
CURSOR STATEMENT : 2
DNAME LOC
SALES CHICAGO
1 row selected.
FORD CURSOR STATEMENT : 2
CURSOR STATEMENT : 2
DNAME LOC
RESEARCH DALLAS
1 row selected.
MILLER CURSOR STATEMENT : 2
CURSOR STATEMENT : 2
DNAME LOC
ACCOUNTING NEW YORK
1 row selected.
14 rows selected. -
Calling a function in the select clause.
I am using Oracle 11g.
I am trying to write a query like this
select name,age, sal, avg = avg_salary(age)
from customer
where sal >= avg;
However, I am not able to do so. What the query is trying to do is print the name, age and salary of every customer as well as the average salary for the customer's age where the customer's salary is greater than the average salary for his age.
Please help. Thanks.Hi,
The way to assign a column alias is to put the alais after the expression. It makes your code clearer if you put the keyword AS after the expression and before the alias, but this is not required.
SELECT name
, age
, sal
, avg_salary (age) AS avg_salary_age
FROM customer
WHERE sal >= avg_salary (age)
;You can't reference a column alais in the same query where it is defined (except in an ORDER BY clause). If you want to reference the alias anywhere else (e.g., in the WHERE clause) you have to define it in a sub-query; then you can use it anywhere you want in the super-query, liek this:
WITH got_avg_salary_age AS
SELECT name
, age
, sal
, avg_salary (age) AS avg_salary_age
FROM customer
SELECT *
FROM got_avg_salary_age
WHERE sal >= avg_salary_age
;Since AVG is the name of a built-in function, there could be problems using it as a column alias. You could call it average, if you don't like avg_salary_age. -
Date comparison in the select clause
I want to have comparison as if date1 >= date2 then select as 1 or select as 2. This should be in the select clause
select greatest (date1, date2)
from table
~
pascal -
How to overwrite an inner query in the select clause
Hello,
I have a queryof this form:
SELECT t1.ID,
t1.column2,
(SELECT SUM (t2.column2)
FROM table2 t2
WHERE t2 = t.ID
AND t2.column1 IN (SELECT ..... FROM table3 t3 WHERE t3.column1 = t1.column3 ........)
FROM table1 t1At the stage where I select from table3 I do not see the columns of table1. In other words:
t3.column1 = t1.column3will NOT work.
The version of the database is 10.2.0.4.
How could I rewrite this piece of code in order to surround the problem?
I cannot join table3 with table1 in the outermost query, because the structure of this database is such that it would not work for me.
I know that most of you would say, change the DB structure, but anyway, any ideas? :)
Besides, is the same restriction for inner queries applicable in Oracle 11g2?
Thanksuser13080027 wrote:
Hi
I mean I receive the error ORA-00904-"t1.column3" invalid identifier.Something does not add up here. You said earlier
I cannot join table3 with table1 in the outermost query, because the structure of this database is such that it would not work for me.Why can't you rewrite your query something like follows:
SELECT t1.ID,
t1.column2,
(SELECT SUM (t2.column2)
FROM table2 t2
WHERE t2 = t.ID
AND t2.column1 = t3.column3
FROM table1 t1, table3 t3
WHERE t3.column1 = t1.column3p.s. I am not saying this is the exact query you need but then you don't provide any details requested. ;) -
Getting Exception in the select clause - Very Urgent
Hi,
I have given the below statement but it is showing the exception.
SELECT *
FROM (lv_tab_name)
INTO CORRESPONDING FIELDS OF TABLE <fs_1>.
If I execute the above select statement it is showing the below exception.
Exception CX_SY_NO_HANDLER triggered.
An exception with the type CX_SY_OPEN_SQL_DB occurred.
It is working very well if I mention the few field names.
Please let me know the possible reasons.
Thanks,
SuvinThanks much for your quick response.
I have tried with what you mentioned but it is not working.
Please find my code below.
*Declarations
DATA: ddfields TYPE STANDARD TABLE OF ddfield.
DATA: ls_ddfields TYPE ddfield.
DATA: lt TYPE lvc_t_fcat.
DATA: ls TYPE lvc_s_fcat.
DATA: lv_tab_name TYPE dd02l-tabname.
Data References
DATA: lt_data TYPE REF TO data.
DATA: new_line TYPE REF TO data.
Field Symbols
FIELD-SYMBOLS: <fs_1> TYPE ANY TABLE.
FIELD-SYMBOLS: <fs_data> TYPE REF TO data.
FIELD-SYMBOLS: <fs_2> TYPE ANY,
<l_field> TYPE ANY.
Get the fields of the database table, here i am passing the table name
CALL FUNCTION 'DD_NAMETAB_TO_DDFIELDS'
EXPORTING
KEYFIELDS = 'X'
NULLABLE = 'X'
tabname = lv_tab_name
TABLES
ddfields = ddfields.
LOOP AT ddfields INTO ls_ddfields.
ls-fieldname = ls_ddfields-fieldname.
APPEND ls TO lt.
ENDLOOP.
*Assigning Field-Symbol to our dynamic internal table
ASSIGN lt_data TO <fs_data>.
Calling the method CREATE_DYNAMIC_TABLE
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt
IMPORTING
ep_table = <fs_data>
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
IF sy-subrc EQ 0.
ASSIGN <fs_data>->* TO <fs_1>.
Create a work area for the dynamic table.
CREATE DATA new_line LIKE LINE OF <fs_1>.
A field-symbol to access that work area
ASSIGN new_line->* TO <fs_2>.
ENDIF.
Selecting the Data from the respective table.
SELECT *
FROM (lv_tab_name)
INTO CORRESPONDING FIELDS OF TABLE <fs_1>.
Please advise..it is very urgent.
Thanks,
Suvin -
Using if logic in the where clause of a select statement
I have a select clause. And in the select clause there is a variable all_off_trt that can be 'Y' or 'N'.
In the where clause I want to make it so that if a form variable is checked and all_off_trt is 'Y' then
exclude it else if the form variable isn't checked then select it no matter what all_off_trt is.
Is there any way to include either and if statement or a case statement within the where clause to acheive this? If not is there another way of doing it?
Basically I am looking for a case statement like this
case
when all_off_trt = 'Y' and mail_para.code = 'Y' then false
else true
end
Message was edited by:
Tugnutt7Ok, so that really doesn't solve my problem. I have 3 different fields that I need to do that with. Each combining in a select statement to print an email list, as well as other thing limiting the where clause.
This is currently what I have, tested and working 100%.
cursor email_cur is
select unique p.email,s.all_off_trt,s.all_deceased,s.no_enroll
from participant p, trialcom t, ethics s
where p.status='A'
and p.surname=t.surname
and p.initials=t.initials
and s.trial_cd = t.tricom
and s.centre = t.centre
and p.email is not null
and (t.centre in (select code from mail_parameters where user_name=user and mail_para='CENTRE')
or 'XX' in (select code from mail_parameters where user_name=user and mail_para='CENTRE'))
and (t.tricom in (select code from mail_parameters where user_name=user and mail_para='TRIAL')
or 'XX' in (select code from mail_parameters where user_name=user and mail_para='TRIAL'))
and (t.role in (select code from mail_parameters where user_name=user and mail_para='ROLE')
or 'XX' in (select code from mail_parameters where user_name=user and mail_para='ROLE'))
and (p.country in (select code from mail_parameters where user_name=user and mail_para='COUNTRY')
or 'XX' in (select code from mail_parameters where user_name=user and mail_para='COUNTRY'))
and (t.represent in (select code from mail_parameters where user_name=user and mail_para='REPRESENT')
or 'XX' in (select code from mail_parameters where user_name=user and mail_para='REPRESENT'));
This is in a program unit that runs when a button is clicked. At the end of that I need to add on the 3 case statements that help further narrow down the selection of emails to be printed. Then it prints the emails selected from this statement into a file. So it has to be done right in the select statement. The three table variables are the all_off_trt, all_deceased, and no_enroll. The form has 3 checkboxes. One for each, that when checked (giving the variable associated with the checkboxes a value of 'Y') excludes all emails that have a 'Y' in the coresponding table variable. -
The mechanics of the WHERE clause
I’ve been out in industry for over 10 years now doing DB work most of that time. Lately I’ve been doing some work that is starting to challenge my long held assumptions about the internal workings of SQL Server, specifically what exactly is happening when
I do joins and where clauses.
I was explaining to someone that when doing a join putting in a where clause limits the amount of records that are available to do the join on thereby making the query faster. My thought was if a table has 100MM records but only 50MM of those meet the WHERE
criteria then the JOIN clause wouldn’t try matching the 50MM records that don’t meet the WHERE clause.
I did some work that afternoon and the empirical results didn’t match the expected outcome of a query I had written in terms of execution time. I don’t think my understanding of what goes on during a JOIN is correct. Can someone educate me?Here is how a SELECT works in SQL ... at least in theory. Real products will optimize things, but the code has to produce the same results.
a) Effectively materialize the CTEs in the optional WITH clause. CTE's come into existence in the order they are declared so only backward references are
alllowed. A CTE can be recursive. Think of them as VIEWs that exist only in the scope of the query. In practice, if they are used once then they are implemented as an in-line macro.
b) Start in the FROM clause and build a working table from all of the joins, unions, intersections, and whatever other table constructors are there. The <table expression> AS <correlation name> option allows you give a name to this working
table which you then have to use for the rest of the containing query. Ther are UNIONB, INTERSECT and EXCEPT set construtors, LATERAL tables, table-valued funcitosn and all kinds of things happening in here.
c) Go to the WHERE clause and remove rows that do not pass criteria; that is, that do not test to TRUE (i.e. reject UNKNOWN and FALSE). The WHERE clause is applied to the working set in the FROM clause.
d) Go to the optional GROUP BY clause, partiton the original table into groups and reduce each grouping to a *single* row, replacing the original working table with the new grouped table. The rows of a grouped table must be only group characteristics:
(1) a grouping column (2) a statistic about the group (i.e. aggregate functions) (3) a function or constant(4) an expression made up of only those three items. The original table no longer exists and you cannot reference anything in it (this was an error
in early Sybase products).
e) Go to the optional HAVING clause and apply it against the grouped working table; if there was no GROUP BY clause, treat the entire table as one group.
f) Go to the SELECT clause and construct the expressions in the list. This means that the scalar subqueries, function calls and expressions in the SELECT are done after all the other clauses are done. The AS operator can also give names to expressions
in the SELECT list. These new names come into existence all at once, but after the WHERE clause, GROUP BY clause and HAVING clause have been executed; you cannot use them in the SELECT list or the WHERE clause for that reason.
If there is a SELECT DISTINCT, then redundant duplicate rows are removed. For purposes of defining a duplicate row, NULLs are treated as matching (just like in the GROUP BY).
g) Nested query expressions follow the usual scoping rules you would expect from a block structured language like C, Pascal, Algol, etc. Namely, the innermost queries can reference columns and tables in the queries in which they are contained.
h) The ORDER BY clause is part of a cursor, not a query. The result set is passed to the cursor, which can only see the names in the SELECT clause list, and the sorting is done there. The ORDER BY clause cannot have expression in it, or references
to other columns because the result set has been converted into a sequential file structure and that is what is being sorted.
As you can see, things happen "all at once" in SQL, not "from left to right" as they would in a sequential file/procedural language model. In those languages, these two statements produce different results:
READ (a, b, c) FROM File_X;
READ (c, a, b) FROM File_X;
while these two statements return the same data:
SELECT a, b, c FROM Table_X;
SELECT c, a, b FROM Table_X;
Think about what a confused mess this statement is in the SQL model.
SELECT f(c2) AS c1, f(c1) AS c2 FROM Foobar;
That is why such nonsense is illegal syntax.
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
If I want to order by dateAdded to I have to include it in the select statement like
If I do this:
<cfquery name="chart" datasource="#datasource#">
select behaviourID,score, dateAdded2 = convert(varchar,
dateAdded , 101)
from staff_charts_data
where userID =
<cfqueryparam value="#arguments.userID#"
cfsqltype="cf_sql_integer"> AND
NOT score = 5
</cfquery>
If I want to order by dateAdded to I have to include it in
the select statement like so:
<cfquery name="chart" datasource="#datasource#">
select behaviourID,score, dateAdded2 = convert(varchar,
dateAdded , 101),dateAdded
from staff_charts_data
where userID =
<cfqueryparam value="#arguments.userID#"
cfsqltype="cf_sql_integer"> AND
NOT score = 5
</cfquery>you should be able to order by dateAdded without it being in
the select clause. The only time the order by field has to be in
the select clause is when your query has an aggregate and group by
clause, like this:
select field1, field2, max(field3) as youralias
from sometables
where whatever
group by field1, field2
order by ???
You can only order field1, field2, max(field3) or youralias.
You can't order by field4. -
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. -
¶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
Maybe you are looking for
-
How to add a button in the view at a specific position
Hi Gurus, We have a requirement : To add a button or image at a specific position in the view which is like an indicator showing different color based on another field . Example : Adding a button next to a drop down flield and changing the color of t
-
Terms of Payment Key in line item with Special G/L Indicator
Hi All, Displaying the line item of a financial document with Special G/L Indicator, I can't see the Terms of Payment Key (BSEG-ZTERM). Could anyone tell me how to make it shown? Thanks G.
-
Importing from photo booth, problems with length and sound
I have a 15 min (277 MB) video clip from photo booth that I would like to post to youtube. I can't get it to work and have been wrestling with a few different programs: When opening the clip in Quicktime, there is no sound. I can open with VLC media
-
How to disable the first row of an ALV Grid?
Hi All, I am working on a module pool programme. I am displaying ALV grid. I have to give some default values in the first row and disable it. I have to disable the third column and fourth row value. How can i achieve this? Help will be appreci
-
can any one give me the complete syllabus for abap. thanks in advance.