Delphi Rio - I have dbGO/ADO configured with Oracle (using Oracle's connector, not Microsoft's). I am working with a simple query.
mySQL := 'select REGISTRY_ID, TERRITORY_ID, ACCOUNT_NAME from ACCOUNTS_SI';
ADO_Q1.Close;
ADO_Q1.SQL.Clear;
ADO_Q1.SQL.Add(mySQL);
ADO_Q1.Open;
ShowMessage(IntToStr(ADO_Q1.FieldList.Count));
This works exactly as expected, and the Message popup shows 3. If I add the ROWID as a column, it appears to be totally ignored. The query below runs, but still shows 3 columns.
mySQL := 'select ROWID, REGISTRY_ID, TERRITORY_ID, ACCOUNT_NAME from ACCOUNTS_SI';
I have even tried renaming it.
mySQL := 'select ROWID as MYKEY_ID, REGISTRY_ID, TERRITORY_ID, ACCOUNT_NAME from ACCOUNTS_SI';
ROWID as a column, while completely legal, is being filtered out.
When I look at Oracle's documentation, it seems to show that RowID is perfectly valid.
In order for the OleDbDataAdapter.Update() method to properly update
Oracle with changes made in the DataTable, the DataTable must contain
a primary key of a database table. If the database table does not
contain a primary key, the ROWID must be selected explicitly when
populating the DataTable, so that the ROWID can be used to uniquely
identify a row when updating a row in the database.
Is there a way around this? How can I use RowID with dbGo? (Yes, I am ware of issues using RowID...but this is a single user, local DB.)
Looks like it uses ROWID for internal purposes like cursor navigating, so try to add 2 ROWID columns and wrap one in the nested subquery:
mySQL := 'select RID, REGISTRY_ID, TERRITORY_ID, ACCOUNT_NAME from (select ROWID, ROWID as RID, s.* from ACCOUNTS_SI s';
Update (since previous one didn't help)
Another variant:
mySQL := 'select RowIDtoChar(ROWID) RID, REGISTRY_ID, TERRITORY_ID, ACCOUNT_NAME from ACCOUNTS_SI';
Related
I'm facing an issue in hive while creating view from a partitioned table. If I use the command below:
create view test_view as select * from table where and year=2000 and month=01 and day=02;
The view gets created but the below selection results in 0 records:
select count(*) from test_view where day='02';
Whereas, the below selection will work just what it's meant to do:
select count(*) from test_view where day='2';
The following command also gives the count(*) result properly:
select count(*) from test_view where day=2;
The important thing here is that day=02 is a physical partition in the actual table, which is fine to the understanding. It's somehow the view creation is interpreting the input integers.
Anyone got any ideas on this?
I'm trying to generate unique id's for a table that was originally done in DB2 using the following:
insert into database.table
select next value for database.sequence,
current_timestamp,
from source
Where the sequence has a defined start value (e.g 25430).
The code I'm currently using is:
insert into database.table
select
row_number() over() + select max(id) from table,
from_unixtime(unix_timestamp())
from source;
Which is fine apart from the nested select statement not working, at the moment I have to run
select max(id) from table
and put it into the query manually.
Can anyone suggest a way to do this in the one query?
You have to force a crossjoin, something like this:
select
...
from source,
(select max(id)as maxid from table) as m_id
;
This way you get one value for your max id back, and you can use that to generate your new one.
Generating surrogate keys with hive is kind of painful, sadly enough.
I'm doing some cleaning up in a bunch of old solutions. As part of the cleanup, I'm looking at removing some old triggers from an Oracle database. The triggers were originally designed by colleagues of mine, and put in place by a third party consultant. I don't have any direct access to the Oracle database except through a server link from a Sql Server where I do have access.
So I'm listing the triggers like this:
select * from openquery(SERVERLINKNAME, '
select *
from ALL_TRIGGERS
where owner like ''%OURUSERNAME%''
order by trigger_name
')
This works ok, but the problem is that the TRIGGER_BODY field from ALL_TRIGGERS is of type LONG, and the data in the field gets cut off at some point between the Oracle server and my SSMS resultset. So I can only see the first 100 chars from this column.
How can select the whole TRIGGER_BODY field?
Searching through Google for oracle convert long to varchar gives quite a few results, many of which suggests using functions, (temporary) tables etc. All of these are out of the question in my specific case since I'm not allowed to create any objects in the Oracle database/server.
I did finally find a sample that I was able to modify for my use case. The sample is from this page, by someone calling himself Sayan Malakshinov. After modifying his sample, I ended up with this:
select * from openquery(SERVERLINKNAME, '
select *
from
xmltable( ''/ROWSET/ROW'' passing dbms_xmlgen.getXMLType(''
select
trigger_name,
TRIGGER_BODY
from ALL_TRIGGERS
where TRIGGER_BODY is not null
and owner = ''''OURUSERNAME''''
'')
columns
trigger_name varchar2(80),
TRIGGER_BODY varchar2(4000)
)
')
This omits some columns from ALL_TRIGGERS but I get the whole trigger body (since none of the triggers are longer than 4000 chars).
In case you like to have it a little easier to read an execute parts of it, I transformed the version from user1429080 using literal escape syntax using § and [/] for escaping the nested strings:
select * from openquery(SERVERLINKNAME, q'§
select *
from
xmltable( '/ROWSET/ROW' passing dbms_xmlgen.getXMLType(q'[
select
trigger_name,
TRIGGER_BODY
from ALL_TRIGGERS
where TRIGGER_BODY is not null
and owner = 'OURUSERNAME'
]')
columns
trigger_name varchar2(80),
TRIGGER_BODY varchar2(4000)
)
§')
And just in case you want to inspect the code in sql result views (that often support displaying only single CHR(13) as visual line feeds) this is very useful:
select translate( trigger_body, CHR(10)||CHR(13), CHR(13)||CHR(13) ) as body
from xmltable(
'/ROWSET/ROW' passing dbms_xmlgen.getXMLType(
q'[
select TRIGGER_BODY from ALL_TRIGGERS
where TRIGGER_NAME='<MY_TRIG_NAME>' -- or any other condition
]')
columns TRIGGER_BODY varchar2(4000))
Can someone tell me how I can get the number of rows in each table in my oracle database? I have found several queries, but none of them worked because I am using oracle 7 and sqlplus 3.2 and basically all what I found didn't work on it. I just need something that would work on sqlplus 3.2.
Required:
Table Name Rows
Table 1 0
Table 2 5
...
Is it possible to do it with something like a loop? Or what exactly should I do?
if SELECT table_name, num_rows from all_tables doesn't give you what you need.
You could use dynamic SQL and counts as Rahul selected.
Run the below to get results which dynamically build a union on all tables, then run the results as it's own query to get final results.
SELECT 'SELECT ' ||t.name || ' as tName, count(*) as Row_Cnt
FROM ' || t.name || ' UNION ALL '
FROM ALL_TABLES t
Just be sure to remove the last union statement on the last query.
Also note: if you don't have access to see the table, it will not come out in this list!
---Updated ------
So if all_tables doesn't exist none of this will work. Since I don't have a oracle 7 instance handy... could you see if SELECT * FROM dictionary returns anything that might produce a list of all the tables? If you find a view or table object use it in place of all_tables above.
I'm reading the docs for oracle 7 now but finding little easily searchable. thus a guess and check method may go faster.
SELECT object_id from dbname.tablename
This query has to be executed against oracle 11g.I get errors when i execute this.
I do a migration from sybase to oracle and in oracle this query fails.
What could be the problem. Please suggest a solution
"What could be the problem."
All sorts of things. Since you failed to state what errors you're getting, we can only guess, e.g.:
Table not found
No SELECT privilege on table
dbname not a valid schema
object_id not a column in the table
Not connected to a running oracle instance
Trying to run the statement in an environment that doesn't understand SQL
etc, etc, ...
If all you want is to check that the table exists, you could do this:
SELECT 1 FROM dba_tables WHERE owner = 'DBNAME' AND table_name = 'TABLENAME';
If you want to check that you can query the table, you could do this:
SELECT 1 FROM schemaname.tablename WHERE 1=0;
If you want to check if the table has any rows, you could do this:
SELECT 1 FROM schemaname.tablename WHERE ROWNUM <= 1;
What you will do with the result. If you only want a unique id for a row, yo can user SELECT ROWID FROM dbname.tablename!