Insert into emp values
(:FNAME ,.......
Above Sample Code from TPT works fine.
I want to convert null values in flatfile to blank while loading
insert into emp values ( COALESCE(:Fname,' '),.... -- Throws ERROR
TPT_INFRA: TPT04046: Error: Line 193 of Job Script File 'tpscript4.txt': Adjacen
t quoted strings must be separated by the
concatenation operator: '||'.
Job script preprocessing failed.
insert into emp Values ( case when :Fname is null then ' ' else :Fname End,... --Throws Error
Teradata Parallel Transporter Version 13.10.00.02
TPT_INFRA: TPT04046: Error: Line 191 of Job Script File 'tpscript4.txt': Adjacen
t quoted strings must be separated by the
concatenation operator: '||'.
Job script preprocessing failed.
Job terminated with status 8.
When used Case when in Select oerator for fastload:
TO OPERATOR (UPDATE_OPERATOR[2])
SELECT case when FNAME is null then ' ' else FNAME,LNAME,....
FROM OPERATOR (FILE_READER[2]);
ERROR:
TPT_INFRA: Syntax error at or near line 249 of Job Script File 'tpscript4.txt':
TPT_INFRA: At "SELECT" missing SEMICOL_ in Rule: Job Definition Body
Compilation failed due to errors. Execution Plan was not generated.
Job script compilation failed.
Job terminated with status 8.
Note: with out the case in select it is working fine ,
APPLY('insert into emp values ( COALESCE(:Fname,'' ''),....') Worked with Mload
and
SELECT CASE WHEN Fname IS NULL THEN ' ' ELSE Fname END AS Fname,... FROM OPERATOR worked with Fload
You didn't specify which error is returned, i assume it's related to the single quotes. Your INSERT is probably within an APPLY('INSERT ....;') you might try two single quotes to get one quote in a string:
APPLY('insert into emp values ( COALESCE(:Fname,'' ''),....')
Or do it in the SELECT (COALESCE is not supported here):
SELECT
CASE WHEN Fname IS NULL THEN ' ' ELSE Fname END AS Fname,
...
FROM OPERATOR
Related
What I want to do is check in my database if my table exists, if yes drop it. Here is my .tpt :
DEFINE JOB DELETE_ET_TABLES
DESCRIPTION 'Delete ET tables'
(
DEFINE OPERATOR DDL_OPERATOR
DESCRIPTION 'Teradata Parallel Transporter DDL Operator'
TYPE DDL
ATTRIBUTES
(
varchar TdpId = #TERADATA_TDP,
varchar UserName = #User,
varchar UserPassword = #Pwd
);
APPLY
'SELECT (CASE WHEN TableName = ''Test_Del''
THEN (''DROP TABLE #Table;'')
ELSE NULL
END)
FROM dbc.TablesV WHERE databasename = #Db;' TO OPERATOR(DDL_OPERATOR);
And this is the error message I am getting :
Running "tbuild" command: tbuild -f /$HOME/loaders/test_deleteETTables.tpt -u TERADATA_TDP=$TDP, TERADATA_DATABASE=$DB -L /$LOG/
Teradata Parallel Transporter Version 16.20.00.09 64-Bit
TPT_INFRA: Syntax error at or near line 18 of Job Script File '/$HOME/loaders/test_deleteETTables.tpt':
TPT_INFRA: At "(" missing { EXTENDED_LITERAL_ CHAR_STRING_LITERAL_ } in Rule: Character String Literal
Compilation failed due to errors. Execution Plan was not generated.
Do you have any idea ? I have tried multiple things, such as :
SELECT 1 FROM dbc.TablesV WHERE databasename = #Db AND TABLENAME ='TEST_DEL';
CASE WHEN ACTIVITYCOUNT = 1
THEN (DROP TABLE #Table)
ELSE ( QUIT )
END;
All my variables have been declared. I feel that it is a problem with using single quotes inside que statement but I am not sure and I don't know how to resolve it. Thank you very much for your time.
The solution that Fred recommended me to try in the comments worked just fine :
I think this is due to use of NULL but SELECT is not valid for DDL operator. The recommended way to do this is simply pass a DROP to the operator and tell it to ignore "not found" (and consider that success), i.e. ErrorList='3807'
DESCRIPTION 'Delete ET tables'
(
DEFINE OPERATOR DDL_OPERATOR
DESCRIPTION 'Teradata Parallel Transporter DDL Operator'
TYPE DDL
ATTRIBUTES
(
varchar TdpId = #TERADATA_TDP,
varchar UserName = #USERDB,
varchar UserPassword = #PWD,
VARCHAR ErrorList = '3807'
);
APPLY
('DROP TABLE #TABLENAME')
TO OPERATOR(DDL_OPERATOR);
);```
I wrote the following program:
create or replace procedure ADDPHONE(IDPELATH in number,IDTHLEFWNO in number )
is
cursor cursor_number is select id_pelath ,TelephoneNumber from PhoneNumbers
where id_pelath>2;
more_than_two_numbers exception;
begin
open cursor_number ;
fetch cursor_number into IDPELATH;
if id_pelath%FOUND then raise more_than_two_numbers
end if;
close cursor_number;
exception
when more_than_two_numbers then
raise_application_error('Error');
END;
/
When I run it, I get the following error:
PLS-00103: Encountered the symbol "END" when expecting one of the following: . ;
The symbol ";" was substituted for "END" to continue.
Could you help me to find the error?
There are multiple issues in the procedure.
Input Parameters are never used in the body.
Cursor is declared to fetch two but FETCH statement is only fetching one.
Incorrect usage of raise_application_error,it requires two input arguments.
I have modified the code that should do the job,
CREATE or REPLACE procedure ADDPHONE(IDPELATH in number,IDTHLEFWNO in number)
is
lv_cnt number(10):=0;
more_than_two_numbers exception;
BEGIN
select COUNT(1) INTO lv_cnt
from PhoneNumbers
where id_pelath = IDPELATH
and TelephoneNumber = IDTHLEFWNO;
if (lv_cnt > 2) then
raise_application_error(-20001,'Error - More than two Numbers ');
end if;
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20002,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
END ADDPHONE;
/
I am trying to run merge statement in following manner in PLSQL block and getting ORA-00904 error described below:
--Merge statement
l_mergestr1:='merge into pi_customer picu using (select * from table(picu_var)) src ' ||
' on (picu.customer_id = src.customer_id) when matched then update set '||l_newmergeupstr1||
' where picu.time_stamp <> pctemp.time_stamp when not matched then' ||
' insert ('||l_newmergeinsstr1||') values ('||l_newmergeinstvalstr1||')';
execute immediate l_mergestr1;
ORA-00904: "PICU_VAR": invalid identifier
Here picu_var is a variable of object_type which I have already declared.
Using dbms_output I verified the merge statement converts to following which I think is a correct syntax for merge and it works :
merge into pi_customer picu using (select * from table(picu_var)) src
on (picu.customer_id = src.customer_id) when matched then update set picu.Customer_Name=src.Customer_Name,picu.Server_Name=src.Server_Name,picu.Time_stamp=src.Time_stamp
where picu.time_stamp <> src.time_stamp when not matched then
insert (picu.Customer_ID,picu.Customer_Name,picu.Server_Name,picu.Time_stamp) values (src.Customer_ID,src.Customer_Name,src.Server_Name,src.Time_stamp)
I also verified there is no mismatch across source and target table column names and the merge syntax works when executed as what returned from dbms_output.
Please suggest how to avoid the error ORA-00904.
Does the syntax for merge declared in "l_mergestr1" requires a change?
You can't reference a variable from outside the dynamic SQL inside the dynamic SQL. Use a bind variable to pass it in:
l_mergestr1:='merge into pi_customer picu using (select * from table(:picu_bv)) src ' ||
' on (picu.customer_id = src.customer_id) when matched then update set '||l_newmergeupstr1||
' where picu.time_stamp <> pctemp.time_stamp when not matched then' ||
' insert ('||l_newmergeinsstr1||') values ('||l_newmergeinstvalstr1||')';
execute immediate l_mergestr1 using picu_var;
I wrote a procedure using UTL_FILE:
CREATE OR REPLACE PROCEDURE UTL_CREATE_FILE
(
output_file in UTL_FILE.file_type,
log_file in UTL_FILE.file_type,
filename in VARCHAR2 (64),
ddate in VARCHAR2 (19),
sep in NVARCHAR2 (3)
)
IS
BEGIN
sep := Chr(9);
ddate := TO_CHAR (SYSDATE, 'YYYYMMDD');
filename := 'EXT' || ddate || '.dat';
output_file := UTL_FILE.fopen ('C:/home/S/', filename, 'w', 32000);
log_file := UTL_FILE.fopen ('C:/home/S/', 'WEEKLY.log', 'a', 32000);
UTL_FILE.put_line (log_file, TO_CHAR (SYSDATE, 'DD-MM-YYYY HH24:MI:SS') || 'Started with file ' || filename);
select 'HUGE SQL STATEMENT'|| sep || 'Anykey' as OUTLINE from DUAL;
UTL_FILE.put_line (output_file, OUTLINE);
UTL_FILE.fclose (output_file);
UTL_FILE.put_line (log_file, TO_CHAR (SYSDATE, 'DD-MM-YYYY HH24:MI:SS') || 'Finished for file ' || filename);
UTL_FILE.fclose (log_file);
END;
But Toad returns Warning: compiled but with compilation errors.
Could anybody help me?
As a result I would like to receive a EXT.DAT (and logs) in C:/home/S/ directory. Thank you in advance.
TOAD should give you the compilation errors - they are probably on a separate tab (it's been a while since I used that particular IDE).
However, it easy to spot one bloomer: we cannot assign values to parameters defined in IN mode. The purpose of such parameters is that the calling program assigns their values.
However, in this case I think you need to assign ddate and filename, so you should move them out of the procedure's signature and into its declaration section.
sep I would keep as a parameter but give it a default value.
Bear in mind that SQL limits us to 4000 characters in a column . So if 'HUGE SQL STATEMENT' exceeds 3993 characters your code will hurl a runtime error.
If you're making these sorts of errors you're probably not up-to-speed with the intricacies of writing files from PL/SQL. I suggest you read this previous answer of mine and also this one regarding this topic.
You should be able to append this to the end of your script to get the errors (I don't use TOAD, but I'd expect it to support it). It goes after the last end;.
/
show errors;
The compilation errors that stand out to me -
The parameters are being assigned to. This is illegal as "in" parameters. They don't seem to be used for input, so they should probably be removed from the signature. If this is a code snippet and they do provi
I'm trying to get this dynamic SQL running ( using EXECUTE IMMEDIATE)
M_SQL_STATEMENT := 'SELECT MAX(:m_var1)+1 from :m_var2 RETURNING MAX(:m_var1)+1 INTO :m_var3';
EXECUTE IMMEDIATE M_SQL_STATEMENT
USING M_COLUMN_NAME, UPPER(P_TABLE_NAME), M_COLUMN_NAME
RETURNING INTO M_SEQ_NUMBER;
However, when trying to run this, I keep running into
ORA-00903: Invalid table
P_TABLE_NAME is a table name which is accepted as an input. I have confirmed that the table name & the column name are valid. I can't figure out why Oracle is throwing the error.
FWIW Altering the SQL statement to
M_SQL_STATEMENT := 'SELECT MAX(:m_var1)+1 SEQ from :m_var2 RETURNING SEQ INTO :m_var3';
still results in the same error.
You need to put the table name and column name into the dynamic SQL, so something like
M_SQL_STATEMENT := 'SELECT MAX(' || M_COLUMN_NAME || ')+1 from '
|| P_TABLE_NAME';
EXECUTE IMMEDIATE M_SQL_STATEMENT INTO M_SEQ_NUMBER;