Appending parameter to the table name removes the dot operator - oracle

I have given a parameter to my sql script which i use to create new tables.
CREATE TABLE TMP_TABLE1&1.
Now when i'm trying to perform an operation on the table using the parameter the dot operator is not showing.
I'm running a script form which i'm calling the sql script. I'm using a unix server.
this is the operation I'm trying to perform
select * from TMP_TABLE1&1 where TMP_TABLE1&1.LISTING_STATUS='N'
but after running the script with parameter as test1 it removes the '.' from the query and when I check the error log the log shows the query as
select * from TMP_TABLE1&1 where TMP_TABLE1test1LISTING_STATUS='N'
why is the dot operator going away? Is there a way around this approach?

Use double dot (..). Otherwise it is like concatenation operator in this context.
TMP_TABLE1&1..LISTING_STATUS='N'
Default CONCAT operator in sqlplus is .

Related

How to resolve Information - Not a valid month error?

When running a PowerCenter session that uses an Oracle database view as a source the session fails with one of the following errors:
ORA-01843: Not a valid month.
In SqL developer it runs without any issues
Column : Report_date : Data Type : date.
In mapping parameter variable defined as String
Passing report date dynamically using param file &Control table
Select * from ABC
Where report_date=to_char(31-MAR-21,'DD-MON-RR')
--Error: not valid month
Could you please advise on it
You need to put single quotes around infa mapping parameter. Like this -
First calculate Report_Date and put the value in infa param file in correct format. You can use control table too. But you need to create a param file from that.
param file should look like
[folder.workflow.session]
$$Report_Date='21-Oct-2021'
Then in mapping you can call it in source qualifier as -
Select * from ABC Where report_date=to_char('$$Report_Date','DD-MON-RR')
single quote will ensure your data is passed as string.
Now, if youdont want to use param file, you can use control file as a new source and join with the SQL above to get desired result. But first approach is faster.

how to specifically define table name in Oracle SQL

i have a DB which has a table named LIKE.
uppon trying to execute any query on the table, it gives me an error and i know it's because of the name which is trying to use the query keyword LIKE.
Now, i have "bypassed" this issue in MySQL by just selecting the table as
SELECT tk_oseba_id, COUNT(tk_tip_like_id) AS St_Like_haha
FROM student999.`like`;
Now this same line wont work at `l...is there any special way to to this in oracle or how can i manipulate with the table by not using the LIKE keyword.
Oracles's counter part to mysql's back tick is quote for defining tablenames/columns.
To use a key word as a table name though I recommend against it...
wrap the table name in quotes. From student9999."like"
AND... it forces case sensitivity when you use the quotes!

How to call ora_hash function inside control file in sql loader?

I'm trying to call a function(ORA_HASH) inside sqlldr but I'm not able to achive the target.
Data File
abc.txt
AKY,90035,"G","DP",20150121,"",0,,,,,,"","E8BD4346-A174-468B-ABC2-1586B81A8267",1,17934,5099627512855,"TEST of CLOROM","",14.00,"",14.00,17934,5099627512855,"TEST of CLOROM",14.00,"ONE TO BE T ONE",344,0,"98027f93-4f1a-44b2-b609-7ffbb041a375",,,AKY8035,"Taken Test","L-20 Shiv Lok"
AKY,8035,"D","DP",20150121,"",0,,,,,,"","E8BD4346-A174-468B-ABC2-1586B81A8267",2,17162,5099627885843,"CEN TESt","",15.00,"",250.00,17162,5099627885843,"CEN TESt",15.00,"ONE TDAILY",3659,0,"09615cc8-77c9-4781-b51f-d44ec85bbe54",,,LLY8035,"Taken Test","L-20 Shiv Lok"
Control file
cnt_file.ctl
load data
into table Table_XYZ
fields terminated by "," optionally enclosed by '"'
F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12,F13,F14,F15,F16,F17,F18,F19,F20,F21,F22,F23,F24,F25,F26,F27,F28,F29,F30,F31 ORA_HASH(CONCAT(F2,F5,F6,F9,F10,F12,F13,F14,F15,F16,F17,F19,F21,F22)),F32 ORA_HASH(CONCAT(f23,H24,F7,F8,F3)),F33,F34,F35
sqlldr "xxxxx/yyyyy" control=cnt_file.ctl data=abc.txt
whenever I'm executing sqlldr from Linux box I'm getting below error
SQL*Loader-350: Syntax error at line 4.
Expecting "," or ")", found "ORA_HASH".
F29,F30,F31,KEY_CLMNS_HASH ORA_HASH(CONCAT( F2,F5
^
Any idea
You might consider using a virtual column on the table to which you are loading the data.
For columns which are deterministically based on other column values in the same row, that usually ends up being a more simple solution than anything involving SQL*Loader.
You're doing a few things wrong. The immediate error is because the Oracle function call has to be enclosed in double quotes:
...,F31 "ORA_HASH(CONCAT(F2,F5,F6,...))",...
The second issue is that the concat function only takes two arguments, so you would either have to nest (lots of) concat calls, or more readably use the concatenation operator instead:
...,F31 "ORA_HASH(F2||F5||F6||...)",...
And finally you need to prefix the field names inside your function call with a colon:
...,F31 "ORA_HASH(:F2||:F5||:F6||...)",...
This is explained in the documentation:
The following requirements and restrictions apply when you are using SQL strings:
...
The SQL string must be enclosed in double quotation marks.
And
To refer to fields in the record, precede the field name with a colon (:). Field values from the current record are substituted. A field name preceded by a colon (:) in a SQL string is also referred to as a bind variable. Note that bind variables enclosed in single quotation marks are treated as text literals, not as bind variables.

Named Parameter with AND/OR in CONTAINS query is not working

I am using Oracle Text for searching in my web application. I have configured Oracle Text by creating Data Store and Index.
This is my query
select * from PROFILE where CONTAINS(FIRST_NAME,:firstName OR :secondName,1)>0;
Every time I get the following exception ORA-00907: missing right parenthesis.
But after replacing :firstName and :secondName by any string it's working perfectly.
Also its working perfectly with one parameter.
select * from PROFILE where contains(FIRST_NAME,:firstName,1)>0
The above code is working. But after adding OR :secondName, the result is ORA-00907
From the Oracle Text documentation, it seems CONTAINS is a defined as a regular function with three parameters (the last one optional):
CONTAINS(
[schema.]column,
text_query [VARCHAR2|CLOB]
[,label NUMBER])
RETURN NUMBER;
The text_query parameter is a regular string interpreted as a phrase. Thus you should write:
select * from PROFILE where contains(FIRST_NAME, :search_query, 1)>0
And bind the value FOO OR BAR to the variable search_query since the OR keyword is not part of the SQL query in this case.
You should better use
select * from PROFILE where CONTAINS(FIRST_NAME,:firstName ,1)>0
OR CONTAINS(FIRST_NAME,:secondName,1)>0

How to resolve SQL query parameters mapping issues while using Oracle OLE DB provider?

When trying to enter a SQL query with parameters using the Oracle OLE DB provider I get the following error:
Parameters cannot be extracted from the SQL command. The provider might not help to parse parameter information from the command. In that case, use the "SQL command from variable" access mode, in which the entire SQL command is stored in a variable.
ADDITIONAL INFORMATION:
Provider cannot derive parameter information and SetParameterInfo has not been called. (Microsoft OLE DB Provider for Oracle)
I have tried following the suggestion here but don't quite understand what is required:Parameterized queries against Oracle
Any ideas?
To expand on the link given in the question:
Create a package variable
Double click on the package variable name. (This allows you to access the properties of the variable)
Set the property 'EvaluateAsExpression' to true
Enter the query in the expression builder.
Set the OLE DB source query to SQL Command from Variable
The expression builder can dynamically create expressions using variable to create 'parametised queries'.
So the following 'normal' query:
select * from book where book.BOOK_ID = ?
Can be written in the expression builder as:
"select * from book where book.BOOK_ID = " + #[User::BookID]
You can then do null handling and data conversion using the expression builder.
If You use Data Flow Task and use OLE DB Source, and you need parameterize your Query :
Create Variable to save "Full" of Query statement : Right Click on blank area outside the package - and Click Variables :
Click Add Variables on Variables Window :
Make the name is SQL_DTFLOW_FULL or something that can you understand easily. The variable data type is STRING
Create Variable(s) to save your parameter(s).
i.e, the full of Query stamements is :
SELECT * FROM BOOK WHERE BOOK_ID = #BookID --#BookID is SQL Parameter
at the sample above, I have just one parameter : #BookID, so I need to create one variable to save my parameter. Add more variables depends on your Queries.
Give it name SQL_DTFLOW_BOOKID
The variable data type is STRING
So, you need make your SSIS neat, and the variables is sorted in understandable parts.
Try to make the variable name is SQL_{TASK NAME}_{VariableName}
Make Expression for SQL_DTFLOW_FULL variable, click on number 1, and start fill number 2. Make Your SQL Statements to be a correct SQL Statement using string block. String block usually using "Double Quote" at the beginning and the end. Concat the variables with the string block.
Click evaluate Expression, to showing result, to make sure your query is correct, copy-paste the Query result at SSMS.
Make sure by yourself that the variables is free from SQL Injection using your own logic. (Use your developer instinct)
Open the Data Flow Task, open the OLE DB Source Editor by double click the item.
Select the Data Access Mode : SQL Command From Variable
Select the Variable Name : SQL_DTFLOW_FULL
Click Preview to make sure it works.
That is all, my way to prevent this SSIS failure case. Since I use this way, I never got that problem, you know, SSIS something is weird.
To change the variable value, set it before Data Flow Task, the SQL Result of SQL_DTFLOW_FULL variable will changed every you change your variable value.
In my case the issue was that i had comments within the sql in the normal form of /* */ and i also had column aliases as "Column name" instead of [Column Name].
Once i removed them it works.
Also try to have your parameter ? statement within the WHERE clause and not within the JOINS, that was part of the issue too.

Resources