Searching a column name across a database in oracle9i? - oracle9i

Is there a way to search to which table or tables a column(say Cycle_name) belongs to in oracle?

Select *
from all_tab_cols
where column_name like '%%'
If you want also to spiecified a table add the following to WHERE clause
table_name like '%%'

Related

alias column names without mentioning column name

I'm trying to get all columns from each table with a prefix in the output, without mentioning all column names specifically in the select statement. Like:
SELECT *
FROM TABLE1 as T1
FULL JOIN TABLE2 as T2
ON T1.number=T2.number
Where I would want to get all column names from table1 and table2 prefixed with "T1" and "T2".
Many thanks in advance!
SELECT
CONCAT('T1', COLUMN_NAME), ORDINAL_POSITION
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME = 'TABLE1'
ORDER BY 2
UNION
SELECT CONCAT('T2', COLUMN_NAME), ORDINAL_POSITION
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME = 'TABLE2'
ORDER BY 2

MyBatis Dynamic SQL join on subquery

I want to do something like this in MyBatis Dynamic SQL:
SELECT id FROM foo
JOIN (SELECT foo_id ...) bar ON foo.id = bar.foo_id
WHERE ...
However, the join() function only accepts SqlTable as an argument.
Is it possible to join on a subquery with MyBatis Dynamic SQL? If so, how do I do it?
MyBatis Dynamic SQL doesn't support these types of sub-queries right now. I'll think about adding it.
What's your database?
Do you really need to explicitly use JOIN like this?
Can't you do it just ike this?
SELECT id FROM foo , (select foo_id...) bar
WHERE foo.id = bar.foo_id

Nested queries. Select as column

Is it possible to write this query in ROR?
SELECT column_1,
(SELECT name FROM table_2 WHERE table_2.column_1 = table_1.column_1) as name
FROM table_1;
Yes, it is possible:
Table_1.select("column_1, (SELECT name FROM table_2 WHERE table_2.column_1 = table_1.column_1) as name")
If you will user Arel it will seems yet more complicated then this.
But exists other ways to simplify this query:
split it to two query and merge it together in Rails
using joins method for join table_1 and table_2 and select field table_2.name.

Display the object names and types from the USER_OBJECTS data dictionary view EMPLOYEE and DEPARTMENT tables

I'm having trouble with the where clause...
SELECT OBJECT_NAME, OBJECT_TYPE
FROM USER_OBJECTS
WHERE TABLE_NAME IN ('EMPLOYEE', 'DEPARTMENT');
Figured it out -
SELECT constraint_name, constraint_type
FROM user_constraints
WHERE table_name IN ('EMPLOYEE', 'DEPARTMENT');

How to use SphinxSE table + sort by "weight desc" when there are other joins in query?

By default, when you perform query to sphinx table, Sphinx engine returns rows which are already sorted by query weight and does it really fast.
So, when I do this:
select
article.name
from article
left join article_ft on article._id=article_ft.id
where article_ft.query='some text;mode=any;';
Where:
article is InnoDB like table.
article_ft is Sphinx table.
Both of them (article.name and article_ft) contain these data (1 line = 1 row):
This is text.
This is also some text.
This is another text.
Sphinx engine will return rows like:
This is also some text.
This is text.
This is another text.
But, If I do something like this:
select
article.name
from article
left join article_ft on article._id=article_ft.id
left join article_category on article.category=article_category._id
where article_ft.query='some text;mode=any;';
It seems, MariaDB sorts it by its own way here.
Even If I provide Sphinx's 'sort' option like this:
select
article.name
from article
left join article_ft on article._id=article_ft.id
left join article_category on article.category=article_category._id
where article_ft.query='some text;mode=any;sort=extended:#weight desc;';
Still it doesn't work.
Changing order of joins doesn't work as well.
If I use order by article_ft.weight DESC MariaDB returns error message like:
Error: ER_ILLEGAL_HA: Storage engine SPHINX of the table `article_ft` doesn't have this option
in case if article has no rows that could match condition like article.category=50.
article_ft was created using this:
CREATE TABLE article_ft
(
id BIGINT NOT NULL,
weight INTEGER NOT NULL,
query VARCHAR(3072) NOT NULL,
INDEX(query)
) ENGINE=SPHINX CONNECTION="sphinx://192.168.1.98:9402/article_ft";
How to use this "magical" sort by weight feature if query contains more joins with no errors in return?
Thanks forward, for any reply!
P.S. Can't provide you a fiddle for this because I do not know any SQL fiddle online service which supports Sphinx Tables. Also if you found more relevant topic question I'll appreciate that.
Put the article_ft table first in the query. ie ... article_ft inner join article ...
Or maybe use FORCE INDEX, to force the use of the query index. Then it might honour the sort order.
Failing that use a subquery?
(select name,weight from article_ft ... ) order by weight desc;

Resources