System.Data.OleDb.OleDbException: 'SQL: Column ' ' is not found.' - visual-foxpro

When I run my VFP query I'm getting:
System.Data.OleDb.OleDbException: 'SQL: Column ' ' is not found.'
Sample SQL
SELECT a.Name
FROM [some-table] b

Fix the table alias: [some-table] a should be [some-table] b
Sample SQL
SELECT b.Name
FROM [some-table] b

Related

Select Statement Using Dual Table As A Sub Query In Oracle Generates "From keyword not found" Error

I get below error message while executing following queries using a select statement from dual table as a sub query:
Error: ORA-00923: FROM keyword not found where expected
Query 1:
select a.dt_1, a.dt_2, a.dt_1=a.dt_2 as "match_type" from
(select to_date(replace('2020-05-14 00:00:00',' 00:00:00',''), 'yyyy/mm/dd') as "dt_1", to_date('14/05/2020','dd/mm/yyyy') as "dt_2" from dual) a
Query 2:
select a.dt_1, a.dt_2, a.dt_1=a.dt_2 as match_type from
(select to_date(replace('2020-05-14 00:00:00',' 00:00:00',''), 'yyyy/mm/dd') as dt_1, to_date('14/05/2020','dd/mm/yyyy') as dt_2 from dual) a
When I individually run sub query it executes as expected, however when I run the whole statement it generates error.
Any help is appreciated.
Your match_type column is generating the error. Oracle doesn't support relational operator matching. You may try below query -
SELECT a.dt_1,
a.dt_2,
CASE WHEN a.dt_1=a.dt_2 THEN 'TRUE' ELSE 'FLASE' END AS "match_type"
FROM (SELECT TO_DATE(REPLACE('2020-05-14 00:00:00',' 00:00:00',''), 'yyyy/mm/dd') as "dt_1",
TO_DATE('14/05/2020','dd/mm/yyyy') as "dt_2"
FROM DUAL) a;

Encountered the symbol "INNER" when expecting one of

CURSOR CUR_OP_BAL IS
SELECT GLD.GOLDSMITH_ID, RTRIM(LTRIM(PTY.LC_PARTY_FIRST_NAME)) || ' ' ||
RTRIM(LTRIM(NVL(PTY.LC_PARTY_LAST_NAME,''))) AS GOLDSMITH_NAME,
PTY.LC_PARTY_SHORT_NAME
FROM PUR_GOLDSMITH_ML_T GLD
INNER JOIN COM_LOCAL_PARTY_MST_T PTY ON GLD.GOLDSMITH_ID = PTY.LC_PARTY_ID
ORDER BY GOLDSMITH_NAME;
in above code i am getting compile error :
Error(16,33): PLS-00103: Encountered the symbol "INNER" when expecting one of the following:
, ; for group having intersect minus order start union where connect
Please give me a proper solution
Not Sure about the issue but what i could see in the code is using of alias name "GOLDSMITH_NAME" in order by statement which is not possible, it can be possible only if you write one more select statement on top of it, some thing like :
select * from
(SELECT GLD.GOLDSMITH_ID, RTRIM(LTRIM(PTY.LC_PARTY_FIRST_NAME)) || ' ' ||
RTRIM(LTRIM(NVL(PTY.LC_PARTY_LAST_NAME,''))) AS GOLDSMITH_NAME,
PTY.LC_PARTY_SHORT_NAME
FROM PUR_GOLDSMITH_ML_T GLD
INNER JOIN COM_LOCAL_PARTY_MST_T PTY ON GLD.GOLDSMITH_ID = PTY.LC_PARTY_ID
)
ORDER BY GOLDSMITH_NAME;

Oracle function to select multiple rows in a single row not working

I am loading a file into a staging record using Application Engine. when ever there is blank in BU,Deptid etc... I have to capture what all columns are blank and update error text field with those values.
UPDATE SYSADM.PS_VI_EMP_TS SET ERR_TEXT =
SELECT ERROR FROM (SELECT * FROM (
SELECT CASE WHEN BUSINESS_UNIT = ' ' THEN 'BUSINESS_UNIT IS NULL' ELSE ' ' END AS ERROR FROM SYSADM.PS_VI_EMP_TS WHERE USERID='JCOOPER' AND ACTION = 'E' AND PROCESS_INSTANCE = '7852429'
UNION
SELECT CASE WHEN DEPTID = ' ' THEN 'DEPTID IS NULL' ELSE ' ' END AS ERROR FROM SYSADM.PS_VI_EMP_TS WHERE USERID='JCOOPER' AND ACTION = 'E' AND PROCESS_INSTANCE = '9852429'
UNION
SELECT CASE WHEN PROJECT_ID =' ' THEN 'PROJECT_ID IS NULL' ELSE ' ' END AS ERROR FROM SYSADM.PS_VI_EMP_TS WHERE USERID='JCOOPER' AND ACTION = 'E' AND PROCESS_INSTANCE = '9852429'
)) WHERE ERROR <> ' '
WHERE USERID='JCOOPER' AND ACTION = 'E' AND PROCESS_INSTANCE = '9852429'
The above script results as below.
ERROR
BUSINESS_UNIT IS NULL
DEPTID IS NULL
I want the result as below.
ERROR
BUSINESS_UNIT IS NULL,DEPTID IS NULL
I am using ListAgg function but facing errors as below.Any help would be great.
SELECT LISTAGG(BUSINESS_UNIT, ';') WITHIN GROUP(ORDER BY USERID)
FROM SYSADM.PS_VI_EMP_TS WHERE USERID='JCOOPER'
GROUP BY BUSINESS_UNIT
Facing the error:
ORA-00923: FROM keyword not found where expected
00923. 00000 - "FROM keyword not found where expected"
*Cause:
*Action:
Error at Line: 47 Column: 43
You overcomplicated things. You don't need two unions and listagg at all. Simple use concatenation of case... when, write your select like here:
select case business_unit when ' ' then 'BUSINESS_UNIT IS NULL; ' end ||
case deptid when ' ' then 'DEPTID IS NULL; ' end ||
case project_id when ' ' then 'PROJECT_ID IS NULL; ' end as error
from ps_vi_emp_ts
where userid = 'JCOOPER' and action = 'E' and process_instance = '9852429'
demo
If your table has primary key then use it for update. Otherwise you can use merge with rowid. Or do it the way you did it if it worked for you, especially if there is only one row meeting criteria.

Parent child relationship query in Oracle

I have table like this
Table- A
Conversion_logic Output_param
func(a,b) c
func(d) e
func(c) d
func(e) f
Here rows depicts that func(a,b) gives me "c", now this "c" is applied as func(c) and gives me "d", now this "d" is applied as func(d) and gives me "e" and now this "e" is applied as func(e) which gives me "f"
So I want an output like this
1) That row should be the first row whose output has no dependency.
2) From there it should follow parent child relation
Conversion_logic Output_param
func(e) f
func(d) e
func(c) d
func(a,b) c
You can use hierarchical queries.
SELECT table_name.*
FROM table_name
CONNECT BY PRIOR conversion_logic = 'func(' || output_param || ')'
START WITH conversion_logic = 'func(e)';
UPDATE:
SELECT table_name.*
FROM table_name
CONNECT BY PRIOR conversion_logic = 'func(' || ooutput_param || ')'
START WITH ooutput_param =
(SELECT a.ooutput_param
FROM table_name a
WHERE 'func(' || a.ooutput_param || ')' NOT IN (
SELECT b.conversion_logic
FROM table_name b));
Not sure about the performance of this query. Maybe there are better and efficient ones.
Try
SELECT t1.*
FROM taba t1
LEFT OUTER JOIN taba t2 ON instr(replace(t1.Conversion_logic, 'func'), t2.Output_param) > 0
START WITH t2.Conversion_logic IS NULL
CONNECT BY instr(replace(t1.Conversion_logic, 'func'), PRIOR t1.Output_param) > 0
ORDER BY LEVEL DESC
Here is a sqlfiddle demo

Return Oracle column names in table.column format?

Is there any setting or method I can use to get Oracle to return results in <table>.<column> format? For example:
Query:
SELECT *
FROM foo f
INNER JOIN bar b
ON b.foo_id = f.id
Desired results:
F.ID F.BLAH B.ID B.FOO_ID B.BLAH
--------------------------------------------------------
1 blah 7 1 blah
2 blah 8 2 blah
3 blah 9 2 blah
The obvious solution is to individually alias each column SELECT f.id AS F_ID, ...; however, I'm needing to export some very large legacy tables (300+ columns), so using this method would cause the queries to be enormous and impractical.
There is no "option" in Oracle to do this; you may be able to find a client that allows you to do so as this is a job that would normally be done in the client; I don't know of one.
To expand upon tbone's answer you're going to have to do this dynamically. This does not mean that you have to list every column. You would use the data dictionary, specifically all_tab_columns or user_tab_columns to create your query. It would be easier to create a view with the exact definition you want so that you can re-use it if you want.
The aim is to use the fact that the columns existence is stored in a table as a string in order to create a query to use that column. As the column names and table names are stored as strings you can use string aggregation techniques to easily create a query or DDL statement that you can then manually, or dynamically, execute.
If you're using Oracle 11g Release 2 the listagg function is available to help you:
select 'create or replace view my_view as
select '
|| listagg( table_name || '.' || column_name
|| ' as '
|| substr(table_name,1,1) || '_'
|| column_name, ', ')
within group
( order by case when table_name = 'FOO' then 0 else 1 end
, column_id
)
|| ' from foo f
join bar b
on f.id = b.foo_id'
from user_tab_columns
where table_name in ('FOO','BAR')
;
Assuming this table structure:
create table foo ( id number, a number, b number, c number);
create table bar ( foo_id number, a number, b number, c number);
This single query produces the following:
create or replace view my_view as
select FOO.ID as F_ID, FOO.A as F_A, FOO.B as F_B, FOO.C as F_C
, BAR.FOO_ID as B_FOO_ID, BAR.A as B_A, BAR.B as B_B, BAR.C as B_C
from foo f
join bar b on f.id = b.foo_id
and here's a SQL Fiddle to prove it.
In you're not using 11.2 you can achieve exactly the same results using the undocumented function wm_concat or the user-defined function stragg, which was created by Tom Kyte. Oracle Base has an article on string aggregation techniques and there are many posts on Stack Overflow.
As a little addendum you can actually create exactly what you're looking for with a small change to the above query. You can use a quoted identifier to create a column in the TABLE_NAME.COLUMN_NAME format. You have to quote it as . is not a valid character for an object name in Oracle. The benefit of this is that you gain exactly what you want. The downside is that querying the created view is a huge pain if you don't use select * from ...; selecting named columns will require them to be quoted.
select 'create or replace view my_view as
select '
|| listagg( table_name || '.' || column_name
|| ' as '
|| '"' || table_name || '.'
|| column_name || '"', ', ')
within group
( order by case when table_name = 'FOO' then 0 else 1 end
, column_id
)
|| ' from foo f
join bar b
on f.id = b.foo_id'
from user_tab_columns
where table_name in ('FOO','BAR')
;
This query returns:
create or replace view my_view as
select FOO.ID as "FOO.ID", FOO.A as "FOO.A", FOO.B as "FOO.B", FOO.C as "FOO.C"
, BAR.FOO_ID as "BAR.FOO_ID", BAR.A as "BAR.A"
, BAR.B as "BAR.B", BAR.C as "BAR.C"
from foo f
join bar b on f.id = b.foo_id
Using aliases wouldn't make the queries become impractical, its just not nearly as convenient as typing *. Use dynamic SQL to generate the columns for you:
select 'f.' || column_name || ' as F_' || column_name || ','
from all_tab_columns
where table_name = 'FOO'
order by column_id;
Do the same for any other wide tables you need, and copy/paste into your query. Also note the 30 char limit, hopefully none of your columns are over 28 in size.

Resources