SQL : Select clause
Hi all..
In open sql, is it impossible..?
Select a~*
into table gt_mara
from mara as a inner join marc as b
~~~
For performance, I want to fetch the fields of table mara. But, while compiling, occur error..
How to do..? What to do..? tell me plz..
Thank you!!
regards..
Hi Kil,
Just an addition to the prev post..
Avoid the "into corresponding fields" for performance reasons... as long as the fields in the internal table are in the same order, use the below clause..
Select *
into table gt_mara
from mara as a inner join marc as b
ON amatnr = bmatnr.
Rgds,
Prash.
Similar Messages
-
SQL Query : Getting specific datatype in select clause
Hi
I want to write one query that returns me the values inside a table based on the datatype of column(s) of the table. For e.g. I need only those columns of the table in select clause where the datatype of the column is VARCHAR.
Can you please help me on this?Use the "user_tab_columns" Data Dictionary to get the columns and build the SQL Dynamically.
Thanks,
Karthick. -
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 -
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. -
I have the privilege of performing a very tedious task.
We have some home grown regular expressions in our company. I now need to expand these regular expressions.
Samples:
a = 0-3
b = Null, 0, 1
Expression: Meaning
1:5: 1,2,3,4,5
1a: 10, 11, 12, 13
1b: 1, 10, 11
1[2,3]ab: 120, 1200, 1201, ....
It get's even more inetersting because there is a possibility of 1[2,3]a.ab
I have created two base queries to aid me in my quest. I am using the SQL MODEL clause to solve this problem. I pretty confident that I should be able to convert evrything into a range and the use one of the MODEL clause listed below.
My only confusion is how do I INCREMENT dynamically. The INCREMENT seems to be a constant in both a FOR and ITERATE statement. I need to figure a way to increment with .01, .1, etc.
Any help will be greatly appreciated.
CODE:
Reference: http://www.sqlsnippets.com/en/topic-11663.html
Objective: Expand a range with ITERATE
WITH t AS
(SELECT '2:4' pt
FROM DUAL
UNION ALL
SELECT '6:9' pt
FROM DUAL)
SELECT pt AS code_expression
-- , KEY
-- , min_key
-- , max_key
, m_1 AS code
FROM t
MODEL
PARTITION BY (pt)
DIMENSION BY ( 0 AS KEY )
MEASURES (
0 AS m_1,
TO_NUMBER(SUBSTR(pt, 1, INSTR(pt, ':') - 1)) AS min_key,
TO_NUMBER(SUBSTR(pt, INSTR(pt, ':') + 1)) AS max_key
RULES
-- UPSERT
ITERATE (100000) UNTIL ( ITERATION_NUMBER = max_key[0] - min_key[0] )
m_1[ITERATION_NUMBER] = min_key[0] + ITERATION_NUMBER
ORDER BY pt, m_1
Explanation:
Line numbers are based on the assupmtion that "WITH t AS" starts at line 5.
If you need detailed information regarding the MODEL clause please refer to
the Refrence site stated above or read some documentation.
Partition-
Line 18: PARTITION BY (pt)
This will make sure that each "KEY" will start at 0 for each value of pt.
Dimension-
Line 19: DIMENSION BY ( 0 AS KEY )
This is necessary for the refrences max_key[0], and min_key[0] to work.
Measures-
Line 21: 0 AS m_1
A space holder for new values.
Line 22: TO_NUMBER(SUBSTR(pt, 1, INSTR(pt, ':') - 1)) AS min_key
The result is '1' for '1:5'.
Line 23: TO_NUMBER(SUBSTR(pt, INSTR(pt, ':') + 1)) AS max_key
The result is '5' for '1:5'.
Rules-
Line 26: UPSERT
This makes it possible for new rows to be created.
Line 27: ITERATE (100000) UNTIL ( ITERATION_NUMBER = max_key[0] - min_key[0] )
This reads ITERATE 100000 times or UNTIL the ITERATION_NUMBER = max_key[0] - min_key[0]
which would be 4 for '1:5', but since the ITERATION_NUMBER starts at 0, whatever follows
is repaeted 5 times.
Line 29: m_1[ITERATION_NUMBER] = min_key[0] + ITERATION_NUMBER
m_1[ITERATION_NUMBER] means m_1[Value of Dimension KEY].
Thus for each row of KEY the m_1 is min_key[0] + ITERATION_NUMBER.
Reference: http://www.sqlsnippets.com/en/topic-11663.html
Objective: Expand a range using FOR
WITH t AS
(SELECT '2:4' pt
FROM DUAL
UNION ALL
SELECT '6:9' pt
FROM DUAL)
, base AS
SELECT pt AS code_expression
, KEY AS code
, min_key
, max_key
, my_increment
, m_1
FROM t
MODEL
PARTITION BY (pt)
DIMENSION BY ( CAST(0 AS NUMBER) AS KEY )
MEASURES (
CAST(NULL AS CHAR) AS m_1,
TO_NUMBER(SUBSTR(pt, 1, INSTR(pt, ':') - 1)) AS min_key,
TO_NUMBER(SUBSTR(pt, INSTR(pt, ':') + 1)) AS max_key,
.1 AS my_increment
RULES
-- UPSERT
m_1[FOR KEY FROM min_key[0] TO max_key[0] INCREMENT 1] = 'Y'
ORDER BY pt, KEY, m_1
SELECT code_expression, code
FROM base
WHERE m_1 = 'Y'
Explanation:
Line numbers are based on the assupmtion that "WITH t AS" starts at line 5.
If you need detailed information regarding the MODEL clause please refer to
the Refrence site stated above or read some documentation.
Partition-
Line 21: PARTITION BY (pt)
This will make sure that each "KEY" will start at 0 for each value of pt.
Dimension-
Line 22: DIMENSION BY ( 0 AS KEY )
This is necessary for the refrences max_key[0], and min_key[0] to work.
Measures-
Line 24: CAST(NULL AS CHAR) AS m_1
A space holder for results.
Line 25: TO_NUMBER(SUBSTR(pt, 1, INSTR(pt, ':') - 1)) AS min_key
The result is '1' for '1:5'.
Line 26: TO_NUMBER(SUBSTR(pt, INSTR(pt, ':') + 1)) AS max_key
The result is '5' for '1:5'.
Line 27: .1 AS my_increment
The INCREMENT I would like to use.
Rules-
Line 30: UPSERT
This makes it possible for new rows to be created.
However seems like it is not necessary.
Line 32: m_1[FOR KEY FROM min_key[0] TO max_key[0] INCREMENT 1] = 'Y'
Where the KE value is between min_key[0] and max_key[0] set the value of m_1 to 'Y'
*/Of course, you can accomplish the same thing without MODEL using an Integer Series Generator like this.
create table t ( min_val number, max_val number, increment_size number );
insert into t values ( 2, 3, 0.1 );
insert into t values ( 1.02, 1.08, 0.02 );
commit;
create table integer_table as
select rownum - 1 as n from all_objects where rownum <= 100 ;
select
min_val ,
increment_size ,
min_val + (increment_size * n) as val
from t, integer_table
where
n between 0 and ((max_val - min_val)/increment_size)
order by 3
MIN_VAL INCREMENT_SIZE VAL
1.02 .02 1.02
1.02 .02 1.04
1.02 .02 1.06
1.02 .02 1.08
2 .1 2
2 .1 2.1
2 .1 2.2
2 .1 2.3
2 .1 2.4
2 .1 2.5
2 .1 2.6
2 .1 2.7
2 .1 2.8
2 .1 2.9
2 .1 3
15 rows selected.--
Joe Fuda
http://www.sqlsnippets.com/ -
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 -
How can I set a variable number of values in a SQL IN clause?
Hi,
How can I set a variable number of values in a SQL IN clause without having to change the text of the SQL statement each time?
I read the link http://radio.weblogs.com/0118231/2003/06/18.html. as steve wrote.
SELECT *
FROM EMP
WHERE ENAME IN (?)
But we need the steps not to create type in the system and would there be any other solution if we would like to use variable number of values in a SQL IN clause ?
We are using JDeveloper 10.1.3.2 with Oracle Database 10.1.3.2
Thanks
RajHi,
can you please explain why the solution from steve is not the right solution for you.
regards
Peter -
¶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 -
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 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 -
How to use a function in select clause
hi gems...good evening...
I want to write a select clause from a function. The scenario is like below:
function parameters
CREATE OR REPLACE FUNCTION FUNCTION_DEMO(p_pid IN NUMBER,
p_bankerNum IN NUMBER,
p_banker_name IN VARCHAR2,
p_business_num IN NUMBER,
p_businesses IN table_typ_businesses)
return table_typ_bankers
as .......
global object and table types
CREATE OR REPLACE TYPE obj_typ_businesses AS OBJECT (businesses NUMBER);
CREATE OR REPLACE TYPE table_typ_businesses AS TABLE OF obj_typ_businesses;
CREATE OR REPLACE TYPE obj_typ_bankers AS OBJECT (banker_num NUMBER(10,0));
CREATE OR REPLACE TYPE table_typ_bankers IS TABLE OF obj_typ_bankers;
The select query
select * from
table(cast(FUNCTION_DEMO(1,
2,
'ALEX',
2,
table(cast(select businesses_id from reference_businesses) as table_typ_businesses) as table_typ_bankers)But it is giving error with Missing expression.
My function is compiled successfully. I just want to make the select query to view the output given by the function i.e the table type "table_typ_bankers".
Please help...thanks in advance..Hi ,
You can check this and change your code by taking this as an example. I just noted down with simple one input and return as collection type
and how to use/call it in select statement.
SQL> CREATE OR REPLACE TYPE obj_typ_businesses AS OBJECT (businesses NUMBER)
2 /
Type created.
SQL> CREATE OR REPLACE TYPE table_typ_businesses AS TABLE OF obj_typ_businesses
2 /
Type created.
SQL> CREATE OR REPLACE TYPE obj_typ_bankers AS OBJECT (banker_num NUMBER(10,2))
2 /
Type created.
SQL> CREATE OR REPLACE TYPE table_typ_bankers IS TABLE OF obj_typ_bankers
2 /
Type created.
/* Now creating a demo function and just focusing on your one input as collection type */
SQL> create or replace function f11 ( tab_rec IN table_typ_businesses)
2 return table_typ_bankers
3 is
4 t_val table_typ_bankers:= table_typ_bankers();
5 begin
6 dbms_output.put_line('tab_rec count -'||tab_rec.count);
7
8 for i in 1..tab_rec.count
9 loop
10 dbms_output.put_line ('tab_rec value ('||i||')'||tab_rec(i).businesses);
11 t_val.EXTEND;
12 t_val(i) := obj_typ_bankers(tab_rec(i).businesses * 12.50);
13 end loop;
14 return t_val;
15 end;
16 /
Function created.
/* To run your function by a select statement */
SQL> SELECT * FROM TABLE(f11(table_typ_businesses(obj_typ_businesses(5),
2 obj_typ_businesses(12),
3 obj_typ_businesses(18))
4 ) )
5 /
BANKER_NUM
62.5
150
225
tab_rec count -3
tab_rec value (1)5
tab_rec value (2)12
tab_rec value (3)18Hope this will help you... :)
Thanks!
Ashutosh -
How to remove column name in select clause
Hello Guys,
I just want to remove a column name in select clause. Because, I don't want to write all column names. I hope I express myself.
In other words, I want the following.
Select * - unwanted_column from table;
instead of this
Select col1, col2, col3, col4, ........ col 10000 from table;Hi,
Sorry, there's nothing in SQL that means "all columns *except* ...". As the others have said, the only way to get those results in SQL is to list all the columns you do want.
Your front end may have some feature that allows you to hide a specific column. For example, in SQL*Plus, you can use <tt> COLUMN ... NOPRINT </tt> , like this:
COLUMN dname NOPRINT
SELECT *
FROM scott.dept
ORDER BY dname
;Output:
` DEPTNO LOC
10 NEW YORK
40 BOSTON
20 DALLAS
30 CHICAGOThere is a column called dname in the scott.dept table; the query above actually uses it. But, because of the COLUMN command, SQL*Plus won't display that column.
Edited by: Frank Kulash on Feb 26, 2013 10:10 AM
Changed scott.dept example. -
Maximum no. of columns allowed in SELECT clause - Urgent please
Hi,
I am constructing SQL query dynamically in a stored proc. based on user inputs. I am getting following error when I have around 400 columns in my SELECT clause. FROM, WHERE, GROUP BY clauses are same eventhough I have 30 columns and I don't have any problems here. Can anyone please let me know what is maximum no. of columns allowed in a query. I am working on Oracle 9i Release2.
Thanks in advance.ORA-01467 sort key too longIt's not the SELECT clause that causes this, it's most likely the GROUP BY clause. Basically, the columns in the GROUP BY clause have to fit comfortably within a single database block. Does that sound like it might be a problem with your query?
Cheers, APC
Message was edited by:
APC -
Select clause with where part is needs 600 times longer to complete
Hello.
I have two select clauses one with where, which needs 120 seconds to complete and one without where, which completes in 0,3 seconds. I want to know why is that.
120 seconds
SELECT B.* FROM
(SELECT A.OLOG, MCL_ISPROTOCOLALLOWED('LMOD', 'MCLI', A.OPRG) ALLOWED FROM (SELECT DISTINCT OLOG, OPRG FROM FLOG WHERE FIRM = '001') A) B WHERE B.ALLOWED = '1' ORDER BY OLOG;0,3 seconds
SELECT B.* FROM
(SELECT A.OLOG, MCL_ISPROTOCOLALLOWED('LMOD', 'MCLI', A.OPRG) ALLOWED FROM (SELECT DISTINCT OLOG, OPRG FROM FLOG WHERE FIRM = '001') A) B ORDER BY OLOG;Table FLOG has arround 270000 records, but only 40 of them are distinct.
IsProtocolAllowed checks if user has a permision to view the record.
Thank you for your help.
Regards,
Borut Ojcinger
Edited by: 993896 on 14.3.2013 7:24Hi,
welcome to the forum.
Please read SQL and PL/SQL FAQ
If you have a performance issue have a look at SQL and PL/SQL FAQ
Additionally when you put some code or output please enclose it between two lines starting with {noformat}{noformat}
i.e.:
{noformat}{noformat}
SELECT ...
{noformat}{noformat}
Regards.
Al -
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.
Maybe you are looking for
-
hi , I want to display a given set of nationalities(25/250) in the combobox of my module pool screen. I hav used POV as follows . process on value-request. field P0002-NATIO module onvalue_land1. MODULE onvalue_land1 INPUT. data : GT_LAND TYPE T005T
-
Hi, I recently purchase a CP1025nw color laserjet printer and am using the network (hard wired to my router) version. I upgraded the firmware and drivers on computer running Windows 7 64bit. The issue I am having is when I try to print a configurat
-
Why does my While loop not work?
I was using the SetInterval timer but this kept causing problems getting the timing right, So I thought - get the loop to work infiitely... var cond=0; while (cond !=1){ $("#DivStage1").fadeIn(1000); $("#DivStage1").delay(6500).fadeOut(500); //8000 $
-
What is the safest way to move iPad iTunes sync from an old laptop to a new one?
-
Hi,I am new to webcenter, and my situation is : I develop a very simple bounded task flow(using page fragement) which just shows the employees list and emplee detail info views, nothing special and it works well in the jsf page as region, then I crea