I am not familiar with Oracle syntax, but I am getting a missing right parenthesis error when I am passing this string to an .Net Oracle Command and then it tries to fill the data adapter.
string cT = "SELECT 'PRODUCT' AS ItemType, 'x' || CAST(LPROD.QUANTITY AS VARCHAR2(50)), " +
"PNAME.NAME || ' (' || CAST((PRODS.\"SIZE\" AS VARCHAR2(50))) || ' ' || PRODS.MEASURE || ')' AS Name, " +
"PRODS.PRODUCT_ID as ProductSizeID, PRODS.UPC_CODE as BarCode FROM ORDERS ORDR, LI_PROD LPROD, PRODUCT_NAME PNAME, " +
"PRODUCT PRODS WHERE ORDR.INV_NUM = :Invoice_Num AND ORDR.ORDER_NUM = LPROD.ORDER_NUM " +
"AND LPROD.PRODUCT_ID = PRODS.PRODUCT_ID AND PRODS.PRODUCT_NAME_ID = PNAME.ID";
Can anyone spot the error that may be causing this? Thanks for your help.
Try:
cast(prods."SIZE" as varchar2(50))
Instead of:
cast((prods."SIZE" as varchar2(50)))
I recently came up with the exact same issue and could not find a solution. What ended up happening was that I had the following code from SQLServer that I was attempting to convert to Oracle.
CAST(col AS NVARCHAR(250)) AS col_name,
I was able to fix it by changing it to
CAST(col AS NVARCHAR2(250)) AS col_name,
Related
I have a table in which there is a column name associated_ids with datatype as varchar2(4000). It contains a value and i need to append the new value with existing value. Using below update query:
update ncl_getafix.service_graph
set Associated_ids = Associated_ids + ',' + '95d4980b-d12c-4854-97c6-bd9854f8f003'
where SERVICE_ID='075d7a58-7fad-4e1d-9822-83a2fa1a0d05';
I am getting below error:
Error starting at line : 5 in command - update
ncl_getafix.service_graph set
Associated_ids=Associated_ids+','+'95d4980b-d12c-4854-97c6-bd9854f8f003'
where SERVICE_ID='075d7a58-7fad-4e1d-9822-83a2fa1a0d05'
Error report - ORA-01722: invalid number.
Can anyone help to debug this.
You need to use concat operator || not + as follows:
update ncl_getafix.service_graph
set Associated_ids = Associated_ids || ',' || '95d4980b-d12c-4854-97c6-bd9854f8f003'
where SERVICE_ID='075d7a58-7fad-4e1d-9822-83a2fa1a0d05';
i found the answer.
Use || symbol instead of + in query
I have gone over the SQL for an hour and can't find why the error is being raised. I have checked all the basic reasons this error can occur and found nothing. I'm suspicious of the CASE statement but it appears to be correct. Can anyone spot the problem or point me in a direction? Thanks
INSERT INTO RPT_HOUSEHLDBATCH
(CUSTOMERKEY,HOUSEHOLDNBR,CUSTOMERTYPE,LASTNAME,FIRSTNAME,ADDRNBR,AddressLine1,AddressLine2,AddressLine3,
CITYNAME, STATECD, ZIPCD, SCORE, DATECREATED, RUNDATE, TYPECD, PREVIOUSHHLDNBR)
SELECT CustomerKey,' || in_HHNbr || ',
CASE SUBSTR(CUSTOMERKEY,1,1)
WHEN ''P'' THEN ''I''
WHEN ''O'' THEN ''B''
END CASE,
a.LastName,
a.FirstName,
AddrNbr,
AddressLine1,
AddressLine2,
AddressLine3,
Cityname,
StateCd,
ZipCd,
2, b.AddDate, SYSDATE, ''' || in_NewUpd || ''', HouseHoldNbr
FROM rpt_HouseHldBatchwrk a
JOIN PERS b
ON SUBSTR(a.CUSTOMERKEY,2) = b.PersNbr
WHERE CUSTOMERKEY = ''P' || in_PersNbr || '''
UNION
SELECT CustomerKey,' || in_HHNbr || ',
CASE SUBSTR(CUSTOMERKEY,1,1)
WHEN ''P'' THEN ''I''
WHEN ''O'' THEN ''B''
END CASE,
a.LastName,
a.FirstName,
AddrNbr,
AddressLine1,
AddressLine2,
AddressLine3,
Cityname,
StateCd,
ZipCd,
2, b.AddDate, SYSDATE, ''' || in_NewUpd || ''', HouseHoldNbr
FROM rpt_HouseHldBatchwrk a
JOIN ORG b
ON SUBSTR(a.CUSTOMERKEY,2) = b.OrgNbr
WHERE CUSTOMERKEY = ''O' || in_OrgNbr || '''
A good strategy to debug such a statement is to pare it down, as #OldProgrammer suggested.
In your case, I'd try to ignore the INSERT and get the SELECT running first.
As it's a UNION of two SELECTs, I'd split them into separate statements, too.
The in_NewUpd and in_PersNbr look strange, just like parameters in a procedure. I'd replace them with fixed known values, like WHERE CUSTOMERKEY LIKE ''P1234''
And please, please don't store SQL in a variable and execute it based on a condition. The syntax for that is to use placeholder like ? in the SQL instead of string concatenation ||. You'll flood the cursor cache if you do it wrong.
Turns out the in_HHNbr in some cases was coming in as a null. Concatenating null throws missing expression.
As far as how the code is structured I inherited this code and can't make major changes. I was sent to bug fix.
I have the below select statement in hive .It executes perfectely fine.
In Hive
select
COALESCE(product_name,CONCAT(CONCAT(CONCAT(TRIM(product_id),' -
'),trim(plan_code)),' - UNKNOWN')) as product_name
from table name;
I am trying to use the same select statement in POSTGRESQL and it throw me error saying "
Query execution failed
Reason:
SQL Error [42883]: ERROR: function concat(text, unknown) does not exist
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
In postgresql:
select
COALESCE(product_name,CONCAT(CONCAT(CONCAT(TRIM(product_id),' -
'),trim(plan_code)),' - UNKNOWN')) as product_name
from table name;
Could some one throw some light on this ?
Instead of concat try with ||:
SELECT COALESCE(product_name,
(TRIM(product_id) || ' - ' || TRIM(plan_code) || ' - UNKNOWN')
) AS product_name
FROM tablename;
or simply a single CONCAT as:
SELECT COALESCE(product_name,
CONCAT(TRIM(product_id)::text, ' - ', TRIM(plan_code)::text, ' - UNKNOWN')
) AS product_name
FROM tablename;
You can also consider using format function:
SELECT coalesce(product_name, format('%s - %s - UNKNOWN', trim(product_id), trim(plan_code)))
Im having trouble with my sql :
sSQL:= 'select * from tbldebit where transaction date like " '+ tdate+ ' " ' ;
Delphi 2010 keeps giving me missing operator error.
(TDate captures value from date time picker)
Look foward to your response
Regards
I have always used:
function DateTimeToSQLDate(const ADate: TDateTime): string;
var
MyYear, MyMonth, MyDay, MyHour, MyMinute, MySecond, MyMSecond: Word;
begin
DecodeDateTime(ADate, MyYear, MyMonth, MyDay, MyHour, MyMinute, MySecond, MyMSecond);
Result := Format('#%d %s %d#', [MyDay, FormatSettings.LongMonthNames[MyMonth], MyYear]);
end;
You would use this...
sSQL:= 'select * from tbldebit where [transaction date] = ' + DateTimeToSQLDate(TDate);
Correct code =
sSQL: ='Select * from tbldebit where [Transaction date] like " '+ datepicked+ ' " ' ;
The field name had to be in square brackets since their is a space in the name. I tested it and 'like' works.
Regards
Use wildcards like below:
query = "SELECT * FROM tbldebit WHERE date LIKE '%" + tdate+ "%'";
Query below returns error
SELECT 'mailto:'|| fscp.parameter_value || '?subject=' || wfn.subject nid_subject || chr(38)
FROM apps.wf_notifications wfn, apps.fnd_svc_comp_param_vals_v fscp
WHERE fscp.component_id = :component_id
AND component_parameter_id = :param
AND wfn.item_key = :itemkey;
Error
ORA-00923: FROM keyword not found where expected
00923.00000 - "FROM keyword not found where expected"
When I remove the '|| chr(38)' at the end of the select statement, the query runs fine.
Something related to joining tables? Because the below query also works fine:
select 'Text: '||chr(39)||wfn.notification_id||chr(39) from wf_notifications wfn;
You have this in the select:
|| wfn.subject nid_subject ||
Perhaps you intend:
SELECT 'mailto:'|| fscp.parameter_value || '?subject=' || wfn.subject || nid_subject || chr(38)
----------------------------------------------------------------------^
Alex is right. The key in the question is that it works without chr(38). So, try this:
SELECT ('mailto:'|| fscp.parameter_value || '?subject=' || wfn.subject || chr(38) ) as nid_subject
Notice the use of parentheses and as to make it clear that a column alias is being defined.