PL-SQL Solve: Using INSTR and SUBSTR
I am trying to work on this and cannot get a solution. Please help
You have to use INSTR and SUBSTR to solve
Question:
You have the following acceptable value
Numberic: 0-34
80-100
or Non Numberic X S U D- D D+
Im have to use INSTR and SUBSTR functions to test that the value is a valid (as above) number before TO_NUMBER is called:
SELECT TO_NUMBER('?? ') //HERE ?? and a space (for 100 etc) is for the values as above
FROM DUAL
WHERE ....INSTR(......)<=;
(Hence if the number is true then number comes back or it says no rows)
and also id non numberic it should also be tested.
I am completely unsure about it but tried this
SELECT TO_NUMBER('34 ')
FROM DUAL
WHERE INSTR('0123456789',1,1)<=9 (looking at first number ?)
AND
INSTR('0123456789',2,2)<=9
AND
INSTR('0123456789',3,3)=0;
Please help
We have the following value that we can use:
Numeric: 0-34 and 80-100 only
or Non Numberic X S U D- D D+
Have to use INSTR and SUBSTR functions to test that the value is a valid
(for now only trying to create a function which can later be put into a procedure.)
SELECT TO_NUMBER('12 ') //e.g HERE 12 and a space for the values as above
FROM DUAL
the where clause looks at all three spaces to make sure values are correct (given number or non-numberic values only)
(Hence if the number is true then number comes back (meaning true)
or it says NO rows)
If value is non numeric, test it to allow non numberic also.
I am completely unsure about it but tried this
SELECT TO_NUMBER('34 ')
FROM DUAL
WHERE INSTR('0123456789',1,1)<=9 (looking at first number ?)
AND
INSTR('0123456789',2,2)<=9
AND
INSTR('0123456789',3,3)=0;
Something like this has to be done.....subst (instr, x,x,) i think mite help.
Similar Messages
-
Some instr and substr fundamental
Hi,
In a procedure, my input parameter would be 123,345,456,567......I will put this in a loop..
My requirement is like first it will take 123 and i will do some calculation end loop,
then 345 and i will do some calculation end loop,
then 456 and i will do some calculation end loop,
then 567 and i will do some calculation end loop, and so on...
i think there is some instr and substr fundamental..
Will be great if i get some suggestion to solve the issue...
Thanks,
HPNot quite.
Dbms_utilty.comma_to_table will do the job quite nicely.
http://www.java2s.com/Code/Oracle/System-Packages/demonstratestheuseofDBMSUTILITYTABLETOCOMMAandDBMSUTILITYCOMMATOTABLE.htm
Sybrand Bakker
Senior Oracle DBA -
Hi All,
I need to get the "Creation Script" of the existing table using c# and without using SMO dlls (is it possible? I don't know).
I.e. In SQL Management Studio -> right click on any table -> Script table as -> Create To - > open in the new query editor window. This will give you the schema of the table with the constraints of the table.
For E.g. In Northwind database, for the table "Categories", I would like to get it as show below
USE [Northwind]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Categories](
[CategoryID] [int] IDENTITY(1,1) NOT NULL,
[CategoryName] [nvarchar](15) NOT NULL,
[Description] [ntext] NULL,
[Picture] [image] NULL,
CONSTRAINT [PK_Categories] PRIMARY KEY CLUSTERED
[CategoryID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
I would like to get the same schema using c#. Please help.
Thanks & Regards,
Kalai.SMO is the easiest way to get this. This is what Management Studio uses. If you can't use SMO, get a Profiler trace of the queries that SMO executes when generating the script and execute the same using ADO.NET.
Regards,
Farooq Mahmud
Support Escalation Engineer
• Microsoft Health Solutions Group -
Issue while importing table from oracle to sql server using import and export wizard
Hi All,
I am trying to populate oracle table to sql server using import export wizard and i am getting the below error.the table is allready present in the database but still it throwing error like table doesn't exists.
Could not connect source component.
Error 0xc0202009: Source - JOB_ACTION_HISTORY [1]: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005.
Error 0xc02020e8: Source - JOB_ACTION_HISTORY [1]: Opening a rowset for ""FLXUSER"."JOB_ACTION_HISTORY"" failed. Check that the object exists in the database.
(SQL Server Import and Export Wizard)
Kindly help me out
Thanks in advanceHi Snehasis,
Please check whether the table name in the Oracle database has lower case letters. The table name should be exactly correct.
In addition, the issue might be related to the Oracle driver. What provider/driver do you use? If you use Microsoft OLE DB Provider for Oracle, you can try the
Oracle OLE DB Provider. If you use Enterprise or Developer edition of SSIS 2008 or higher, you can also try the
Microsoft Connectors for Oracle by Attunity. The Oracle OLE DB Provider and Microsoft Connectors for Oracle are proved to have better performance.
Regards,
Mike Yin
TechNet Community Support -
Sql loader using position and functions
Hi all, i need help loading some data in my table using sql loader. consider the following
CREATE TABLE er
a1 NUMBER,
a2 number,
a3 VARCHAR2(100),
a4 VARCHAR2(100),
a5 VARCHAR2(100),
a6 VARCHAR2(100),
a7 VARCHAR2(100),
a8 VARCHAR2(100)
OPTIONS (BINDSIZE=20548000, READSIZE=20548000, STREAMSIZE=20548000, DATE_CACHE=25000, SKIP=0)
LOAD DATA
INTO TABLE er
APPEND
TRAILING NULLCOLS
a1 POSITION(0001:0021) ,
a2 POSITION(0022:0042) "DECODE(SUBSTR(:a2,1,3),'***',NULL,:a2)" ,
a3 POSITION(0043:0053) ,
a4 POSITION(0054:0064) ,
a5 POSITION(0065:0075) ,
a6 POSITION(0076:0086) ,
a7 POSITION(0087:0093) "DECODE(SUBSTR(:a7,1,3),'***',NULL,:a7)"
BEGIN
0.00 ******************** X X X *X ****
END;if you look at the data, some fields have a lot of * and some has af few such as ****. i want to load this data into a table and when a field contain all * as a value, i want to set it to null. if a field contain a * and alphanumeric then that value should be load as it is.
in the example above, ******************** should be set to null and **** should also be set to null. notice that there is a field with X. since this field contain alpha numeric, it should be loaded into the table as is. the only time field should be set to null is when the value contain all .
somebody in this forum suggest using decode but it looks like it is not working and i get error when it reads second field and try to insert into a2 number column.
is there any way to use regular expression to find out if a field contain all *. also i want to trim each field since they might contain leading spaces.
can some one help with this using the sqlloader ctl and data above?You can include regular expression in you SQL*Loader control file.
An example can be found here:
http://www.morganslibrary.org/reference/sqlloader.html
Demos 7 and 8 using the UPPER and DECODE functions to illustrate how to do it. -
I'm using the LabView Database Connectivity Toolset and am using the following query...
UPDATE IndexStation
SET Signal_Size=200
WHERE 'StartTime=12:05:23'
Now the problem is that this command seems to update all rows in the table IndexStation... Not just specifically the row where StartTime=12:05:23
I have tries all sorts of {} [] / ' " around certain characters and column names but it always seems to update all rows...
I've begun to use the SQL query tab in Access to try and narrow down as to why this happens, but no luck!
Any ideas!?
Thanks,
Chris.Chris Walter wrote:
I completely agree about the Microsoft issue.
But it seems no SQL based manual states that { } will provide a Date/Time constant.
Is this an NI only implementation? Because I can't seem to get it to function correctly within LabView or in any SQL query.
Chris.
There is nothing about the database toolkit in terms of SQL syntax that would be NI specific. The database Toolkit simply interfaces to MS ADO/DAO and the actual SQL syntax is usually implemented in the database driver or database itself although I wouldn't be surprised if ADO/DAO does at times munch a bit with that too.
The Database Toolkit definitely does not. So this might be a documentation error indeed. My understanding of SQL syntax is in fact rather limited so not sure which databases might use what delimiters to format date/time values. I know that SQL Server is rather tricky thanks to MS catering for the local date/time format in all their tools and the so called universal date/time format has borked on me on several occasions.
Rolf Kalbermatter
Rolf Kalbermatter
CIT Engineering Netherlands
a division of Test & Measurement Solutions -
Data to sql server using labview and labview sql toolkit
Hello everyone,
I am using mssqlserver 7.0, labview 6.1 and labview sql toolkit.
I am getting error while i try to store (large) data of size more than 4000bytes. Has anyone come accross such problem .
Looking for your solutions or suggestion for the
above said problem.Check if the threshold is actual 4095 or 4096.
If so it is probably a default size of the field you are trying to write. If so, change table properties.
Ben
Ben Rayner
I am currently active on.. MainStream Preppers
Rayner's Ridge is under construction -
How to execute the *.sql when using occi and vc
help me!
i must to initialize the remote database using the file of sql,
for example:
the file is ss.sql;
and it is
"DECLARE
row integer := 0;
user varchar2(256);
BEGIN
user := '&1';
dbms_java.grant_policy_permission('PUBLIC', 'SYS',
'java.lang.RuntimePermission', 'loadLibrary.*', row);
dbms_java.grant_permission(user, 'SYS:java.lang.RuntimePermission',
'loadLibrary.orawcom10', null);
dbms_java.disable_permission(row);
dbms_java.delete_permission(row);
EXCEPTION
WHEN OTHERS THEN
IF row > 0 THEN
dbms_java.disable_permission(row);
dbms_java.delete_permission(row);
END IF;
RAISE;
END;"
i use the occi statement
Environment * env;
Connection * conn;
Statement * stmt;
env=Environment::createEnvironment(Environment::DefaultEnvironment);
conn=env->createConnect(user_name,pwd,db_name);
string sqlstmt=''BEGIN ss.sql;END";
stmt=conn->createStatement(sqlstmt);
it is wrong
how do i change the sql statement???Hi,
Instead of having the PL/SQL code as an anonymous block, you can create
a procedure and then execute it through OCCI.
For example:
create or replace procedure my_proc
is
row integer := 0;
user varchar2(256);
begin
--code here...
end;
I assume this code will be in ss.sql. Compile this procedure in
your schema and then form the sqlstmt in OCCI this way:
Statement *stmt = con->createStatement("BEGIN my_proc; END;") ;
Rgds.
Amogh -
SQL Developer (using TNS and LDAP) fails
If I use a Basic Connection Type and specify the Host, Port and Service Name I can get connected.
If I use a TNS Connection Type and click on the appropriate Network Alias I get:
Status: Failure -lo exception: SO exception was generated.
The SQLNET.ORA file has this entry:
NAMES.DIRECTORY_PATH= (LDAP)
SQL*Plus connections work fine.
Has anyone seen this issue and resolved it ?
Thanks,
Bob LarsenBob,
TNS connection with Network Alias option should work.
I assume you have a local tnsnames.ora file with the database entry.
You can launch sqldeveloper from sqldeveloper\sqldeveloper\bin\sqldeveloper.exe
or sqldeveloper\sqldeveloper\bin\sqldeveloper.bat.
This will give a stack trace.
Thanks,
Sri -
Sql Tuning using OEM and Logon triggers
OEM = 10.2.0.4/Agent 10.2.0.4
Target = 10.2.0.3 Db
We have several db users that have session level adjustments made by use of logon triggers. When OEM is used to review one of those session's performance and sql tuning opportunities - are the logon triggers and the session level settings taken into consideration? Another way to ask is if the suggested changes from the sql profiler are making decisions based on the user's session level settings?
Thank you in advance.
-abeYour logon triggers affect the new sessions. When you monitor with OEM, it is no affect on OEM's activity. Hoping that, your logon trigger did not affect the user which OEM uses to connect to repository DB.
-
Instr and substr function in oracle issues
hi all
I have an issue to split my filename
Filename is as below:
ABCD01_123456789_samplename_13062012_10062012-12-12-12-1.PDF
my output as below
Col1 Col2 col3 col4 col5 col6
ABCD01 123456789 samplename 13062012 10062012 10062012-12-12-12-1.PDFcan you please help me to split this using any simple method
thanks ain advance
Edited by: A on Jun 12, 2012 8:25 PM
Edited by: A on Jun 12, 2012 8:25 PM>
can you please help me to split this using any simple method
>
You can split the string into rows using the same technique used in this example
http://nuijten.blogspot.com/2009/07/splitting-comma-delimited-string-regexp.html
Just replace the ',' with an underscore.
Then you can convert the rows to columns using LISTAGG like this example
http://www.oracle-base.com/articles/misc/string-aggregation-techniques.php
Search the forum for 'rows to columns' and you will find plenty of other alternatives. -
SQL Statement using LIKE and Subquery?
Hi,
I have two tables, one table is called "Restricted_Words", the other table is called "Content" . I have a field called "short_desc" in the Content table and a field called "word" in the Restricted Words
table.
I want to write a query that will compare all the words in the restricted words table against the short_desc field in the content table and just return all the records in the content table that contain 1 or more of these words.
I started with this:
SELECT short_desc
FROM Content
WHERE short_desc LIKE ( SELECT word FROM Restricted_Words )
I know the above isn't valid and won't work, but that's what I'm trying to do.
Any help appreciated...Sorry cannot test it right now...
SELECT short_desc
FROM Content
WHERE short_desc LIKE ( SELECT word FROM Restricted_Words where
word like '%'+short_desc
+'%' )
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
Missing right parenthesis using DECODE and SUBSTR
Hello,
Can anyone explain why I am getting missing right parenthesis when trying to execute this query
INSERT INTO LOCATION_INFO
(LOCATION,REGION)
SELECT SUBSTR(OLD_SYSTEM_SITE_CODE,1,2), DECODE(SUBSTR(OLD_SITE_SYSTEM_CODE, 1, 2), 'CA', CHICAGO,'TX', DALLAS, NEW YORK)
FROM SITE_MAPPING_TABLE;Thanks for looking
MikeINSERT INTO LOCATION_INFO
(LOCATION,REGION)
SELECT SUBSTR(OLD_SYSTEM_SITE_CODE,1,2),
DECODE(SUBSTR(OLD_SITE_SYSTEM_CODE, 1, 2), 'CA', 'CHICAGO','TX', 'DALLAS', 'NEW YORK')
FROM SITE_MAPPING_TABLE;i think the CHICAGO, DALLAS, and NEW YORK are character strings and should be enclosed in single quotes -
Using Charindex and Substring together
Hi Friends
I have the one column String has Amberley Lodge(London) I want
only this string
Amberley Lodge for another new Column.
Can you please help me thank you.
Thanking you for advanceThank you very much for your replay
Jingyang
Li
Jingyang Li
MCC
10,655 Points1032
Recent Achievements
Forums
Answerer IV Code
Answerer III First
Marked Answer
Jingyang
Li's threadsView
Profile -
Oracle to SQL Server using JDBC
I would like to connect Oracle to SQL Server using JDBC and a java program in oracle using loadjava.
I cannot seem to get a SQL Server driver to work when loaded into Oracle using loadjava. Outside of oracle, they work just fine. Within oracle, I receive class not found exceptions.
PLEASE HELP!!!!!!!I would like to connect Oracle to SQL Server using JDBC and a java program in oracle using loadjava.
I cannot seem to get a SQL Server driver to work when loaded into Oracle using loadjava. Outside of oracle, they work just fine. Within oracle, I receive class not found exceptions.
PLEASE HELP!!!!!!!
Maybe you are looking for
-
OIM: Error while updating Task Attributes
Hi All, I am trying to use PeopleSoft User Management using OIM connector. I am facing an error saying "problem in updating Task Attributes" while scheduling a task on OIM design Console. I am trying to update and save PSFT Base Non Trusted User Reco
-
Which new Macbook to replace my 2008 Macbook Pro?
I am about to buy a new replacement for my 5 year old 15" Macbook Pro which I have sworn by, but is slowly letting go. I would like someones opinion: should I replace it with the new 13 inch Macbook Air, or 13 inch Macbook Pro? I would use it mostly
-
Data Transfer Betw 8i's 0040, ODBC, or OLE DB Drivers & XML
I have researched that Oracle has 3 database drivers for accessing Windows NT data - they are Oracle 8i's: 0040, ODBC Driver, and OLE DB drivers. Do these drivers allow data transfer between XML and Oracle 8i? null
-
TOC text flows on top of existing text
My book text is in a master text frame and everything seems find -- until I try to generate the table of contents. After I have loaded the cursor and click on the page I want the TOC to start, the text simply dumps out on page after page, over the TO
-
Help ----- DUMP: bread: dev_seek error: I/O error
Dear All, While taking a backup I am facing some problem with one mount point in the server, getting the below error when taking a backup on tape with the help of UFSDUMP. Solaris 9 is running in this server. Could you please help me to resolve this