Short table name in SELECT statement
Does Oracle support anything like the following sintax:
SELECT * FROM TABLE1 AS T1
Thanks in advance
syntex use like....
create table T1 select * from T2.
test@ORA10G>
test@ORA10G> create table t2 (x number);
Table created.
test@ORA10G> create table T1 select * from T2;
create table T1 select * from T2
ERROR at line 1:
ORA-00922: missing or invalid option
test@ORA10G>
test@ORA10G>pratz
Similar Messages
-
How to use bind variable value for table name in select statement.
Hi everyone,
I am having tough time to use value of bind variable for table name in select statement. I tried &p37_table_name. ,
:p37_table_name or v('p37_table_name) but none worked.
Following is the sql for interactive report:
select * from v('p37_table_name') where key_loc = :P37_KEY_LOC and
to_char(inspection_dte,'mm/dd/yyyy') = :P37_INSP_DT AND :p37_column_name is not null ;
I am setting value of p37_table_name in previous page which is atm_state_day_insp.
Following is error msg:
"Query cannot be parsed, please check the syntax of your query. (ORA-00933: SQL command not properly ended) "
Any help would be higly appreciated.
RajInterestingly enough I always had the same impression that you had to use a function to do this but found out from someone else that all you need to do is change the radio button from Use Query-Specific Column Names and Validate Query to Use Generic Column Names (parse query at runtime only). Apex will substitute your bind variable for you at run-time (something you can't normally do in pl/sql without using dynamic sql)
-
How user variable table names in select statement
Dear all,
I have three table gp1,gp2,g3. i want user variable table in sql query
for example at oracle forms have a list table showing table names gp1,gp2,gp3
at form i want user this query
select gpno from :table where gpno=120;
how i can specify table name Dynamicly in select query
ThanksForms_DDL is a one-way street: You can only pass DDL commands TO the database; you cannot get data back using Forms_DDL.
Exec_SQL is the Forms package that enables dynamic sql within a form. But to retrieve data, you have to make a Exec_SQL call for every column in every row. So it is not a good thing to use, either.
The ref cursor method should work. You could also retrieve the data into a record group using populate_group_with_query -- it also enables dynamic data retrieval.
But if you already know you have three distinct tables and you know their names, I would keep it simple and just write three sql select statements. -
Dynamically assigning table name in select statement
how can i assign the table name dynamically in Select statement?
i tried following code
create or replace procedure proc1
as
x varchar2(100);
y varchar2(10);
begin
x='UNIT_MASTER';
execute immediate 'select unit_code into y from x where
rownum=1';
dbms_output.put_line(y);
end;
the procedure is created but when i execute the procedure the
error is shown in the execute immediate statementDo the following :
Create or replace procedure pro1 as
x varchar2(100);
y varchar2(10);
begin
x := 'UNIT_MASTER';
EXECUTE IMMEDIATE 'select unit_code from '||x||' where rownum
= 1' INTO y;
dbms_output.put_line(y); -
How to insert variable for table name in Select statement ?
I am creating a stored procedure which will take two table names as IN parameters. Within the procedures I would like to use the parameters in the following manner;
SELECT count(*)
INTO v_target_cnt
FROM TargetTable;
TargetTable is one of the parameters passed in. When I do this however it does not recognize the parameter. I have tried assigning the parameter to a local variable and using the variable, with not luck.
Any help....thanksNull,
What you are describing is called a LEXICAL parameter, which is allowed (preceded by an ampersand) in sql but not in pl/sql because it would not be possible to compile it. That is why you need to use Andrew's suggestion to make the sql dynamic. In older versions you would need to use DBMS_SQL which is horrible and now thankfully redundant. -
How to assign table name for select query in loop.
Hi friends my requirement is count the no of records of all the database table which comes into an internal table ."Check the below coding". Iam fetching the tables from dd03l table into an internal table .plz give me a sujjesion how to assign a table name in select query in a loop.
SELECT tabname FROM dd09l
INTO TABLE i_dd09l
WHERE protokoll = 'X'.
IF sy-subrc = 0.
SORT i_dd09l BY tabname.
ENDIF.
LOOP AT i_dd09l.
SELECT COUNT(*) INTO val FROM i_dd09l-tabname.
IF sy-subrc = 0.
i_dd09l-count = val.
ENDIF.
MODIFY i_dd09l INDEX sy-index.
CLEAR val.
ENDLOOP.
error : 'I_DD09L-TABNAME' is not defined in the abap dictionary as a table.data: dy_table type ref to data,
dy_line type ref to data,
xfc type lvc_s_fcat,
ifc type lvc_t_fcat,
dy_field type ref to data.
LOOP AT i_dd09l.
perform get_structure using i_dd09l-tabname .
CREATE DATA dy_table TYPE TABLE OF (_dd09l-tab_name).
UNASSIGN <dyn_table>.
ASSIGN dy_table->* TO <dyn_table>.
SELECT COUNT(*) INTO val FROM <dyn_table>.
IF sy-subrc = 0.
i_dd09l-count = val.
ENDIF.
MODIFY i_dd09l INDEX sy-index.
CLEAR val.
ENDLOOP.
form get_structure using p_table.
data : idetails type abap_compdescr_tab,
xdetails type abap_compdescr.
data : ref_table_des type ref to cl_abap_structdescr.
Get the structure of the table.
ref_table_des ?=
cl_abap_typedescr=>describe_by_name( p_table ).
idetails = ref_table_des->components.
loop at idetails into xdetails.
clear xfc.
xfc-fieldname = xdetails-name .
xfc-datatype = xdetails-type_kind.
xfc-inttype = xdetails-type_kind.
xfc-intlen = xdetails-length.
xfc-decimals = xdetails-decimals.
append xfc to ifc.
endloop.
endform. "get_structure
Try like this hope it will work.
Regards,
madan. -
How to join THREE different tables into internal table using one select statement .
How to join THREE different tables into internal table using one select statement .
Hi experts,
I would like to request your guidance in solving the problem of joining the data from three different database tables into one internal table
Scenario:
Database tables:
SPFLI
SFLIGHT
SBOOK.
Table Fields:
SPFLI - CARRID CONNID COUNTRYFR CITYFRM COUNTRYTO CITYTO
SFLIGHT - CARRID CONNID FLDATE SEATSMAX SEATSOCC SEATSMAX_C
SEATSOCC_C SEATSMAX_F SEATSOCC_F
SBOOK - CARRID CONNID CLASS
MY INTERNAL TABLE IS IT_XX.
Your help much appreciated.
Thanks in advance.
Pawan.Hi Pawan,
please check below codes. hope it can help you.
TYPES: BEGIN OF ty_xx,
carrid TYPE spfli-carrid ,
connid TYPE spfli-connid ,
countryfr TYPE spfli-countryfr,
cityfrom TYPE spfli-cityfrom ,
countryto TYPE spfli-countryto,
cityto TYPE spfli-cityto ,
fldate TYPE sflight-fldate ,
seatsmax TYPE sflight-seatsmax ,
seatsocc TYPE sflight-seatsocc ,
seatsmax_b TYPE sflight-seatsmax_b,
seatsocc_b TYPE sflight-seatsocc_b,
seatsmax_f TYPE sflight-seatsmax_f,
seatsocc_f TYPE sflight-seatsocc_f,
class TYPE sbook-class,
END OF ty_xx,
t_xx TYPE STANDARD TABLE OF ty_xx.
DATA: it_xx TYPE t_xx.
SELECT spfli~carrid
spfli~connid
spfli~countryfr
spfli~cityfrom
spfli~countryto
spfli~cityto
sflight~fldate
sflight~seatsmax
sflight~seatsocc
sflight~seatsmax_b
sflight~seatsocc_b
sflight~seatsmax_f
sflight~seatsocc_f
sbook~class
INTO TABLE it_xx
FROM spfli INNER JOIN sflight
ON spfli~carrid = sflight~carrid
AND spfli~connid = sflight~connid
INNER JOIN sbook
ON spfli~carrid = sbook~carrid
AND spfli~connid = sbook~connid.
Thanks,
Yawa -
Is it Possible to join 4 or more tables in a Select Statement?
Hello guys,
Can I do Inner Join 4 or 5 tables in a select statement?U HAVE TO SERCH FOR KEY FIELD FOR THAT . MEANS HOW TABELS ARE RELATED EACH OTHE FOR THIS U ALSO USE SQ02
FOR EXAMPLE
SELECT bkpf~belnr
bkpf~gjahr
bkpf~bukrs
bkpf~blart
bkpf~bldat
bkpf~budat
bkpf~usnam
bkpf~tcode
bkpf~xblnr
bsik~lifnr
bsik~bupla
bsik~secco
INTO CORRESPONDING FIELDS OF TABLE itab_pur
FROM bkpf INNER JOIN bsik
ON bkpfbelnr = bsikbelnr
and bkpfbukrs = bsikbukrs
WHERE bkpf~bukrs IN co_code
AND bkpf~budat IN pos_dt
AND bkpf~tcode IN t_code
AND bsik~secco IN se_code.
U CAN ALSO ADD MORE TABLE BASED ON CONDITION -
Need a that Table Name in Select command which being used in from statement
My Question Is:
If my SQL command is like this "
Select Code, Name from Customer (Table Name)
Can I get this output in this Way .. ?
Select Code, Name,Customer(Table Name) from Customer (Table Name)
in dynamic way ..NO. You missing many fundamental concepts of RDBMS. A table is a set of entities, so it's name is plural or collective(unless you really do have only one customer as you said). There is no such thing as a generic "name", or "code" in RDBMS. Those affixes
are called attribute properties, and they have to be part of an attribute data element name -- customer_name, postal_code, etc.
Since a table is a set, its columns are fixed and known in the schema. They do not change by magic! This kind of non-RDBMS thinking is called "Automobiles, Squids and Lady GaGa" coding. Please read any intro book on RDBMS. Your whole mindset is wrong.
--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 -
Short dump with a select statement
I have the following select statement (I have also inluded my data statement(s)) and I get a short dump. The error is as follows:
<b>What happened?
Error in ABAP application program.
The current ABAP program "ZPARTNER" had to be terminated because one of the
statements could not be executed.
This is probably due to an error in the ABAP program.
Following a SELECT statement, the data read could not be placed in AN
the output area.
A conversion may have been intended that is not supported by the
system, or the output area may be too small.
Error analysis
An exception occurred. This exception will be dealt with in more detail
below. The exception, assigned to the class 'CX_SY_OPEN_SQL_DB', was not
caught, which
led to a runtime error. The reason for this exception is:
The data read during a SELECT access could not be inserted into the
target field.
Either conversion is not supported for the target field's type or the
target field is too short to accept the value or the data are not in a
form that the target field can accept </b>
it_adrc TYPE TABLE OF adrc,
wa_adrc LIKE LINE OF it_adrc,
SELECT addrnumber name1 street city1 region post_code1 tel_number
FROM adrc INTO TABLE it_adrc
FOR ALL ENTRIES IN it_detail
WHERE addrnumber = it_detail-adrnr.
Regards,
DavisIf you only need the fields mentioned in the select query, then follow this:
TYPES: BEGIN OF ADRC_TYPE,
ADDRNUMBER LIKE ADRC-ADDRNUMBER,
NAME1 LIKE ADRC-NAME1,
STREET LIKE ADRC-STREET,
CITY LIKE ADRC-CITY,
REGION LIKE ADRC-REGION,
POST_CODE1 LIKE ADRC-POST_CODE1,
TEL_NUMBER LIKE ADRC-TEL_NUMBER,
END OF ADRC_TYPE,
ADRC_T_TYPE TYPE TABLE OF ADRC_TYPE.
DATA: IT_ADRC TYPE ADRC_T_TYPE WITH HEADER LINE.
IF NOT IT_DETAIL[] IS INITIAL.
SELECT addrnumber name1 street city1 region post_code1 tel_number
FROM adrc INTO TABLE it_adrc
FOR ALL ENTRIES IN it_detail
WHERE addrnumber = it_detail-adrnr.
ENDIF.
Thanks,
SKJ -
Dynamic table name in select statment
hai,
Please help me....
oracle 9i i am using.
i have four tables abc_121,
abc_122,
abc_123,
abc_124.
i want to pick records from a table.table name should be prepared dynamically.
i.e., i want to pick records from a quarter table of this year.(ex: abc_124). using sql statement only.
i have tried..but i couldn't...... pls help me...ramadurga.v wrote:
oracle 9i i am using.
i have four tables abc_121,
abc_122,
abc_123,
abc_124.
i want to pick records from a table.table name should be prepared dynamically.
i.e., i want to pick records from a quarter table of this year.(ex: abc_124). using sql statement only.Create a partition view. E.g.
create or replace view abc as
select * from abc_121
union all
select * from abc_122
union all
...For the partition view approach to correctly work (doing "partition pruning"), you need to have a constraint on the column that identifies that partition.
In other words, you cannot use the table name as an attribute to identifies its data content. Foe example, you can have tables YEAR2001_Q1 and YEAR2001_Q2. However, the year and quarter also need to be in the table itself - e.g. columns YEAR and QUARTER.
For table YEAR2001_Q1, the YEAR column needs to have a check constraint that ensures it is always 2001. And a check constraint for column QUARTER to ensure that it is always 1.
If these conditions are met, then a select from the partition view using +"where YEAR=2001 and QUARTER=2"+ will result in only table YEAR2001_Q2 to be used and not other tables like YEAR2001_Q1.
See {message:id=10539404} for an example. -
Using Table name in Read statement dynamically
Hi Experts,
I have the following requirement.
Based on a country code say "A" , "B", "C" and based on this i have to read different internal tables lt_tabA, lt_tabB and lt_tabC.
The table key can be given dynamically, but how can i use the internal table name dynamically without using if statements.
Please help.
Thanks!
Best Regards,
GayathriHi Gayathri,
something like
DATA:
lt_t100 TYPE TABLE OF t100,
lt_t000 TYPE TABLE OF t000.
FIELD-SYMBOLS:
<table> TYPE table,
<rec> TYPE ANY,
<field> TYPE ANY.
SELECT:
* INTO CORRESPONDING FIELDS OF TABLE lt_t100 FROM t100 UP TO 10 ROWS,
* INTO CORRESPONDING FIELDS OF TABLE lt_t000 FROM t000 UP TO 10 ROWS.
CASE abap_true.
WHEN space.
ASSIGN lt_t100 TO <table>.
WHEN OTHERS.
ASSIGN lt_t000 TO <table>.
ENDCASE.
READ TABLE <table> with key ('MANDT') = sy-mandt ASSIGNING <rec>.
Regards,
Clemens -
Use table name in UPDATE statement as variable
Hi All,
I am using ORACLE 9i AIX base. I want to write following procedure:
PROCEDURE update_header (
p_care_msg_nbr IN NUMBER,
p_care_msg_id IN NUMBER,
p_care_msg_gkey IN NUMBER,
p_old_status IN VARCHAR2,
p_new_status IN VARCHAR2
IS
l_table varchar2(50);
BEGIN
l_table := 'CARE_EDI_MESSAGES';
UPDATE '&l_table'
SET status = p_new_status,
changed = sysdate,
changer = user
WHERE care_msg_no = p_care_msg_nbr
AND care_msg_id = p_care_msg_id
AND gkey = p_care_msg_gkey
AND status = p_old_status;
END;
I want to give the table name by passing value in a variable or parameter. Is it the write way or can I do this function in any other way.
Pleae tell me in urgency.
Thanks & Regards
Hassan RazaThis implies that you have several tables with identical or near identical structures, otherwise you will get errors if any of the mentioned columns do not exist in the table passed but ...
You cannot use a substitution variable that way. Oracle will ask for a value when you try to create the procedure, and compile what ever value you supply into the procedure viz.
SQL> CREATE PROCEDURE p AS
2 l_id NUMBER;
3 BEGIN
4 SELECT id INTO l_id FROM &t;
5 END;
6 /
Enter value for t: T
old 4: SELECT id INTO l_id FROM &t;
new 4: SELECT id INTO l_id FROM T;
Procedure created.
SQL> SELECT text FROM user_source WHERE name = 'P'
2 ORDER BY line;
TEXT
PROCEDURE p AS
l_id NUMBER;
BEGIN
SELECT id INTO l_id FROM T;
END;Even if that is the effect you want, note that there are no quotes around the substitution variable in the CREATE statement.
If you want to be able to pass the name of the table to the procedure, then you need to make the table name a parameter, then build the sql statement and execute it using EXECUTE IMMEDIATE. Something more like:
PROCEDURE update_header (p_care_msg_nbr IN NUMBER,
p_care_msg_id IN NUMBER,
p_care_msg_gkey IN NUMBER,
p_old_status IN VARCHAR2,
p_new_status IN VARCHAR2,
p_table IN VARCHAR2) IS
l_sqlstr VARCHAR2(4000);
BEGIN
l_sqlstr := 'UPDATE '||p_table||' SET status = :b1 '||
'changed = sysdate, changer = user '||
'WHERE care_msg_no = :b1 and care_msg_id = :b3 and '||
'gkey = :b4 and status = :b5';
EXECUTE IMMEDIATE l_sqlstr
USING p_new_status, p_care_msg_nbr, p_care_msg_id, p_care_msg_gkey, p_old_status;
END;HTH
John -
Specify schema name in select statements
Is there a way to specify the schema name for the connection so that I don't have to specify schema name with every statement?
Currently I am executing the statement:
Statement stmt = null;
ResultSet rs = null;
String getAllNames =
"SELECT NAME FROM " + schemaName +".NAMES " + schemaName +" WHERE STATUS_CODE != 12 ";
stmt = conn.createStatement();
rs = stmt.executeQuery(getAllNames);
But I have a lot of such statements, a few which uses parameters.
Is there a way I can specify the schemaName once and for all so that I don't have to perform string concat everytime the function is invoked.well I tried that, since the application runs under CICS which uses the trusted connection with DB2, all CICS application will be using the same userid and there is no way to ensure that other applications would not be using the same table name in some other application. So the only option I have is to specify the schema name with the select statements but I don't want to append the schema name with each statement.
-
Cannot use alias for dynamic column name in SELECT statement
Hi,
I want to retrieve values from several tables by using dynamic column & table name as below:
DATA: tbl_name(30) TYPE c VALUE '/bic/tbi_srcsys', " staticly initialized for this example
col_name(30) TYPE c VALUE '/bic/bi_srcsys'. " staticly initialized for this example
SELECT (col_name) INTO CORRESPONDING FIELDS OF TABLE it_values FROM (tbl_name).
The internal table "it_values" does not contain a field named "/bic/bi_srcsys", instead it has another generic field "value" so that the above code can be applied to other tables. I tried to use alias (AS) as below:
SELECT (col_name) AS value INTO CORRESPONDING FIELDS OF TABLE it_values FROM (tbl_name).
But this cannot work. I know that there are other ways to solve this problem, such as by using a single field in SELECT .. ENDSELECT and subsequently appending it to the work area and internal table as below:
SELECT (col_name) INTO (lv_value) FROM (tbl_name).
wa_value-value = lv_value.
APPEND wa_value TO it_values.
ENDSELECT.
Just wonder if there is any other more elegant workaround, because I might have several other fields instead of only one?
Thanks.
Regards,
Joon MengHi Suhas,
thanks for the quick reply.
Sorry that I have not well described the structure of the internal table "it_values". This internal table contains several other fields (key, type, value, etc.).
I guess that the following code
SELECT (col_name) INTO TABLE it_values FROM (tbl_name).
works if the internal table only has one field (value) or the field "value" is in the first position, right?
In this case, I need to fill the "value" field of internal table it_values (ignore the other fields like type, key) with values retrieved from (col_name) of the DDIC table.
Looking forward to your reply.
BR,
Joon Meng
Maybe you are looking for
-
Mac mini 2009 . Mini DVI - VGA adapter with Monitor LG L1953S . No sleep .
Hi .. Yesterday i started in the fabulous world of MAC with my brand new MAC MINI . The problem that i have is that when the MAC mini is in stand-by the monitor is not in sleep state , and i get in the monitor screen " check cable " . So i have to di
-
Error connecting weblogic server 10.3.6.0 64bits
Hello I installed weblogic server 10.3.6.0 64bits on windows server 2008 R2 64bits. I have jdeveloper 11.1.1.7.0 installed on client machines which are xp pro 32bits and win 7 32bits. When I try to connect weblogic server from jdeveloper it is giving
-
PDF from HTMLLoader is Not Displaying in a Container
PDF from HTMLLoader is Not Displaying in a Container Was there a new version of AIR released recently that breaks the display of a PDF through the HTMLLoader? I've been experiencing problems displaying a PDF in a container lately. AIR applications th
-
Is it possible top render an Adobe Interactive form as HTML instead of PDF?
Currently a form developed as an Adobe interactive form is presented to the user as a PDF document (this is somewhat obvious!!!!) If, for whatever reason, we are unable to use Adobe reader on the front end PC is there a way to configure ADS to render
-
please help me out .. my camera flash was not working. jus bought iphone 5 in singapore and jus boarded ship. so i dont have mobile signal and call to apple customer care. so plz do help. i already reset to factory setting, but still same .