can someone tell me how to write a statement to get all the fields of a database table instead of creating a work area with each field name of database table?
DATA gt_dd03l TYPE STANDARD TABLE OF dd03l INITIAL SIZE 0.
SELECT * FROM dd03l "Table Fields
INTO TABLE gt_dd03l
WHERE tabname = 'table name'.
You can do the following:
* define Table type of Business Partner Table BUT000
data: lt_table type table of but000 .
* Create Structure of the corresponding table type
data: ls_table like line of lt_table .
Related
When querying table using "select * from t2p", the reponse is as blow. I think I have missed some concepts, please help me out.
Failed with exception java.io.IOException:java.lang.ClassCastException: org.apache.hadoop.hive.serde2.lazy.objectinspector.LazyMapObjectInspector cannot be cast to org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector
Step1, create table
create table t2p(id int, name string, score map<string,double>)
partitioned by (class int)
row format delimited
fields terminated by ','
collection items terminated by '\\;'
map keys terminated by ':'
lines terminated by '\n'
stored as textfile;
Step2, insert data like
1,zs,math:90.0;english:92.0
2,ls,chinese:89.0;math:80.0
3,xm,geo:87.0;math:80.0
4,lh,chinese:89.0;english:81.0
5,xw,physics:91v;english:81.0
Step3, add another column
alter table t2p add columns (school string);
Step4, change column's order
alter table t2p change school school string after name;
Step5, do query and get error as mentioned above.
select * from t2p;
This is an obvious error.
Your command alter table t2p change school school string after name; changes metadata only. If you are moving columns, the data must already match the new schema or you must change it to match by some other means.
Which means, the map column has to be matching to the new column. In other words, if you want to move column around, make sure new column and existing data types are same.
I did a simple experiment with int data type. It worked because data type are not hugely different but you can see metadata changed but data stayed same.
create table t2p(id int, name string, score int)
partitioned by (class int)
stored as textfile;
insert into t2p partition(class=1) select 100,'dum', 199;
alter table t2p add columns (school string);
alter table t2p change school school string after name;
MSCK REPAIR TABLE t2p ;
select * from t2p;
You can see new column school is mapped to position 3( defined as INT).
Solution - You can do this but make sure new structure+data type is compatible to old structure.
I created a structure in SE11 with the following columns:
column name type (data element)
----------- -------------------
mandt mandt
itemdesc arktx
quantity lfimg
tweight gsgew
I created a table type ZPACK_DETAIL in SE11 whose line type is the structure above.
Then I used the code below to declare an internal table and fill it with data from the database table:
DATA : dresult TYPE zpack_detail .
SELECT arktx lfimg ntgew
FROM lips AS detail LEFT JOIN marm AS material
ON detail~matnr = material~matnr
LEFT OUTER JOIN vbak
ON detail~vgbel = vbak~vbeln
INTO TABLE dresult
WHERE detail~vbeln = '001'.
The activation reports this warning message:
The data type of the component ITEMDESC of DRESULT is not compatible with the data type of LFIMG.
Can someone give me a hint what's wrong? Is there something wrong with the way I'm declaring the internal table?
In fact there are couple of issues with your code.
You have to declare your variable as an internal table. ZPACK_DETAIL is a structure table and not a table type.
DATA: dresult TYPE STANDARD TABLE OF zpack_detail WITH EMPTY KEY.
Second of all. You should not use MANDT field as your query is not client indepentent. Remove this field from your structure or use INTO CORRESPONDING FIELDS OF TABLE and adjust your projection to SELECT arktx AS itemdesc lfimg AS quantity ntgew AS tweight.
I am trying to alter the column size of a view with the same command that we use for table like :
alter table
STUDENT
modify (
ROLL_NO VARCHAR2(80)
);
But its throwing error
SQL Error: ORA-00942: table or view does not exist
So how we can alter the column size of a view?
A view is simply saved query and "inherits" column type from underlying base table. So if you need to change metadata you should alter view definition:
ALTER VIEW view_students
AS
SELECT CAST(roll_no AS VARCHAR2(80)) AS roll_no,
...
FROM tab_students;
If you want to change data type to store longer strings, then you need to locate base table and alter it instead:
ALTER VIEW tab_students
MODIFY (ROLL_NO VARCHAR2(80));
Here is the procedure that I followed :
1- First find the base table for that view by running the following query
SELECT * FROM DBA_DEPENDENCIES
WHERE OWNER = '<scheman_name>'
AND NAME = '<view_name>'
AND TYPE = 'VIEW';
2- Above query will you a table where you will find the base table under the column name 'REFERENCED_NAME'.
3- Now Change the column size of that base table.
NOTE: The view can be made up of 1 or more than 1 tables, so you need to change the column size of all those base tables.
I want to create a table in Hive using a select statement which takes a subset of a data from another table. I used the following query to do so :
create table sample_db.out_table as
select * from sample_db.in_table where country = 'Canada';
When I looked into the HDFS location of this table, there are no field separators.
But I need to create a table with filtered data from another table along with a field separator. For example I am trying to do something like :
create table sample_db.out_table as
select * from sample_db.in_table where country = 'Canada'
ROW FORMAT SERDE
FIELDS TERMINATED BY '|';
This is not working though. I know the alternate way is to create a table structure with field names and the "FIELDS TERMINATED BY '|'" command and then load the data.
But is there any other way to combine the two into a single query that enables me to create a table with filtered data from another table and also with a field separator ?
Put row format delimited .. in front of AS select
do it like this
Change the query to yours
hive> CREATE TABLE ttt row format delimited fields terminated by '|' AS select *,count(1) from t1 group by id ,name ;
Query ID = root_20180702153737_37802c0e-525a-4b00-b8ec-9fac4a6d895b
here is the result
[root#hadoop1 ~]# hadoop fs -cat /user/hive/warehouse/ttt/**
2|\N|1
3|\N|1
4|\N|1
As you can see in the documentation, when using the CTAS (Create Table As Select) statement, the ROW FORMAT statement (in fact, all the settings related to the new table) goes before the SELECT statement.
I get this error:
In a SELECT access, the read file could not be placed in the target field provided.
when executing this line of code:
SELECT vbeln
posnr
matnr
netpr
netwr
kondm
FROM vbap INTO TABLE t_tab
FOR ALL ENTRIES IN postab
WHERE vbeln = postab-vbeln.
I try one by one, and every time I put a currency field it will trigger this dump. Anyone know the root cause?
How is your t_tab declared? It seems like it is declared like a structure or, maybe, component order is wrong. Try to make declarations like this:
DATA: postab LIKE TABLE OF vbap,
t_tab LIKE TABLE OF vbap.
and replace INTO clause with this piece of code
FROM vbap INTO CORRESPONDING FIELDS OF TABLE t_tab
If your fields in the t_tab have other names then the fields your selecting be sure to match these with as:
SELECT vbeln AS ....
posnr AS ....
matnr AS ....
netpr
netwr
kondm
FROM vbap INTO TABLE t_tab
FOR ALL ENTRIES IN postab
WHERE vbeln = postab-vbeln.
If they have the same names try INTO CORRESPONDING FIELDS OF TABLE.
Also be sure that the fields in the t_tab have the right format.