How to see Table detail when writing query? - oracle

How to see Table detail when writing query?
Hi, i am new to using Embarcadero DBArtisan for Oracle and Syabase queries executions.
but i am unable to see the tables and fields information when i write queries.
Forexample:
Databasname.User.Table.Fields
Suppose if i write first Database name and write .(dot) it should show me all users and when i pick one user and write .(dot) agian it should show me all tables inside and when i pick one table and write .(dot) it should show me all the fields inside.
But it is not doing that way. every time i have to describe table to find the specific field in the table.
I am woundering if i have to choose some option to see this information.
Thank you very much for your help.

Sybase, there is no User.
I think you have to write a cursor to loop over the DBs on a server.
For the rest of your question:
select db_name() 'databasename', b.name 'table', a.name 'fields'
from syscolumns a, sysobjects b
where a.id = b.id
-- and b.type = 'U' -- User tables only

It seems that there is a setting in Code Workbench. Please see page 733 in the DBArtisan User Guide.
From the Manual,
In the ISQL Window, when Enable Auto Replacement is selected on the Setting Tab,
the application uses "dot completion" auto population to display the list of columns
for the target table.

Related

How to Create a VIEW in oracle

So I'm supposed to create a view product_view that presents the information about how many products of a particular type are in each warehouse: product ID, product name, category_id, warehouse id, total quantity on hand for this warehouse.
So I used this query and tried to change it so many times but I keep getting errors
CREATE OR REPLACE VIEW PRODUCT_VIEW AS
SELECT p.product_id, p.product_name,
COUNT(p.product_id), SUM(i.quantity_on_hand)
FROM oe.product_information p JOIN oe.inventories i
ON p.product_id=i.product_id
ORDER BY i.warehouse_id;
ERROR at line 2:
ORA-00928: missing SELECT keyword
Please help... Thanks
Image showing the Tables in the OE schema
Image showing the error that occurs
When I get errors creating a view, I firstly drop the CREATE ... AS line and fix the query until it works. Then you need to name all the columns, for instance COUNT(p.product_id) won't work, you'll need to write something like COUNT(p.product_id) AS product_count or specify a list of aliases, like so
I'm not sure what the output of your query should look like. You'll get better answers quicker on stackexchange if you type a minimal example including the CREATE statments, some input data and your desired output, leaving out columns that are not essential.

Using FOR ALL ENTRIES for validation multiple lines

I have a question concerning the For all Entries statement in ABAP.
I know that it functions like a Select Distinct and deletes duplicate entries.
In my case, I want to write a validation for table inputs. As you can enter more than one line, I have to check every single one of them.
Loop with Select is not an Option. The alternative is For all Entries. Sadly if f.e. the same company code needs to be validated, FoE just gives back one entry. So I have no chance to identify where the error was (if there is one).
Here is the Code for the validation:
LOOP AT extract.
IF <xact> NE empty.
READ TABLE total WITH KEY <vim_xextract_key>.
IF sy-subcs EQ 0.
MOVE <vim_total_struc> TO ls_y.
APPEND ls_y TO lt_y.
ENDIF.
ENDIF.
ENDLOOP.
SELECT bukrs
FROM t001
FOR ALL ENTRIES IN #lt_y
WHERE bukrs = #lt_y-bukrs
INTO TABLE #DATA(lt_check_bukrs).
IF lt_check_bukrs IS INITIAL.
MESSAGE 'Error in company code' TYPE 'S' DISPLAY LIKE 'E'.
vim_abort_saving = abap_true.
ENDIF.
Maybe one of you has an approach or an idea.
Thank you for all answers!
Considering that the company code table should not be too long (in any sanely configured system), I would load it into the application server and do the comparison on the ABAP layer instead of the database layer.
SELECT bukrs
FROM t001
INTO TABLE #DATA(lt_all_bukrs).
LOOP AT lt_check_bukrs REFERENCE INTO DATA #(lr_check_bukrs).
IF NOT line_exists( lt_all_bukrs[ lr_check_burks->bukrs ] )
MESSAGE |Document { lv_check_bukrs->belnr } has invalid company code { lr_check_burks->bukrs }| TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.
ENLOOP.
In a different case where this is not viable because the table you want to compare with is so large it would cause a TSV_TNEW_PAGE_ALLOC_FAILED, then I would go back to where you acquired the original data and perform an OUTER JOIN with the comparison table:
SELECT bkpf~opbel,
bkpf~bukrs
FROM bseg
LEFT OUTER JOIN t001 ON bkpf-burks = t001~bukrs
INTO TABLE
WHERE t001~bukrs IS NULL.
The result table should be all financial document numbers with invalid company codes.
Should this also be impossible because the source data doesn't come from the database (manual entry, read from a file, received from a webservice, whatever...) then the last option would be to pass that data to an ABAP-Managed Database Procedure. Because SQLScript can do JOINs between database tables and tables in memory. But that does require that you are using a SAP HANA database.

ORA-02019:connection description for remote database not found - left join in a view

I have 3 tables:
table1: id, person_code
table2: id, address, person_code_foreing(same with that one from table 1), admission_date_1
table3: id, id_table2, admission_date_2, something
(the tables are fictive)
I'm trying to make a view who takes infos from this 3 tables using left join, i'm doing like this because in the first table i have some record who don't have the person_code in the others tables but I want also this info to be returned by the view:
CREATE OR REPLACE VIEW schema.my_view
SELECT t1.name, t2.adress, t3.something
from schema.table1#ambient1 t1
left join schema.table2#ambient1 t2
on t1.person_code = t2.person_code_foreing
left join schema.table3#ambient1 t3
on t3.id_table2 = t2.id
and t1.admission_date_1=t2.admission_date_2;
This view needs to be created in another ambient (ambient2).
I tried using a subquery, there I need also a left join to use, and this thing is very confusing because I don't get it, the subquery and the left join are the big no-no?! Or just de left-join?!
Has this happened to anyone?
How did you risolved it?
Thanks a lot.
ORA-2019 indicates that your database link (#ambient1) does not exist, or is not visible to the current user. You can confirm by checking the ALL_DB_LINKS view, which should list all links to which the user has access:
select owner, db_link from all_db_links;
Also keep in mind that Oracle will perform the joins in the database making the call, not the remote database, so you will almost certainly have to pull the entire contents of all three tables over the network to be written into TEMP for the join and then thrown away, every time you run a query. You will also lose the benefit of any indexes on the data and most likely wind up with full table scans on the temp tables within your local database.
I don't know if this is an option for you, but from a performance perspective and given that it isn't joining with anything in the local database, it would make much more sense to create the view in the remote database and just query that through the database link. That way all of the joins are performed efficiently where the data lives, only the result set is pushed over the network, and your client database SQL becomes much simpler.
I managed to make it work, but apparently ambient2 doesn't like my "left-join", and i used only a subquery and the operator (+), this is how it worked:
CREATE OR REPLACE VIEW schema.my_view
SELECT t1.name, all.adress, all.something
from schema.table1#ambient1 t1,(select * from
schema.table3#ambient1 t3, schema.table2#ambient1 t2
where t3.id_table2 = t2.id(+)
and (t1.admission_date_1=t2.admission_date_2 or t1.admission_date is null))
all
where t1.person_code = t2.person_code_foreing(+);
I tried to test if a query in ambient2 using a right-join works (with 2 tables created there) and it does. I thought there is a problem with that ambient..
For me, there is no sense why in my case this kind of join retrieves that error.
The versions are different?! I don't know, and I don't find any official documentation about that.
Maybe some of you guys have any clue..
There is a mistery for me :))
Thanks.

Does TOAD for oracle generate logs of executed SQL?

I cannot seem to find a view which I created in one of my schemas within TOAD. Lets assume I don't know the exact schema in which I've created it, is there any way where I can find all the create statements which have been executed within a period of time, lets say the last days.
Thank you in advance.
If you created the view, just query ALL the views, and order by the date in which it was created.
select * from dba_objects
where object_type = 'VIEW'
order by created desc, last_ddl_time desc
We're hitting DBA_ views to make sure we look at EVERYTHING, not just the things you have PRIVS for. Switch to ALL_ views in case you lack access, and hope you didn't create the view in a schema in which your current logon can't see.
The other way to go is query the views themselves and key in on the table you think you included in the SQL behind the view.
SELECT *
FROM dba_views
WHERE UPPER (text_vc) LIKE '%EMPLOYEES%';
You might be looking for a feature called "SQL Recall" in Toad. Press F8 or View/SQL Recall. It will show you the SQL you ran in the last month or so.

How to recreate SAP queries in Oracle?

I need to recreate some SAP stored procedures in Oracle. I've been trying to find tutorials, similar questions, examples, etc about this but apparently no one had to do this before
What Oracle SQL query can be similar to this SAP query ?
SELECT * FROM A
INTO CORRESPONDING FIELDS OF TABLE B
FOR ALL ENTRIES IN C
WHERE a = C-a
AND x = y.
LOOP AT B INTO D.
D-b = E-b.
INSERT c FROM D.
IF SY-SUBRC <> 0.
WRITE: / 'error on insert', D-b, D-a.
ENDIF.
Any help will be appreciated, Thanks.
I recommend you to use transaction 'ST05' to trace your program. This tool will show details of the queries on the database including the exact SQL executed.
EDIT:
As a demonstration of the queries generated by SAP for Oracle let's execute this code and trace it with transaction 'ST05'. Remember to run 'ST05' before executing the program.
tables: mara.
data: it_mara type standard table of mara,
it_eina type standard table of eina.
select-options so_matnr for mara-matnr.
start-of-selection.
select matnr from mara into corresponding fields of table it_mara
up to 100 rows where matnr in so_matnr.
check sy-subrc eq 0.
select * from eina into table it_eina for all entries in it_mara
where matnr eq it_mara-matnr.
After execution check the output in transaction 'ST05':
If you want more details select an SQL statement in the screen and then click the button 'Explain'. You will see the following:
For better reference on transaction 'ST05' check this link.
Hope it helps.
The FOR ALL ENTRIES statement usually produces many queries which results are then grouped by UNION or UNION ALL.
Here is a really nice analysis for Microsoft SQL Server.
Because of the fact that UNION and UNION ALL are part of SQL standard I think it is implemented exactly the same for any other SQL database.
[EDIT]
As Mr Miranda stated it looks differently when it comes to Oracle database. I googled a bit and found this article where it is said that IN-LISTs are used which seems also to be plausible.

Resources