SQL & PL/SQL :: Inherit From Varchar 2 / Number

Mar 22, 2012

I see you can build an address object consisting of street name and number, city and so on, and use this in CREATE TABLE, so all tables use the same fields for addresses. And moreover you can add check functions to prevent street numbers to be negative for instance in the constructor. You can even use inheritance. I like that.

However, all teaching on this subject I found on the Internet starts with structs (points consisting of x and y, persons consisting of name and address, etc.). Then they go to inheritance and show how to build an employee who is just a person plus an employee number. They never start with simple types.

What I would like to do would be rather to start with basic types such as number or varchar2 and inherit from them. An EAN is a VARCHAR2 holding only digits where the last digit is a check sum that must be matched. An item number may be a VARCHAR2 matching 'NNN-AAAA'. A simple string may be a VARCHAR2 where no functional characters such as carriage return, etc. occur.

I would then write my create table statement thus:

CREATE TABLE item (itemno T_ITEMNO, ean T_EAN, itemname T_SIMPLESTRING); and inserts like INSERT INTO item values('123--BCD', '1234567890abc', 'toy') would fail with exceptions like 'item numbers must be formatted NNN-AAAA' or '1234567890abc is not a valid EAN'.

However this seems not possible:

create or replace type T_EAN under varchar2
(
constructor function T_EAN(p_string in varchar2) return self as result
);

fails with "PLS-00580: supertype must be an object type".

Rather than creating completely new types, I would start with extending existing types, but this seems not possible. Is that really impossible or am I using the wrong approach?

View 4 Replies


ADVERTISEMENT

SQL & PL/SQL :: Varchar Not Printing Zero Front Of Number?

Feb 18, 2013

Today we faced one strange issue Varchar doesnot print the zero front of number

eg

SQL> select agent_code from table_name where AGENT_CODE = 0061;
AGENT_CODE
----------
61
61

where in my database agent_code columns as value 0061 and 061 for both it shows same value.

View 9 Replies View Related

SQL & PL/SQL :: Result Come As Number Like To Change Varchar

Jun 28, 2011

I have procedure that is used by trigger but I define it as Varchar2 it's result show number.

change my PLSQL to use as varchar,

If trigger fired, the procedure make this query

select CB_SMS_FLAG, CB_SMS_DT from TM_SFS_CUST_04 where CUST_NUM = 01071234151;

but I want this query

select CB_SMS_FLAG, CB_SMS_DT from TM_SFS_CUST_04 where CUST_NUM ='01071234151';
because CUST_NUM is VARCHAR2(12)

so it can use index appropriately.

how can I change my PLSQL this sentence,

v_sel_sql1 := 'select CB_SMS_FLAG, CB_SMS_DT from ' || pTBL_NM ||' where CUST_NUM = ' || pCUST_NUM;

Here my code

CREATE OR REPLACE PROCEDURE ORAASFS.P_TM_SFS_CB_SMS_CNT_upd_104(
gKIND VARCHAR2,
pCUST_NUM VARCHAR2,
pSMS_CNT NUMBER,
pSMS_CLC VARCHAR2,
pRD_FLAG VARCHAR2,

[Code]....

View 4 Replies View Related

SQL & PL/SQL :: Query Two Columns With Datatypes As Number And Varchar

Jul 17, 2012

Have table with two columns with datatypes as number and varchar and the values in A column like 1,2,3 AND B column values like a,b,c. Now need to display data in a single column as 1,a,2,b,3,c.

View 4 Replies View Related

SQL & PL/SQL :: Using Varchar Parameter In Queries With Number Column Can Result In Performance Degrade

Jul 4, 2013

I would like to know if using varchar parameter in sql queries with number column can result in performance degrade.

Ex: Procedure testa ( myparam varchar) is
begin
select col1 into var1 from table where colno = myparam;
end;

Here col no is a number column and myparam is varchar. I feel its better to change the parameter to number.

View 7 Replies View Related

Networking And Gateways :: Resetting Password For Listener Inherit?

Dec 7, 2010

I just found out that the LISTENER I've creating with a password was with "-inherit" settings. Twice I succeeded in doing this, but it seems that it's not working when I tested it. Thus, I opted to get rid of it's listener.bak file and set the password again. Now I just can't stop it because of this error message: "TNS-01169: The listener has not recognized the password".

I've tried every passwords I made, and tried resetting it, but I'm not successful either, it's the same error message.My last option would be to restart the db Server (since the original listener.ora is already intact),

View 7 Replies View Related

SQL & PL/SQL :: Compare Varchar With Date

Feb 26, 2012

I have one command compare varchar type with date type by Pl/SQL.

date_entry gave values:" 2012/01/06 22:28:24",

now i want to convert it to date and compare with sysdate.

Select * From qvsystem
Where to_char(to_date(date_entry, 'rrrr-mm-dd hh24:mi:ss'), 'dd-mm-rrrr') = to_char(Sysdate, 'dd-mm-rrrr');
----
note:date_en2012/01/06 22:28:24

after I executed that command It's appear one message .

View 7 Replies View Related

SQL & PL/SQL :: Convert Long To Varchar

Aug 30, 2012

display or get values stored in a long column.i tried the below code, but myvar is shown as null. am i missing something here or is there a better apporoach than this ?. There are actually 16 rows returned for this query but with empty values for 'high_value' column which is critical for me. How can i do this long to varchar convertion ?

SET SERVEROUTPUT ON
DECLARE
my_var long;
BEGIN
for x in ( SELECT high_value
FROM all_tab_partitions
WHERE table_name = 'SALES_DISCOUNT'
AND table_owner = 'CED12'
ORDER BY partition_position DESC )
[code]....

View 4 Replies View Related

SQL & PL/SQL :: Creation Of Sequence To Varchar

Dec 7, 2011

how to create sequence to varchar and how see that sequence

View 2 Replies View Related

SQL & PL/SQL :: Getting Highest Value From Varchar Column

Feb 12, 2011

I've a large table on which I applying aggregate and group by functions to the the results.

Here are two of the columns in my table:

Name ==== Score
John ==== 200*
Zohaib ==== 299
Ali ==== 0*
John ==== 200
Maria ==== 150*
Ali ==== 0
Maria ==== absent
John ==== absent

Here astrick (*) means with distinction....

The "score" column is a varchar column I want to run a query on this table to show the highest score for each student and the output should be like this:

Name ==== Score
Zohaib ==== 299
John ==== 200*
Maria ==== 150*
Ali ==== 0*

Important note:

1. if there is a tie between two highest scores like for a student, incase of john 200 was made twice, but the score with asterick (*) will be the "maximum" becuase it is with distinction so the output should also show the the highest score with asterick.

2. the output should show the the 2nd column (score) in desc order of highest score by each student...again incase of a tie, the one with astrick will come first in the result..

I know with just mere numbers, that is pretty easy but in this case it is a varchar column and also i need the astrick along with the highest score.

I want the simplest and shortest query if possible to achieve this result

I hope I've been able to clearly explain my requirment. I am using 10G.

View 1 Replies View Related

SQL & PL/SQL :: Difference Between Varchar And Varchar2?

Aug 31, 2012

What is the exact difference between varchar and varchar2?

As i know only the length is the one difference.Apart from this length,what are all the differences?

View 3 Replies View Related

SQL & PL/SQL :: Storing Unicode In Varchar

Feb 3, 2011

I have a varchar field in a table. When I store the following string, some undefined character is storing.

String to be stored: Test String
String actually stored: Test ¿ string

Please note that here '' is not Hyphen. It is a special character that msword has. when you copy this and paste in a word document you find the difference.

I have listed the character set for CHAR and NCHAR from NLS_DATABASE_PARAMETERS

NLS_CHARACTERSET - WE8ISO8859P1
NLS_NCHAR_CHARACTERSET - AL16UTF16

View 12 Replies View Related

SQL Statement With Varchar Datatype Size

Dec 21, 2010

The below table and functions are examples, but issue is like this.

i have one issue while forming below sql , Application will form this query at run time wih required inputs
it is failing because the application will not support the clob datatype.

Table : T_E (similar to EMP table structure)

This table has data similar to emp but bulk data around 10k records.

Query formed

select empno,ename, get_employees(deptno)
from t_e;

This sql query this is failing when function return varchar2 string more than 4000 size.Because in sql query size should not exceed 4000 for varchar2 data type , function return size can be upto 20000

Function which
CREATE OR REPLACE FUNCTION get_employees (p_deptno in emp.deptno%TYPE)
RETURN varchar2
IS
l_text varchar2(32767) := NULL;
BEGIN
FOR cur_rec IN (SELECT ename FROM t_e WHERE deptno = p_deptno) LOOP
l_text := l_text || ',' || cur_rec.ename;
END LOOP;
RETURN LTRIM(l_text, ',');
END;

I can try this with clob but application doesn't support that..so i tried with using clob in above function , after that while returning to application i want to conver the clob to char and return the entire string

select empno,ename, to_char(substring(get_employees(deptno),1,4000)) -- first 4000 characters
, to_char(substring(get_employees(deptno),4000,8000)) -- next 4000 characters
from t_e;

But this is failing how to return the entire string in above sql

View 1 Replies View Related

SQL & PL/SQL :: Finding MAX And MIN Value From Varchar Datatype Field

Mar 13, 2013

How to get max and min value from a varchar2 datatype column?

CREATE TABLE TEST
(
WEIGHT VARCHAR2(20)
);
INSERT INTO TEST VALUES('100');
INSERT INTO TEST VALUES('120');
INSERT INTO TEST VALUES('113');
INSERT INTO TEST VALUES('145');
INSERT INTO TEST VALUES('204');
INSERT INTO TEST VALUES('130');

I've to find the max and min weight from this data.

View 2 Replies View Related

SQL & PL/SQL :: Varchar 2 Interact Server With Client

Nov 14, 2011

We have server oracle 11 , running on UNIX . we have table with a lot of columns - varchar2(4000)

My question

when data comes from server to client? what actually comes for column varchar2(4000) ?

for example value of columns 'abc'

does it mean that from server to client will be sent buffer with size 3 char ?

or

it will be sent buffer 4000 characters and one more value shows how big is variable inside buffer ( for this case it will be 3 )

View 5 Replies View Related

SQL & PL/SQL :: Split Varchar Field Into 2 Fields?

Mar 22, 2010

I need to separate 1 field into 2 fields. The source is varchar2 and is like:

[VOUCHER]
CGJ0000617
CG0001442
CGJ0001444
CMOV0000200
CXAR00000001
CXAR00000002

Result should seperate numeric value from characters so that the result would be:

[VOUCHER_char] [VOUCHER_num]
CGJ 0000617
CG 0001442
CGJ 0001444
CMOV 0000200
CXAR 00000001
CXAR 00000002

I need one or two SQL statement.

View 9 Replies View Related

SQL & PL/SQL :: Converting Varchar To Clob Within SQL Union?

Feb 14, 2013

Why does oracle not allow the following query

select to_clob(1) from dual
union
select wm_concat(sysdate) from dual;

wm_concat returns a clob. To make both queries in the union have the same type columns i convert the column in the first query to a clob but Oracle gives me an [1]: ORA-00932: inconsistent datatypes: expected - got CLOB error even though both are returning a clob value.

Each of the queries work individually and both return a clob value.

View 4 Replies View Related

Copy Data From One Field (varchar) To Another Within A Table

Oct 5, 2010

i have a table COLOR having alphanumeric fields i.e Color Description & Color Ref. i want to copy the values from Color Description to Color Ref.

what will the select statement for this?

View 9 Replies View Related

Built-in Function To Covert CURSOR To VARCHAR?

Feb 13, 2007

know if there's a built-in function to covert an Oracle CURSOR to VARCHAR? Or how about a XMLType to VARCHAR?

View 1 Replies View Related

SQL & PL/SQL :: Get Numeric Values From A Column Of Varchar Data?

Aug 16, 2013

I have a table and data like mentioned below.

create table emp( ename varchar2(20));
insert into emp values ('122');
insert into emp values ('abc');
insert into emp values ('0.2');
insert into emp values ('0-5');
insert into emp values ('25-30');

SQL> Select * from emp;
| ENAME |
-------------------
| 122 |
| abc |
| 0.2 |
| 0-5 |
| 25-30 |

I am running the code

SQL>select regexp_substr(ename , '^[[:digit:]]+.[[:digit:]]+$|^[[:digit:]]+$')
from emp;

AFTER RUNNING I AM GETTING THIS

| REGEXP_SUBSTR(ENAME,'^[[:DIGIT:]]+.[[:DIGIT:]]+$|^[[:DIGIT:]]+$') |
---------------------------------------------------------------------
| 122 |
| (null) |
| 0.2 |
| 0-5 |
| 25-30 |
| (null) |

Why it's not excluding '0-5' and '25-30', how I should write code to exclude this and Is there is any function in oracle to check for numeric in column and print.

View 4 Replies View Related

SQL & PL/SQL :: Select Numeric Values From A Varchar Column

Feb 5, 2011

select numeric values from a varchar column

For Example:

select * from t1 ;

ID
----------
00300
ABCXY
04230
xyzab

i need to fetch only numeric values from column id

My output should be

00300
04230

View 8 Replies View Related

SQL & PL/SQL :: Converting BLOB Data To Long Or Varchar

Feb 6, 2013

converting BLOB data into varchar2 or long .

we have function which convert long data and return it has varchar . But has part of Apps upgrade the Column has been converted into blob column.

How we need the same function to read the data from BLOB and return its as long or varchar2.

Somewhere i am making mistake..

CREATE OR REPLACE function GDS.test_alert_msg(v_rowid rowid) return varchar2 is

vblob blob;
i2 number;
amt number :=32767;
len number;
pos raw(32767);
position INTEGER := 10000;
my_vr raw(32767);

[Code]....

View 2 Replies View Related

SQL & PL/SQL :: Convert Clob To Varchar Data Type

Aug 16, 2012

I want to convert a clob datatype to varchar data type.I have a clob data type in the below format.

-----------------------------------------------------------------------------------------
<HTML><HEAD><TITLE>Tata Communications Limited</TITLE><BODY leftMargin=20 topMargin=10 rightMargin=20 marginheight=10 marginwidth=10><Table border="0" cellpadding="0" cellspacing="0"
-----------------------------------------------------

I want to insert all the values into varchar datatype.provide the sample code how to convert.

View 1 Replies View Related

PL/SQL :: How To Store Statement In Varchar And Call EXEC

Jun 11, 2012

So this statement works:

SELECT column_name BULK COLLECT INTO table_column_list FROM all_tab_columns WHERE table_name = conv_tablename AND OWNER IN (SELECT USER FROM DUAL);

However I want to add conditions like " AND column_name <> 'abc' " at the end. So i tried to store this in a varchar and call EXEC on it:

select_column_value_sql_stmt := 'SELECT column_name BULK COLLECT INTO table_column_list FROM user_tab_columns WHERE table_name = '''|| conv_tablename || '''' || inexclude_column;
EXECUTE IMMEDIATE select_column_value_sql_stmt;     

No matter how I concatenate the conv_tablename part, i get an error. either invalid identifier or unimplemented feature.

so is there a way to do this at all?

View 3 Replies View Related

Convert Existing Table With Varchar Column To A Clob?

May 8, 2013

how to convert existing table with varchar column to a clob

View 1 Replies View Related

SQL & PL/SQL :: Time Calculation - Make Varchar To Timestamps But Caught With Round Up / Down?

Apr 12, 2011

calculating values of A & B

(both these fields a_std and a_time are coming as varchar from the parent table in a cursor.(basically they are time period and actual arrival time respectively)

i was juggling with the attempt to make varchar to timestamp or date..but caught with Round up /Round down)

Formula ->

A = Round down [A_TIME - A_STD]
B = Round up [A_TIME) - 10 minute + A_STD]

where

A_TIME VARCHAR2(8) N Time (Format" HH:MM AM/PM") eg "3:50 PM"
A_STD VARCHAR2(5) N Standard time (Format" HH:MM") eg "1:00"

Allowed values for A & B after round up/down = multiple of 10 ( 11:00,11:10,11:20 etc.)

View 10 Replies View Related

Precompilers, OCI & OCCI :: Data Lost After Adding Null Terminator For VARCHAR Data Received From Database

Dec 13, 2010

We are migrating a proc application as described below.

Old Env: UNIX
Old DB: Oracle 8i

New Env: Linux
New DB: Oracle 11g

New modules are successfully compiled in Linux environment. But we are facing issues in writing the output of VARCHAR datatype to a file.

find below the extract of code.
EXEC SQL BEGIN DECLARE SECTION;
varchar mcolmnvarchar[4];
EXEC SQL END DECLARE SECTION;

EXEC SQL DECLARE crs CURSOR FOR
SELECT NVL(colmn,' ') FROM table1

memset(mcolmnvarchar.arr,'�',4); //Was added for only Linux migration. Not present in unix env.

EXEC SQL FETCH c1 INTO :mcolmnvarchar;

cout << "Data at Stage one"<< mcolmnvarchar << endl;
mcolmnvarchar.arr[mcolmnvarchar.len]='�';
cout << "Data at Stage two"<< mcolmnvarchar << endl;
fprintf(fptr,"%-4s",mcolmnvarchar.arr);

Above code works absolutely fine in Unix env with Oracle 8i. But with Linux env & Oracle 11g it is not working. No compilation or run time errors. Data at Stage one prints the output of database properly. But after null terminator code, Data at Stage two statement prints without any value. Value is lost after null terminator code.

View 7 Replies View Related

Reports & Discoverer :: How To Find Page Number And Total Number Of Pages

Jan 26, 2010

i am using oracle developer 6i report builder i required this type of query

example

if (:page number LIKE '1')
then
srw.set_text_color('darkred');
end if;

return (TRUE);
end;

but page number is not my table database item how can i use builtan page &<pagenumber> use for conditional format.

View 34 Replies View Related

SQL & PL/SQL :: Replacing 4 Digit Number In A Given String With The Same Number Incremented By 10000?

Jun 17, 2010

i want to replace 4 digit number in a given string with the same number incremented by 10000.

That mean in the given sting 1201 should be replace by 11201 (Icremented BY 10000).

Input String:

<query><matchAll>true</matchAll><row><columnId>1201</columnId><dataType>31</dataType><op>Like</op><val>North America - Houston</val></row><row><columnId>1212</columnId><dataType>31</dataType><op>!=</op><val>Agreement Date Mismatch</val></row><row><columnId>1212</columnId><dataType>31</dataType><op>!=</op><val>Facility Type Mismatch</val></row><row><columnId>1224</columnId><dataType>31</dataType><op>Like</op><val>y</val></row></query>

Required output :

<query><matchAll>true</matchAll><row><columnId>11201</columnId><dataType>31</dataType><op>Like</op><val>North America - Houston</val></row><row><columnId>11212</columnId><dataType>31</dataType><op>!=</op><val>Agreement Date Mismatch</val></row><row><columnId>11212</columnId><dataType>31</dataType><op>!=</op><val>Facility Type Mismatch</val></row><row><columnId>11224</columnId><dataType>31</dataType><op>Like</op><val>y</val></row></query>

View 7 Replies View Related

SQL & PL/SQL :: Extract Number And Previous Character From Where 5 Digit Number Starting

Oct 21, 2011

I have a text field and if the text field has 5 consecutive numbers then I have to extract the number and the previous character from where the 5digit number starting

For example i/p asdfasfsdS251432dasdasd o/p should be S251432

View 10 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved