SQL- 2005 : User Input in select statement's where cond [Input Parameter]
Hi All
i am using SQL Server 2005 , i want to select the data based on the user input in where condition,
but i am not sure what to give in where condition,can anyone have any idea on this
SELECT [NO]
,[NAME]
,[PAGE_COUNT]
FROM [DS].[DB].[tablename]
where [NO]=???
Regards
Chaitanya.A
HI
public String getEmployeeName(String employeeNumber)
// TODO : Implement
String name = new String();
String exception = new String();
try
InitialContext initialContext = new InitialContext();
DataSource dataSource =(DataSource) initialContext.lookup("jdbc/XXXX");
java.sql.Connection connection = dataSource.getConnection();
PreparedStatement stmt =connection.prepareStatement("SELECT [NAME]FROM [XXX].[ASDF].[ABCD] where [NO]=?");
stmt.setString(1,employeeNumber);
ResultSet result = stmt.executeQuery();
while (result.next())
name = result.getString("Name");
connection.close();
return name;
catch (Exception e)
exception = "Exception";
return exception;
i used the above function to achieve my requirement
Thanks
Chaitanya.A
Similar Messages
-
How to call user fuction in select statement.
hi,
i am facing some problem.How to call user functions in select statement.please send me answer with example.
Thanks
GopalLocations to Call User-Defined Functions
• Select list of a SELECT command
• Condition of the WHERE and HAVING clauses
• CONNECT BY, START WITH, ORDER BY, and GROUP
BY clauses
• VALUES clause of the INSERT command
• SET clause of the UPDATE command
Restrictions on Calling Functions from SQL Expressions
To be callable from SQL expressions, a user-defined
function must:
• Be a stored function
• Accept only IN parameters
• Accept only valid SQL data types, not PL/SQL
specific types, as parameters
• Return data types that are valid SQL data types,
not PL/SQL specific types
• Functions called from SQL expressions cannot
contain DML statements.
• Functions called from UPDATE/DELETE statements
on a table T cannot contain DML on the same table
T.
• Functions called from an UPDATE or a DELETE
statement on a table T cannot query the same table.
• Functions called from SQL statements cannot
contain statements that end the transactions.
• Calls to subprograms that break the previous
restriction are not allowed in the function.
jeneesh -
Execute an sql command other than an select statement
hello,
is it possible to execute an sql-command other than a
select statement in a report ?
something like execute ... ?
i want ro execute a statement BEFORE the select ...
or is the one and only possible statement in a report
a "select ?"
greetings
Thorsten LorenzHi ,
You can always use the Report triggers to execute any other SQL commands . If you need to execute them before the SELECT statement of you Data Model query , then You can use the Parameter Form triggers / before Report Trigger. Be sure to put in a commit statement as well, if the result of the Select statement you intend to do depends on these SQL commands.
Thanks
Oracle Reports Team. -
Pl/sql function body returning SQL query - if with in select statement
hello all,
I have a condition where when summary field is checked alone we have show that column for the users in the report. Is IF statement possible for this case ? I have given the code below.. is it possible to write something like below or is there any other way to do it ?
v_sql := 'select TBLCASES.INVESTIGATOR as INVESTIGATOR,';
v_sql := v_sql ||' TBLCASES.CASENUMBER as CASENUMBER,';
v_sql := v_sql ||' TBLCASES.OPENDATE as OPENDATE,';
v_sql := v_sql ||' TBLCASES.ESTCOMPLETE as TARGETDATE,';
v_sql := v_sql ||' TBLCASES.STATUS as STATUS,';
v_sql := v_sql ||' TBLCASES.CASECODE as CASECODE,';
v_sql := V_sql ||' TBLCASES.FAIR_HOTLINE as FAIRHotline,';
v_sql := v_sql ||' TBLCASES.NYSIG as NYSIGCase,';
v_sql := v_sql ||' TBLCASES.REGION as Region,';
IF :P44_INCLUDE_SUMMARY_FIELD is not null THEN
v_sql := v_sql||' TBLCASES.SUMMARY as SUMMARY,';
END IF ;
v_sql := v_sql ||' TBLCASES.PROGAREA as PROGArea ';
v_sql := v_sql ||' from TBLCASES where 1=1';
..\Hi Lucy,
You are adding and removing a column from a report so it may help to have the extra on the end of the query.
Do you get an error? If so paste it in...
BUT - this I would put a condition on the column where ':P44_INCLUDE_SUMMARY_FIELD is not null '
Under he report's "Column Attributes" Select the column edit icon and it has a "Condition" breadcrumb.
Select "Value of Item in Expression 1 is Not Null" and put P44_INCLUDE_SUMMARY_FIELD in Expression 1 text area.
And I make it more readable like this when I do dynamic SQL:
IF :P44_INCLUDE_SUMMARY_FIELD is not null THEN
v_INCLUDE_SUMMARY_FIELD := ' TBLCASES.SUMMARY as SUMMARY ';
END IF ;
v_sql := 'select TBLCASES.INVESTIGATOR as INVESTIGATOR,
TBLCASES.CASENUMBER as CASENUMBER,
TBLCASES.OPENDATE as OPENDATE,
TBLCASES.ESTCOMPLETE as TARGETDATE,
TBLCASES.STATUS as STATUS,
TBLCASES.CASECODE as CASECODE,
TBLCASES.FAIR_HOTLINE as FAIRHotline,
TBLCASES.NYSIG as NYSIGCase,
TBLCASES.REGION as Region,
TBLCASES.PROGAREA as PROGArea,'||
v_INCLUDE_SUMMARY_FIELD ||
'from TBLCASES where 1=1; ';
Hope it helps,
BC -
In Oracle SQL, cannot use column in select statement and order by
Hi,
Is there a work around for this.
Thanks in advance
Pablo.Hi,
943981 wrote:
Hi All,
This is the error I get:
ORA-00960: ambiguous column naming in select list
00960. 00000 - "ambiguous column naming in select list"
*Cause: A column name in the order-by list matches more than one select
list columns.
*Action: Remove duplicate column naming in select list.
Error at Line: 6 Column: 17That error message looks pretty clear to me. What don't you understand?
Either
(a) use aliases, so each column has a unique name, or
(b) remove duplicate columns from the SELECT clause.
Post your query. It's hard to say exactly what you're doing wrong when we don't know exactly what you're doing.
For best results, post a complete test script (including CREATE TABLE and INSERT statements, if necessary) that people can to re-create the problem and test their ideas.
See the forum FAQ {message:id=9360002} -
Limit users to execute "SELECT" statemes only from SQL Developer
Hi:
Is there a way to control what SQL command can be executed from SQL Developer?
I am trying to limit users to execute "SELECT" statements only from SQL Developer.
I believe SQL*Plus used to have the product profile where I can control what SQL command can be executed from what user.
Thanks in advance.There's nothing special in sqldev to enforce privileges, the database does all that already. See the database documentation on the GRANT and REVOKE statements. Basically, you would only want to grant SELECT privileges to your users...
Have fun,
K. -
Need to wite pl sql procedure for dynamic select statement
Need pl sql procedure for a Dynamic select statement which will drop tables older than 45 days
select 'Drop table'||' ' ||STG_TBL_NAME||'_DTL_STG;' from IG_SESSION_LOG where substr(DTTM_STAMP, 1, 9) < current_date - 45 and INTF_STATUS=0 order by DTTM_STAMP desc;I used this to subtract any data older than 2 years, adjustments can be made so that it fits for forty five days, you can see how I changed it from the originaln dd-mon-yyyy to a "monyy", this way it doesn't become confused with the Static data in the in Oracle, and call back to the previous year when unnecessary:
TO_NUMBER(TO_CHAR(A.MV_DATE,'YYMM')) >= TO_NUMBER(TO_CHAR(SYSDATE - 365, 'YYMM')) -
Is there any way to Mask the Name when a select statement is issued?
Dear all,
Is there any way to mask the name .. i mean if User issue a select statement in a customer table the real name should come like ' ABCXXXDEFXXCFXX'... Which is not the actual name?
e.g if Name: CHIEV SONG MEE
If user issue a statment select * from customers;
The Result Should come something Like this:
Name
CHXXV SXNG MXX
Thank Youuser3029023 wrote:
but it seems there is no option in oracle it self which can be used as there they are saying to get a data masking software which we can't due to some internal issues....I would not say that. How one implements masking depends entirely on the requirements that need to be met.
For example, schema A owns all the tables. Schema B can be created as a "trusted" schema - in other words, schema A trusts schema B and allows it full access (with grants) to its tables. Schema B implements data masking as views. For each table in A, a view exists in B that implements the required masking. B can now grant select access on these views to user C. User C will see the same data object names in B as it would have if it used A - only, by using the B data objects it uses masked data objects and not the original source data objects.
Another example - schema Dev is to have all the data objects of schema Prod, but masked where needed. One can use CTAS (Create Table As Select) to create the required tables in Dev with masked values where relevant. This Dev schema can be "refreshed" on weekends by dropping all tables and getting a new fresh copy of production data and masking it - ready for the next week's development cycle.
If the application use is for example APEX, then instead of coding SQL directly as reporting regions to display, a function is used instead. APEX supports reporting regions where it calls a function and this function provides the APEX run-time with the SQL to execute and contents to render. It is easy to use this approach to implement logic in functions that masked column data depending on who the APEX user is, the security/role attributes of the user, and so on.
No there is not a single "+mask this column!+" feature in Oracle.. but that does not mean that such a feature is not supported and cannot be implemented. Oracle has a very comprehensive and rich set of tools - more so than most (if not all) other RDBMS products.
It is up to the architect/designer/developer to use this toolkit in creating a system that meets the specific requirements at hand. -
SQL 2005 SAP R/3 4.6C - DBSL error RC=99 on import of Basis 4.6C SP 39
Hi,
I have just built a R/3 4.6C system on SQL 2005 with 4.6D_EXT kernel. The build was done using R3load to export from the 4.6C/SQL 2000/32bit system and import to 4.6C/SQL 2005/64bit system. The source 4.6C system only had Basis support package 37 applied, and I am trying to apply Basis 4.6C 38-57 on the 4.6C/SQL 2005/64bit system (in preparation for an ECC6 upgrade) and I get the following error:
EXEC SQL: SELECT ID,OBJECT,LANGU,TYP,VERSION FROM DOKIL WHERE (LANGU IN (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,
[developertra,00000] ExecuteAndFlush return code: 0x80040e10 Stmt: [CREATE PROCEDURE ##Y8IBASAPDEIBD00000025600000000006164133 @P
99972 0.099972
[developertra,00000] MapHr:80040E10 DB_E_PARAMNOTOPTIONAL 43 0.100015
[developertra,00000] HandleOledbError [ExecuteAndFlush,line 33423]: Error/Message: (err 0, sev 0), No value given for one or more
96 0.100111
[developertra,00000] DbSlPrepare - Error 99 (dbcode -2147217904) on proc. creation
56 0.100167
[developertra,00000] DbSlPrepare - <CREATE PROCEDURE ##Y8IBASAPDEIBD00000025600000000006164133 @P000 varchar(3072) = ' ', @P001 v
105 0.100272
[developertra,00000] 1 times error (0,0) in sequence 30 0.100302
[developertra,00000] dbdsmss: DBSL99 SQL0 27 0.100329
[developertra,00000] No value given for one or more required parameters.
62 0.100391
[dbds ,00589] ***LOG BY2=>sql error 0 performing FET
66 0.100457
[dbds ,00589] ***LOG BY0=>No value given for one or more required parameters.
I have checked the collation setting in SQL 2005 and it is:
select serverproperty('collation')
SQL_Latin1_General_CP850_BIN2
There are 97000 odd entries in DOKIL, so I don't think that is the problem.
Would appreciate any assistance.
Kind regards,
Sheryl.Hi ,
Instead of doing the build with export import, you can try to do the same with backup restore,,
But remember your sql2000 should be on bin2... then you can take backup and restore.
Since it is from 2000 to 2005 the restore would happen and it will work fine.
Try this and check out, since the error you have pasted is not clearly giving any picture...
Regards,
Ravi. -
Calling an SP takes over 200% more time over the select statement
As part of my POC converting a SQL Server application over to SAP HANA, I'm find that CALL is taking over 200% more time than calling the SELECT statement directly. The result is that the application that uses ODBC against HANA with CALL statements is taking much more time than SQL Server. I'm finding this for all stored procedure calls in the application. Here is an example:
CREATE PROCEDURE dbo.usp_GetOrdersByCustomerID
(IN C_ID bigint)
LANGUAGE SQLSCRIPT DEFAULT SCHEMA "DBO" READS SQL DATA
AS BEGIN
SELECT TOP 20
C_F_NAME,
C_L_NAME,
C_EMAIL,
O_ID,
O_TOTAL,
O_DTS,
O_FM_DTS
FROM dbo.Customer JOIN dbo.Orders ON C_ID = O_C_ID
WHERE C_ID = :C_ID
ORDER BY O_ID DESC;
END;
When using the following CALL statement in SAP HANA Studio
CALL dbo.usp_GetOrdersByCustomerID(3429);
I get execution times that look like this:
Statement 'CALL dbo.usp_GetOrdersByCustomerID(3429)'
successfully executed in 9 ms 663 µs (server processing time: 8 ms 115 µs)
Fetched 5 row(s) in 0 ms 69 µs (server processing time: 0 ms 0 µs)
Statement 'CALL dbo.usp_GetOrdersByCustomerID(3429)'
successfully executed in 11 ms 851 µs (server processing time: 8 ms 238 µs)
Fetched 5 row(s) in 0 ms 62 µs (server processing time: 0 ms 0 µs)
Statement 'CALL dbo.usp_GetOrdersByCustomerID(3429)'
successfully executed in 8 ms 522 µs (server processing time: 6 ms 892 µs)
Fetched 5 row(s) in 0 ms 93 µs (server processing time: 0 ms 0 µs)
When I execute the select statement with the hard coded parameter value, I get much faster results:
Statement 'SELECT TOP 20 C_F_NAME, C_L_NAME, C_EMAIL, O_ID, O_TOTAL, O_DTS, O_FM_DTS FROM dbo.Customer JOIN ...'
successfully executed in 4 ms 430 µs (server processing time: 2 ms 424 µs)
Fetched 5 row(s) in 0 ms 73 µs (server processing time: 0 ms 0 µs)
Statement 'SELECT TOP 20 C_F_NAME, C_L_NAME, C_EMAIL, O_ID, O_TOTAL, O_DTS, O_FM_DTS FROM dbo.Customer JOIN ...'
successfully executed in 4 ms 105 µs (server processing time: 2 ms 210 µs)
Fetched 5 row(s) in 0 ms 69 µs (server processing time: 0 ms 0 µs)
Statement 'SELECT TOP 20 C_F_NAME, C_L_NAME, C_EMAIL, O_ID, O_TOTAL, O_DTS, O_FM_DTS FROM dbo.Customer JOIN ...'
successfully executed in 4 ms 694 µs (server processing time: 2 ms 810 µs)
Fetched 5 row(s) in 0 ms 60 µs (server processing time: 0 ms 0 µs)
I have 500,000 rows in the Customers table and 2,500,000 rows in the Orders table. The tables are COLUMN tables.
Is there an optimization that I'm missing?
Regards,
BillHi Bill,
Can you please try something:
tab_cust =
SELECT
C_F_NAME,
C_L_NAME,
C_EMAIL
FROM dbo.Customer
WHERE C_ID = :C_ID;
tab_orders =
SELECT
O_ID,
O_TOTAL,
O_DTS,
O_FM_DTS
FROM dbo.Orders ON C_ID = O_C_ID
WHERE O_C_ID = :C_ID
SELECT TOP 20
C_F_NAME,
C_L_NAME,
C_EMAIL,
O_ID,
O_TOTAL,
O_DTS,
O_FM_DTS
FROM :tab_cust JOIN :tab_orders ON C_ID = O_C_ID
ORDER BY O_ID DESC;
END;
Expected behavior: The data set for each of the tables is filtered out and then joined. Although the filter is expected to be pushed to each of the joined tables even in your case, but this is worth the try.
Regards,
Ravi -
PL/SQL in user defined reports
Is it possible to use PL/SQL in user defined reports? As far as I know, it isn't, but...
And one more question: can we do something like this in user defined reports:
' select * from :TABLE '
where
:TABLE is a bind variable?
Thanks in advance
AliqI want to create a parent-child report, which in simply version does three things:
parent
1. takes all the table names from user_tables
2. for each table_name (taken from user_tables) it takes a few rows from this table (selet A,B,C from table_name).
child
3. for each table name (from master) gives additional information from this table (select D,E,F from table_name)
And I wonder if it's possible. -
We are upgrading to new server and installing SQL 2005. Using Crystal Server 10. Where can I find a step by step? Can I just backup Business Objects Database, install the app on the new server, restore the database to SQL 2005?
Thanks,
SSHi Samuel
You can refer the below link for more information on SQL Server 2005 upgrade.
[http://www.microsoft.com/technet/prodtechnol/sql/2005/sqlupgrd.mspx#top]
Regards
Girish. -
Hint in Update or Select Statement in an inline query ??
Hi ,
I had an update statement that will get the data from the inline select statement,now where can i can keep the hint ,either in update statement or in Select statement...
Please let me know if my sample script is wrong or any better way to approach...Please assume that Salary table had millions of employee's salary records.
update emp
set salary = salary + (select /*+ full(a) parallel(a,4) */ salary from Salary
where experience > 5 and empno = 55 )
where empno = 85Thanks
RedeYou would put the hint in the select statement as you have it, but it won't work until you alias your table name to "a" since that is how you are referencing it in the hint:
update emp
set salary = salary + (select /*+ full(a) parallel(a,4) */ salary from Salary a
where experience > 5 and empno = 55 )
where empno = 85
NOTE I added the "a" right after the Salary table name AND you can only do parallel updates on partitioned table, but the select will run in parallel to at least get the data for you quickly.
To answer your other question about syntax, it is incorrect and there are a lot of ways to write it but a straight forward way would be to use the merge statement
merge into emp e
using (select /*+ full(s) parallel(s,4) */ s.salary from salary s where s.experience > 5) s
on (e.empno = s.empno)
when matched then update
set salary = s.salary; -
Using Hint in Update or Select Statement...
Hi ,
I had an update statement that will get the data from the inline select statement,now where can i can keep the hint ,either in update statement or in Select statement...
Please let me know if my sample script is wrong or any better way to approach...Please assume that Salary table had millions of employee's salary records.
update emp
set salary = salary + (select /*+ full(a) parallel(a,4) */ salary from Salary
where experience > 5 and empno = 55 )
where empno = 85Thanks
RedeThe better approach would be to determine why you need a hint in the first place. If you're using a hint, that implies that the optimizer is choosing the incorrect plan when left to its own devices. That, in turn, implies that the statistics on your objects, the statistics on your system, your optimizer parameters, your session's optimizer settings or some other variable is incorrect. You're generally better off fixing the root problem than hinting every query.
In this specific case, the parallel hint is invalid because there is no table aliased A. The full hint is invalid for similar reasons. Plus, with the query you provided, if A was intended to be the SALARY table, it seems exceptionally unlikely that you really want to do a full scan on the salary table to look for what had better be a single row (otherwise your query would throw a "too many rows returned" exception).
Justin -
Using Case Statement in Where Clause
Hello All,
I wish to conditionally use different columns for retrieving unique row. This will be dependent upon a parameter passed to the Function/Procedure.
The SQL framed looks as below:
+select *+
from Test_Table
where column_1 = <some_value>
and case when p_call_location = 'A' then column_2 like '%ABC%'
when p_call_location = 'B' then column_2 Not Like '%ABC%'
when p_call_location = 'C' then column_3 like '%EFG%'
when p_call_location = 'D' then column_3 like '%IJKL%'
END;
However, I am not sure if this works, as I am getting a Missing Right Paranthesis error. Major hinderance is the depedency on multiple columns, which would need to be referred for particular scenario.
Can somebody please help me with an example or a skeleton of how a query should be formed?
Appreciate an early reply!!!HI,
i think this may solve your issue...get back to me if u have any qry's on this.
CREATE TABLE Test_Table
(p_call_location VARCHAR2(10),
COLUMN_1 VARCHAR2(20),
COLUMN_2 VARCHAR2(20),
COLUMN_3 VARCHAR2(20))
INSERT INTO Test_Table VALUES('A','COMNVAL','ABC_PER','XXXX');
INSERT INTO Test_Table VALUES('A','COMNVAL','PER','XXXX');
INSERT INTO Test_Table VALUES('B','COMNVAL','ABC_PER','XXXX');
INSERT INTO Test_Table VALUES('B','COMNVAL','PER','XXXX');
INSERT INTO Test_Table VALUES('C','COMNVAL','ABC_PER','EFG_XXXX');
INSERT INTO Test_Table VALUES('C','COMNVAL','ABC_PER','XXXX');
INSERT INTO Test_Table VALUES('D','COMNVAL','ABC_PER','EFG_XXXX_IJKL');
INSERT INTO Test_Table VALUES('D','COMNVAL','ABC_PER','GGG_XXXX');
SELECT * FROM Test_Table WHERE ROWID IN (
select case when p_call_location = 'A' AND column_2 like '%ABC%' THEN ROWID
when p_call_location = 'B' AND column_2 Not Like '%ABC%' THEN ROWID
when p_call_location = 'C' AND column_3 like '%EFG%' THEN ROWID
when p_call_location = 'D' AND column_3 like '%IJKL%' THEN ROWID
END AS KK
from Test_Table
where column_1 = 'COMNVAL');
even u can use the below qry also
select *
from test_table
where column_1 = 'COMNVAL'
and (case when p_call_location = 'A' and column_2 like '%ABC%' then 'VALID'
when p_call_location = 'B' and column_2 Not Like '%ABC%' then 'VALID'
when p_call_location = 'C' and column_3 like '%EFG%' then 'VALID'
when p_call_location = 'D' and column_3 like '%IJKL%' then 'VALID'
else 'INVALID'
END) = 'VALID';
thanks
prasuna.
Edited by: user13820845 on Feb 21, 2011 10:25 PM
Maybe you are looking for
-
My kids want apple products. I don't own any. I buy an iPad for one and an iPhone for the other, but I can't set them up because they require me to setup Family Share and create accounts. I can't do that because I don't have a device with iOS 8 alre
-
IPod Classic (7th Generation) won't reset to factory settings...
Hi, I have a Apple iPod classic 160 GB Black (7th Generation). I had tried to sync it to my MacBook Pro, which the iPod was set up with, will not show up in iTunes. I will get an error message "The iPod "iPod" could not be restored because it could n
-
Commons fileupload problem with Jdeveloper
Hi, I tried to use commons fileupload with jdeveloper and I have put those two jar files under web-inf/lib directory. but it did not work. Anyone can help? Thanks in advance. Error code is shown below: Error(79,33): illegal start of expressionError:
-
Problem updating iPod software
When I open iTunes with my video iPod connected I get this dialog: "Some of the items in the iTunes library were not copied to the iPod because your iPod software is old. Go to the Summary tab and click Update...." etc. When I go to the Summary tab t
-
Hi, Using the Java Object Caching library (formerly OCS4J), you can set a parameter for the Maximum size of your cache. I am using the Cache to store some custom Object in the Application Server. If I set the Max Cache Size it is ignored. Does this C