VARCHAR2 to the number
How to change the type of data of a varchar2 number pass? the pass is not emptyAssuming that the name of the column to change data type is orig_col follow the procedure below:
Add a new column to the table to say TEMP_COL with data like the NUMBER type
ALTER TABLE table_name ADD ( TEMP_COL NUMBER);
Update of the new column with the values of ORIG_COL
UPDATE table_name
SET TEMP_COL = TO_NUMBER(ORIG_COL);
Delete the original column
ALTER TABLE table_name DROP ( ORIG_COL );
Rename the TEMP_COL to ORIG_COL
ALTER TABLE table_name RENAME TEMP_COL TO ORIG_COL;
Create all indexed/constraints that were present on ORIG_COL
Concerning
Arun
Published by: Arun Kumar Gupta on May 23, 2011 10:04
Tags: Database
Similar Questions
-
Varchar2 to the number conversion problem
I have some difficulty conversion strings to numbers. On my Oracle 9.2 server, it gives me an error ORA-1722:
SELECT TO_NUMBER ('1.2') OF DOUBLE
Apparently, this is because my server is configured to use the Greek number format (comma instead of decimal point) and substitute "1.2' above with '1.2' will work correctly."
Is it possible for me to convert strings with decimal number type, independent of the culture so that my application will not have to depends on the locale setting of the server?
Thank you.Hello
Welcome to the forum!
If you don't want to change the NLS settings for your session, you can specify what settings to use for a particular call to TO_NUMBER (and other features), like this:
ALTER SESSION SET NLS_TERRITORY = GREECE; SELECT TO_NUMBER ('1.2') AS wont_work FROM dual; SELECT TO_NUMBER ( '1.2' , '999999999.999999' , 'NLS_NUMERIC_CHARACTERS = '',.''' ) AS n FROM dual;
The output below shows the TO_NUMBER 1-argument fails, but the 3-argument TO_NUMBER works:
Session altered. SELECT TO_NUMBER ('1.2') AS wont_work * ERROR at line 1: ORA-01722: invalid number N ---------- 1,2
The actual format of the string (the first argument) should not match precisely the format mask (the second argument). You can include signs, or omit the decimal points, so '3', ' '-1,2. '-3', ' + 1.2 ' and ' + 3' will be all converted correctly.»»» "
-
How to count the number of updates in a loop Forall
Hi friends
I want to know is - it possible to count the number of updates occurred in FORALL. I share the codes below. His only return the iteration number. If I spend 5 through the values of the PARAMETERS and 2 updates the values in the table then return 5 instead of 2. My requirement is to count the number of updates have taken place and return this value to OUTPUT parameter. If possible, please share codes. Thank you very much...
CREATE OR REPLACE PROCEDURE UPDATE_PROCESS_RATE ( V_HOSPITAL_ID IN HOSPITAL_SERVICE_MASTER.HOSPITAL_ID%TYPE, V_USER IN VARCHAR2, V_DATE IN DATE, V_PROCESS_ID IN VARR_ARRAY, V_PROCESS_RATE IN NUM_ARRAY, V_NUM OUT NUMBER ) IS V_ERROR_CODE NUMBER(15); V_ERROR_MSG VARCHAR2(200); V_ARRAY_ID NUMBER(10,2); V_TOTAL NUMBER:=0; BEGIN SAVEPOINT Sp1; BEGIN FORALL i IN V_PROCESS_RATE.FIRST..V_PROCESS_RATE.LAST UPDATE HOSPITAL_SUBSERVICE_PROCESS M SET M.PROCESS_CHARGE=V_PROCESS_RATE(i) WHERE M.HOSPITAL_ID=V_HOSPITAL_ID AND M.HOSPITAL_PROCESS_ID =V_PROCESS_ID(i); FOR i IN V_PROCESS_RATE.FIRST..V_PROCESS_RATE.LAST LOOP V_TOTAL:=V_TOTAL + SQL%BULK_ROWCOUNT(i); End loop; COMMIT; V_NUM:=V_TOTAL;
IndiMinds wrote:
But my requirement is: it must count the update only when it detects a different value from array. When it detects a different value in the table must be updated and count it and if the update of the table value is similar the TI should not count it.
For example, if the V_PROCESS_RATE table have these 3 values (10,20,30) and we need to update these 3 values with (10,40,50), so no update, it should return is 2 not 3.
Thank you
And then don't update these lines, change your update statement
UPDATE HOSPITAL_SUBSERVICE_PROCESS M SET M.PROCESS_CHARGE=V_PROCESS_RATE(i) WHERE M.HOSPITAL_ID=V_HOSPITAL_ID AND M.HOSPITAL_PROCESS_ID =V_PROCESS_ID(i) AND DECODE(M.PROCESS_CHARGE,V_PROCESS_RATE(i),0,1) = 1;
-
get the number in the declaration of DBMS
Hello everyone,
my friend, I create the following code, but I've always faced a problem to display the result of County all the
the code is:
------------------------------
I insert a count (*) to get the number of employees
but he keep get only '1' to the last of the result in the following way:
DETAILS OF THE EMPLOYEE:
YJOSEPH5 | YOUSEFJOSEPH | 15 NOVEMBER 15
HYOUSEF10 | HASSANYOUSEF | 15 NOVEMBER 15
HYOUSEF17 | HASSANYOUSEF | 15 NOVEMBER 15
HYOUSEF14 | HASSANYOUSEF | 15 NOVEMBER 15
HYOUSEF16 | HASSANYOUSEF | 15 NOVEMBER 15
COUNT: 1
the code
------------------------------------
DECLARE
V_USER_ID VARCHAR2 (50);
NUMBER OF V_EMP_NO;
V_FIRST_NAME VARCHAR2 (30);
V_LAST_NAME VARCHAR2 (30);
DATE OF V_REG_DATE;
NUMBER OF V_COUNT;
V_SQL_SATEMENTS VARCHAR2 (1000);
NCOUNT THE NUMBER;
CURSOR C IS SELECT USER_ID, EMP_NO, FIRST_NAME, LAST_NAME, REG_DATE, COUNT (*) FROM EMP
USER_ID, FIRST_NAME, LAST_NAME, EMP_NO, REG_DATE GROUP;
BEGIN
OPEN C;
SELECT COUNT (*) FROM NCOUNT FROM USER_TABLES WHERE TABLE_NAME = 'EMP ';
IF (NCOUNT < = 0) THEN
V_SQL_SATEMENTS: =' CREATE TABLE EMP)
USER_ID VARCHAR2 (40) PRIMARY KEY,.
NUMBER OF EMP_NO,
FIRST NAME VARCHAR2 (30),
VARCHAR2 (30) LAST_NAME,.
DATE OF REG_DATE)';
RUN IMMEDIATELY "DROP TABLE EMP;
IMMEDIATELY RUN V_SQL_SATEMENTS;
END IF;SELECT NVL (MAX (EMP_NO), 0) + 1
IN V_EMP_NO
YOUSEF. EMP;
INSERT YOUSEF. EMP (USER_ID, EMP_NO, FIRST_NAME, LAST_NAME, REG_DATE)
VALUES (SUBSTR (: LAST NAME, 1, 1) |: LAST_NAME |) V_EMP_NO, V_EMP_NO,:FIRST_NAME,:LAST_NAME,TO_DATE(SYSDATE,'DD-MON-YY'));
DBMS_OUTPUT. PUT_LINE (' DETAILS OF THE EMPLOYEE: "");
LOOP
EXTRACT THE C IN V_USER_ID, V_EMP_NO, V_FIRST_NAME, V_LAST_NAME, V_REG_DATE, V_COUNT;
WHEN THE EXIT %C NOTFOUND;DBMS_OUTPUT. PUT_LINE (V_USER_ID |'|) ' || V_FIRST_NAME | V_LAST_NAME |' | ' || V_REG_DATE);
END LOOP;
DBMS_OUTPUT. PUT_LINE ("COUNT:" | "|") V_COUNT);CLOSE C;
END;
/ALL FRIENDS,
THANKS FOR EVERY BODY,
I JUST FOUND THE RIGHT WAY TO DO
FOR THOSE WHO WANT TO SEE:
-----------------------------------------------------------
DECLARE
V_USER_ID VARCHAR2 (50);
NUMBER OF V_EMP_NO;
V_FIRST_NAME VARCHAR2 (30);
V_LAST_NAME VARCHAR2 (30);
DATE OF V_REG_DATE;
NUMBER OF V_COUNT;
V_SQL_SATEMENTS VARCHAR2 (1000);
NCOUNT THE NUMBER;
CURSOR C IS SELECT USER_ID, FIRST_NAME, LAST_NAME, EMP_NO FROM EMP REG_DATE;
BEGIN
SELECT COUNT (*) IN THE EMP V_COUNT;
OPEN C;
SELECT COUNT (*) FROM NCOUNT FROM USER_TABLES WHERE TABLE_NAME = 'EMP ';
IF (NCOUNT<=0)>=0)>
V_SQL_SATEMENTS: =' CREATE TABLE EMP)
USER_ID VARCHAR2 (40) PRIMARY KEY,.
NUMBER OF EMP_NO,
FIRST NAME VARCHAR2 (30),
VARCHAR2 (30) LAST_NAME,.
DATE OF REG_DATE)';
RUN IMMEDIATELY "DROP TABLE EMP;
IMMEDIATELY RUN V_SQL_SATEMENTS;
END IF;SELECT NVL (MAX (EMP_NO), 0) + 1
IN V_EMP_NO
YOUSEF. EMP;
INSERT YOUSEF. EMP (USER_ID, EMP_NO, FIRST_NAME, LAST_NAME, REG_DATE)
VALUES (SUBSTR (: LAST NAME, 1, 1) |: LAST_NAME |) V_EMP_NO, V_EMP_NO,:FIRST_NAME,:LAST_NAME,TO_DATE(SYSDATE,'DD-MON-YY'));
DBMS_OUTPUT. PUT_LINE (' DETAILS OF THE EMPLOYEE: "");
LOOP
EXTRACT THE C IN V_USER_ID, V_EMP_NO, V_FIRST_NAME, V_LAST_NAME, V_REG_DATE;
WHEN THE EXIT %C NOTFOUND;DBMS_OUTPUT. PUT_LINE (V_USER_ID |'|) ' || V_FIRST_NAME | V_LAST_NAME |' | ' || V_REG_DATE);
END LOOP;
CLOSE C;
DBMS_OUTPUT. PUT_LINE ("COUNT:" | "|") V_COUNT);END;
/ -
How can I know the number of columns in a TYPE?
Hello
If we have a guy like below
type vc_arr2 is table of the varchar2 (32767) index directory.
How can I get the number of columns?
Minoo.TK wrote:
Hello
If we have a guy like below
type vc_arr2 is table of the varchar2 (32767) index directory.
How can I get the number of columns?
It is a type of associative array definition. A table has no columns. It is a collection of elements (variables or values). An array location is usually called a cell.
The standard method Count() exist in Oracle for all table types.
As for the definition of the table, as in structures, variables make the table contain - associative array is defined in the PL/SQL code and does not exist in the layer of metadata to the database as a new user-defined type. For the definition, you must read the declaration of PL/SQL defining the table.
Note that there is very rarely the need for associative tables in PL/SQL - 99% of the time they are used without any idea as to what as a table associative is also.
-
Hello Experts,
I have a problem that is a little tricky. Requirement is if 2 columns (region and Code in the tables below) match exactly, then it is Best Fit, if one of the columns match while it is average in shape, if the two columns do not match then it's worse to adapt.
Create Table Table1 (varchar2 (10), varchar2 (10) of the filter region, Code varchar2 (10), revenue Number (15), owner varchar2 (5));
Table1:
Insert into Table1 values ('Test1', 'Midwest', '0900', 3000286, 'P1')
Insert into Table1 values ('Test1', 'Midwest', '0899', 36472323, 'P2')
Insert into Table1 values ('Test1', 'Midwest', '0898', 22472742, "P3")
Insert into Table1 values ('Test1', 'West', '0901', 375237423, 'P1')
Insert into Table1 values ('Test1', 'West', '0700', 34737523, null)
Insert into Table1 values ('Test1', 'West', '0701', 95862077, "P3")
Insert into Table1 values ('Test1', 'South', '0703', 73438953, 'P4')
Insert into Table1 values ('Test1', 'South', '0704', 87332089, 'P1')
Insert into Table1 values ('Test1', 'South', '0705', 98735162, 'P4')
Insert into Table1 values ('Test1', 'South', '0706', 173894762, "P9")
Insert into Table1 values ('Test1', 'South', '0902', 72642511, 'P6')
Create Table Table2 (filter varchar2 (10), region varchar2 (10), Code varchar2 (10), plafond1 Number (15), Limit2 Number (15));
Table2
Insert into Table2 Values ('Test1', 'ALL', ' 0902', 15000, 10000)
Insert into Table2 Values ('Test1', 'ALL', 'ALL', 20000, 12000)
Insert into Table2 Values ('Test1', 'Midwest' ' 0900', 10000, 5000)
Insert into Table2 Values ('Test1', 'Midwest', 'ALL', 18000, 8000)
Insert into Table2 Values ('Test1', 'West', 'ALL', 16000, 6000)
Insert into Table2 Values ('Test1', 'West', '0901', 10000, 5000)
Final output
Filter the income Code region owner plafond1 Limit2
Test1 0900 3000286 P1 10 000 5 000 - Best Midwest (region because both Code Matches)
Test1 0899 36472323 P2 Midwest 18 000 8 000 - way (because the region corresponds to only), we consider 'ALL' for the Code
Test1 0898 22472742 P3 Midwest 18 000 8 000 - way (because the region corresponds to only), we consider 'ALL' for the Code
Test1 West 0901 375237423 10 000 5 000 - Best P1 (region because both Code Matches)
Test1 West 0700 34737523 16 000 6 000 - medium (because the area corresponds to only), we consider 'ALL' for the Code
Test1 West 0701 95862077 P3 16 000 6 000 - way (because the region corresponds to only), we consider 'ALL' for the Code
Test1 South 0703 73438953 P4 20 000 12 000 - worse (because region both Code DON T Match ' "), we consider option as worst 'ALL', 'ALL '.
Test1 South 0704 87332089 P1 20 000 12 000 - worse (because region both Code DON T Match ' "), we consider option as worst 'ALL', 'ALL '.
Test1 South 0705 98735162 P4 20 000 12 000 - worse (because region both Code DON T Match ' "), we consider option as worst 'ALL', 'ALL '.
Test1 South 0706 173894762 P9 20 000 12 000 - worse (because region both Code DON T Match ' "), we consider option as worst 'ALL', 'ALL '.
Test1 South 0902 72642511 P6 15 000 10 000 - way (because the Code corresponds to only) we consider 'ALL' for the region
In the final result, we should have row count equal to Table1, and as soon as there's game (best first, then middle, then the worst), then if is once again, that we should ignore.
There are other columns in the tables as well.
Thank you very much!
As you wish...
select filter, region, code, region2, code2, revenue, owner, limit1, limit2, match from ( select filter, region, code, region2, code2, revenue, owner, limit1, limit2, match, row_number() over( partition by filter, region, code order by match ) priority from ( select a.filter, a.region, a.code, a.revenue, a.owner, b.region region2, b.code code2, b.limit1, b.limit2, case when (a.region, a.code) = ((b.region, b.code)) then 'Best' when a.region = b.region or a.code = b.code then 'Medium' else 'Worst' end match from table1 a join table2 b on a.filter = b.filter and (b.region, b.code) in ( (a.region, a.code), (a.region, 'ALL'), ('ALL', a.code), ('ALL', 'ALL') ) ) ) where priority = 1 order by region, code;
-
Count of the number of months with unpaid for the last six months
Hello
I now table to store the daily presence of each employee
ATTENDANCESHEET
EMPID
PAYROLLDATE
UNPAID
1
10/01/2013
6
1
10/02/2013
2
1
11/01/2013
0
1
11/02/2013
0
1
12/01/2013
0
1
12/02/2013
0
1
01/01/2014
0
1
01/02/2014
0
1
02/01/2014
0
1
02/02/2014
0
1
03/01/2014
45
1
03/02/2014
0
2
03/01/2014
0
2
03/02/2014
0
I want to get the number of months used unpaid in the past 6 months (excluding the current).
If the month of payroll, I'm in treatment is 4, 2014, I spend 4 as payrollmonth and 2014 as payroll year
The application must check the latest 6 month data and number of months for which there is any unpaid value
In the case above for month 4, 2014, the power required is
EmpID
County
1
2
2
0
I use oracle 10g
EXAMPLES OF DATA
create the table attendancesheet as
(
Select 1 as empid, to_date (January 10, 2013 ',' DD/MM/YYYY ') as payrolldate, 6 paid by union double all the
Select 1 as empid, to_date (10 February 2013 ',' DD/MM/YYYY ') as payrolldate, 0 paid by union double all the
Select 1 as empid, to_date (January 11, 2013 ',' DD/MM/YYYY ') as payrolldate, 0 paid by union double all the
Select 1 as empid, to_date (February 11, 2013 ',' DD/MM/YYYY ') as payrolldate, 0 paid by union double all the
Select 1 as empid, to_date (12 January 2013 ',' DD/MM/YYYY ') as payrolldate, 0 paid by union double all the
Select 1 as empid, to_date (February 12, 2013 ',' DD/MM/YYYY ') as payrolldate, 0 paid by union double all the
Select 1 as empid, to_date (1 January 2014 ',' DD/MM/YYYY ') as payrolldate, 0 paid by union double all the
Select 1 as empid, to_date (February 1, 2014 ',' DD/MM/YYYY ') as payrolldate, 0 paid by union double all the
Select 1 as empid, to_date (January 2, 2014 ',' DD/MM/YYYY ') as payrolldate, 0 paid by union double all the
Select 1 as empid, to_date (February 2, 2014 ',' DD/MM/YYYY ') as payrolldate, 0 paid by union double all the
Select 1 as empid, to_date (3 January 2014 ',' DD/MM/YYYY ') as payrolldate, 45 paid by union double all the
Select 1 as empid, to_date (3 February 2014 ',' DD/MM/YYYY ') as payrolldate, 0 paid by union double all the
Select 2 as empid, to_date (3 January 2014 ',' DD/MM/YYYY ') as payrolldate, 0 as default all the double union
Select 2 as empid, to_date (3 February 2014 ',' DD/MM/YYYY ') as payrolldate, 0 paid double
);
Help, please
Hello
So, you want to count the distinct months for 6 months before (not included) the given month; is this fair?
Here's one way:
VARIABLE month VARCHAR2 (2)
Year VARIABLE VARCHAR2 (4)
EXEC: months: = '4';
EXEC: year: "2014"; =
WITH got_end_date AS
(
SELECT TO_DATE (: month |) '/' || : year
, ' MM/YYYY ".
) AS end_date
OF the double
)
SELECT a.empid
, COUNT (DISTINCT
CASE
WHEN a.unpaid > 0
THEN TRUNC (a.payrolldate, 'MONTH')
END
), Cnt
Of attendancesheet one
JOIN e-got_end_date WE a.payrolldate > = ADD_MONTHS (e.end_date-6)
AND a.payrolldate< > >
GROUP BY a.empid
ORDER BY a.empid
;
If you use a WHERE clause to exclude the lines with some outstanding = 0 (or unpaid is NULL), then you would get no output for employees like empid = 2 in this example. A WHERE clause ignores an entire line, so I used an expression BOX just a value.
-
change the column size for the number
Hello
I created a table with a primary key declared under the (default specification) NUMBER column.
Create table T
(
Number of key primary col1,.
col2 varchar2 (10)
);
Then, I filled this table using the sequence. Now, I want to change the size of the primary key to the number (15) column.
Is this possible without emptying the primary key column?
You can't reduce the length of a column that has already given. But you can work around it like that.
SQL> create table t 2 ( 3 col1 number primary key, 4 col2 varchar2(10) 5 ); Table created. SQL> insert into t 2 select level, 'a' 3 from dual 4 connect by level <= 10; 10 rows created. SQL> desc t Name Null? Type -------------- -------- ------------------------------ COL1 NOT NULL NUMBER COL2 VARCHAR2(10) SQL> select * from t; COL1 COL2---------- ---------- 1 a 2 a 3 a 4 a 5 a 6 a 7 a 8 a 9 a 10 a 10 rows selected. SQL> alter table t modify col1 number(15);alter table t modify col1 number(15) *ERROR at line 1:ORA-01440: column to be modified must be empty to decrease precision or scale SQL> alter table t add col_temp number(15); Table altered. SQL> update t set col_temp = col1; 10 rows updated. SQL> commit; Commit complete. SQL> alter table t drop column col1; Table altered. SQL> alter table t rename column col_temp to col1; Table altered. SQL> alter table t add constraint t_pk primary key (col1); Table altered. SQL> desc t Name Null? Type --------------- -------- ------------------------------ COL2 VARCHAR2(10) COL1 NOT NULL NUMBER(15) SQL> select * from t; COL2 COL1---------- ----------a 1a 2a 3a 4a 5a 6a 7a 8a 9a 10 10 rows selected. SQL>
-
Get the number of items in a collection
I have an associative array that is indexed by VARCHAR2. I want to know the number of items in the collection that have value of index like '% IMSI_ '. Is there a direct way to achieve this, or I have to loop through the collection and get the number in a variable. I use 11g.
The Count() method gives the total number of elements in the array (including null values).
If you want to count how many names or values correspond to a filter predicate, you must do it manually.
-
Change the number to varchar DataType
Hello
I need to change the data type for a column (from the number on the varchar type), it is an existing table so data are there.
I'm runnning modify the command to do it, but he asked me to do all null values before treatment.
Is it possible to do without any null values.
In my view, a solution is
(1) to get the data copied to another table, make the NULL column and change... load the data back at the table
It is the only option?
Hello
First of all, make sure that you really want to lose the NUMBER column. Why you change the column? "" For example, if the column is temperature, and you change it so that you can enter values like ' 68 F ' or ' 20 C ', then perhaps you should allow the temperature of the column as a NUMBER and add a new column, temperature_scale VARCHAR2 (1). (Better yet, convert all temperatures to a comments system, possibly with a trigger or a virtual column and save the original measurment, like ' 68 F"in a separate column, if you really need to know how it was entered.)
Because you really need to change to a VARCHAR2 column, then one of the ways is
(1) adds a new column VARCHAR2
(2) fill in this column of the existing NUMBER column
(3) add a NOT NULL constraint in the new column (if necessary)
(4) delete the original column NUMBER
(5) change the name of the new column to the original column was (if desired)
If you deposit the entire table, then you lose all its indexes, triggers and subsidies. If you come to add and remove columns, you do not lose these things.
-
How to count the number or lines in the file
Hi Experts,
I'm file as source and Oracle as target. My folder that contains some data that will load the target.
My requirement is that I want to count the number of lines that contains my folder. Please help me how to count the total number of lines in the file.
THX,
Sara.Hi Sahaveda,
Now, I tried and it works.
Sorry my mistake again.
I created HR. ETL_FILE_LOG as below:
CREATE THE TABLE HR. ETL_FILE_LOG (numero_fichier varchar2 (10))
Below the code will run without error:
import java.lang as lang
import java.sql SQL
import of java.lang.String
Import os
disadvantages is sql. DriverManager.getConnection ("<%=snpRef.getInfo("DEST_JAVA_URL")%>", "<%=snpRef.getInfo("DEST_USER_NAME")%>", "<%=snpRef.getInfo("DEST_PASS")%>")
dblinks = cons.createStatement)
File1 = Open ('c:\EMP.txt','r')
Count = 0
Line = file1. ReadLine()
all online! ='' :
Count += 1
Line = file1. ReadLine()
File1. Close()
sqlQuery = "insert into HR. "The values of ETL_FILE_LOG (numero_fichier) (" + str (count) + ' ") '.
rqQuery = dblinks.execute (sqlQuery)
jerks. Close()
Concerning
-
How to update the table with the number management
Hello
I need as there is a loc_tab of the created table as below,
CREATE TABLE loc_tab
(
Country_ID NUMBER,
country_code VARCHAR2 (3),
country_name VARCHAR2 (50).
State_ID NUMBER,
state_code VARCHAR2 (3),
state_name VARCHAR2 (50).
city_id NUMBER,
city_code VARCHAR2 (3),
city_name VARCHAR2 (50)
);
I inserted records like below,
Now, I wanted to update the table such that all ID columns are updated with running number.COUNTRY_ID COUNTRY_CODE COUNTRY_NAME STATE_ID STATE_CODE STATE_NAME CITY_ID CITY_CODE CITY_NAME IND INDIA TN TAMIL NADU CHN CHENNAI IND INDIA TN TAMIL NADU TRI TRICHY IND INDIA TN TAMIL NADU CMT COIMBATORE IND INDIA TN TAMIL NADU MDU MADURAI IND INDIA AP ANDHRA PRADESH HYD HYDERABAD IND INDIA AP ANDHRA PRADESH SEC SECUNDRABAD AUS AUSTRALIA QLD QUEENSLAND BRI BRISBANE AUS AUSTRALIA TAS TASMANIA HB HOBART AUS AUSTRALIA TAS TASMANIA CCE CITY OF CLEARANCE AUS AUSTRALIA TAS TASMANIA BUR BURNIE
Each ID columns should get incremented so that, for Country_ID column corresponding to "India" If country_id is 1, that there must be one for all the lines with the name as "India". Likewise for "Australia".
In the case of State, she also has the same logic with numbers repeated until the very name of the State comes.
For the city, it of course will hold separate ID only because the name of the city will not get duplicated.
This update must be done in the normal way using simple SQL such as no PLSQL don't like looping, etc... is involved.
Here are the contents of the table, and that's how the table should be updated,
Thank you and best regards,COUNTRY_ID COUNTRY_CODE COUNTRY_NAME STATE_ID STATE_CODE STATE_NAME CITY_ID CITY_CODE CITY_NAME 1 IND INDIA 1 TN TAMIL NADU 1 CHN CHENNAI 1 IND INDIA 1 TN TAMIL NADU 2 TRI TRICHY 1 IND INDIA 1 TN TAMIL NADU 3 CMT COIMBATORE 1 IND INDIA 1 TN TAMIL NADU 4 MDU MADURAI 1 IND INDIA 2 AP ANDHRA PRADESH 1 HYD HYDERABAD 1 IND INDIA 2 AP ANDHRA PRADESH 2 SEC SECUNDRABAD 2 AUS AUSTRALIA 1 QLD QUEENSLAND 1 BRI BRISBANE 2 AUS AUSTRALIA 2 TAS TASMANIA 1 HB HOBART 2 AUS AUSTRALIA 2 TAS TASMANIA 2 CCE CITY OF CLEARANCE 2 AUS AUSTRALIA 2 TAS TASMANIA 3 BUR BURNIE
Shiva
-
Application of Pivot Oracle regardless of the number of columns
Hi, I have a requirement to create a view by turning all the related records primary record, regardless of the number of records, but... the LEVELID marked as primary should be the first column from left to right. The order of the columns from left to right after that are not important.
There may be up to 18 CODES associated with a time-TRIAL, but the amount is variable.
Thank you for your time.
I need the following:create table id_levels (clm varchar2(12), code varchar2 (12), levelid varchar2 (12)); insert into id_levels select '1','15','Primary' from dual; insert into id_levels select '1','42','Secondary' from dual; insert into id_levels select '1','44','Third' from dual; insert into id_levels select '1','41','Secondary' from dual; insert into id_levels select '2','3','Primary' from dual; insert into id_levels select '2','4','Secondary' from dual; insert into id_levels select '3','24','Primary' from dual; insert into id_levels select '3','15','Secondary' from dual; insert into id_levels select '3','15','Secondary' from dual; insert into id_levels select '3','16','Third' from dual; insert into id_levels select '4','12','Primary' from dual; insert into id_levels select '4','67','Third' from dual; insert into id_levels select '5','13','Primary' from dual; insert into id_levels select '5','24','Secondary' from dual; insert into id_levels select '5','22','Secondary' from dual;
CLM | Code1. Code2. code 3 | code 4 | job.5 | Code6 | Code7. SH8 | Code9 | CODE.10
1. 15. 42. 44. 41
2. 3. 4
3. 24. 15. 15. 16
4. 12. 67.
5. 13. 24. 22There may be up to 18 CODES associated with a time-TRIAL, but the amount is variable.
Thus, when 18 codes can be considered fixed, then you can:
SQL> select * from v$version where rownum=1; BANNER -------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production 1 row selected. SQL> select clm 2 , max(case when rn = 1 then cd end) code1 3 , max(case when rn = 2 then cd end) code2 4 , max(case when rn = 3 then cd end) code3 5 , max(case when rn = 4 then cd end) code4 6 , max(case when rn = 5 then cd end) code5 7 , max(case when rn = 6 then cd end) code6 8 , max(case when rn = 7 then cd end) code7 9 , max(case when rn = 8 then cd end) code8 10 , max(case when rn = 9 then cd end) code9 11 , max(case when rn = 10 then cd end) code10 12 , max(case when rn = 11 then cd end) code11 13 , max(case when rn = 12 then cd end) code12 14 , max(case when rn = 13 then cd end) code13 15 , max(case when rn = 14 then cd end) code14 16 , max(case when rn = 15 then cd end) code15 17 , max(case when rn = 16 then cd end) code16 18 , max(case when rn = 17 then cd end) code17 19 , max(case when rn = 18 then cd end) code18 20 from ( 21 select t.clm 22 , t.code cd 23 , t.levelid 24 , row_number() over (partition by clm order by case when levelid = 'Primary' then 1 else t o_number(code) end) rn 25 from id_levels t 26 ) 27 group by clm 28 order by clm; CLM CODE1 CODE2 CODE3 CODE4 CODE5 CODE6 CODE7 CODE8 CODE9 ------------ ------------ ------------ ------------ ------------ ------------ ------------ --------- 1 15 41 42 44 2 3 4 3 24 15 15 16 4 12 67 5 13 22 24 5 rows selected. SQL> set lines 50 SQL> / CLM CODE1 CODE2 ------------ ------------ ------------ CODE3 CODE4 CODE5 ------------ ------------ ------------ CODE6 CODE7 CODE8 ------------ ------------ ------------ CODE9 CODE10 CODE11 ------------ ------------ ------------ CODE12 CODE13 CODE14 ------------ ------------ ------------ CODE15 CODE16 CODE17 ------------ ------------ ------------ CODE18 ------------ ... CLM CODE1 CODE2 ------------ ------------ ------------ CODE3 CODE4 CODE5 ------------ ------------ ------------ CODE6 CODE7 CODE8 ------------ ------------ ------------ CODE9 CODE10 CODE11 ------------ ------------ ------------ CODE12 CODE13 CODE14 ------------ ------------ ------------ CODE15 CODE16 CODE17 ------------ ------------ ------------ CODE18 ------------ 5 rows selected. SQL>
-
How to count the number of nodes under each parent in any given xml
How to count the number of nodes under each parent in any given xml. for example the xml below was
books has 3 childern, library [1] has 4, [2] library has 6 and bookshop [3] has 2. is it possible to get the number of tags in a childnode duplicate IE library [1]
Book1 Tagus repeated twice... vice versa. do we need to make plsql lie we can achieve through sql
< book >
< library >
ABC < book1 > < / book1 >
BCA < book2 > < / book2 >
ACR < book1 > < / book1 >
Lac < Book4 > < / Book4 >
< / book >
< library >
ABC < book1 > < / book1 >
BCA < book2 > < / book2 >
ACR < book3 > < / book3 >
ACR < book3 > < / book3 >
tray of < bookn_1 > < / bookn_1 >
adjusted cost base < bookn > < / bookn >
< / book >
< library >
ABC < book1 > < / book1 >
BCA < book2 > < / book2 >
< / book >
< / books >
I tried this... query.
Select
XMLQUERY ('count($doc/Books/Bookstore[1]/descendant::*)' in the way of xmltype ("< books >
< library >
ABC < book1 > < / book1 >
ACR < book1 > < / book1 >
Lac < Book4 > < / Book4 >
< / book >
< library >
ABC < book1 > < / book1 >
BCA < book2 > < / book2 >
< / book >
(< / books > ')
as 'doc' of happy return) .getNumberVal () as node_count
of the double
Select
XMLQUERY ('count($doc/Books/descendant::*)' in the way of xmltype ("< books >
< library >
ABC < book1 > < / book1 >
ACR < book1 > < / book1 >
Lac < Book4 > < / Book4 >
< / book >
< library >
ABC < book1 > < / book1 >
BCA < book2 > < / book2 >
< / book >
(< / books > ')
as 'doc' of happy return) .getNumberVal () as node_count
of the double
How can I get the counts for each parent in a single query
Published by: user7955917 on August 24, 2012 07:26Generic function how you want the query to be.
If the structure is known in advance, as in your example a 'books' and then a 'library' root element, it's as simple as:
SQL> select x1.parent_id, x2.child_name, count(*) 2 from tmp_xml t 3 , xmltable( 4 '/books/bookstore' 5 passing t.object_value 6 columns parent_id for ordinality 7 , child_list xmltype path '*' 8 ) x1 9 , xmltable( 10 '/*' 11 passing x1.child_list 12 columns child_name varchar2(30) path 'name()' 13 ) x2 14 group by x1.parent_id, x2.child_name 15 order by x1.parent_id, x2.child_name 16 ; PARENT_ID CHILD_NAME COUNT(*) ---------- ------------------------------ ---------- 1 book1 2 1 book2 1 1 book4 1 2 bookn 1 2 bookn_1 1 2 book1 1 2 book2 1 2 book3 2 3 book1 1 3 book2 1 10 rows selected
If you want a generic solution that works without knowledge of the structure, you will need a recursive approach, and most importantly, you should know which nodes in distinct, I suppose that the leafs?
Also, please help if you can provide the link of reference on the function name() years what are the other expression, that I can use after the path
You can start reading the documentation: http://docs.oracle.com/cd/E11882_01/appdev.112/e23094/xdb_xquery.htm#CBAGCBGJ
The clause PATH expects a XQuery expression however before 11.2, we can put only simple XPath expressions.
-
varchar2 to the date format conversion
I have converted the formats of date several times, but for some reason, I get an error invalid number when you try to convert a varchar2 column. I tried the to_char and to_date function and I get the same result. The column is a date and it is formatted like ME-DD-YYYY, but I want to change it to DD/MM/YYYY. My query is below:
Select to_date('fccpdate','MM/DD/YYYY')
of cc_class_scmast_v
When I try to_date I get this:
Error from the 1 in the command line:
Select TO_DATE ('fccpdate ',' MON-DD-YYYY "") of cc_class_scmast_v, where fccpdate IS NOT NULL
Error report:
SQL error: ORA-01858: a non-digit character was found here where was waiting for a digital
01858 00000 - "a non-digit character found here where was waiting for a digital".
* Cause: Input data to convert using a date format model has been
incorrect answer. The input data did not contain a number where is a number
required by the format model.
* Action: Fix the input data or the date format model to ensure that the
elements correspond to the number and the type. And then try the operation again.
When I try to_char I get this:
Error from the 1 in the command line:
Select TO_char ('fccpdate ',' MON-DD-YYYY "") of cc_class_scmast_v, where fccpdate IS NOT NULL
Error report:
SQL error: ORA-01722: invalid number
01722 00000 - "invalid number."
* Cause:
* Action:
I tried to remove the single quotes of my column and that does make a difference. Any help is appreciated.Hello
housetiger77 wrote:
I have converted the formats of date several times, but for some reason, I get an error invalid number when you try to convert a varchar2 column. I tried the to_char and to_date function and I get the same result. The column is a date and it is formatted like ME-DD-YYYY,If the column is a DATE, then it has the same format that all DATEs, which is nothing like 'DD-MON-YYYY '. Formats like which apply only to chains.
Conversely, if it is in the format "DD-MON-YYY", then it is a string, not a DATE.but I want to change to DD/MM/YYYY. My query is below:
Select to_date('fccpdate','MM/DD/YYYY')
of cc_class_scmast_vTo_date (x, "MM/DD/YYYY") tries to convert the string x in a DATE. Let's say it starts by taking the first 2 characters of x, for the month. The first 2 characters of 'fccpdate' are "fc", which is not a valid number (at least not in base 10), not to mention a number from 1 to 12, TO_DATE so will raise an error.
When I try to_date I get this:
Error from the 1 in the command line:
Select TO_DATE ('fccpdate ',' MON-DD-YYYY "") of cc_class_scmast_v, where fccpdate IS NOT NULL
Error report:
SQL error: ORA-01858: a non-digit character was found here where was waiting for a digital
01858 00000 - "a non-digit character found here where was waiting for a digital".
* Cause: Input data to convert using a date format model has been
incorrect answer. The input data did not contain a number where is a number
required by the format model.
* Action: Fix the input data or the date format model to ensure that the
elements correspond to the number and the type. And then try the operation again.When I try to_char I get this:
Error from the 1 in the command line:
Select TO_char ('fccpdate ',' MON-DD-YYYY "") of cc_class_scmast_v, where fccpdate IS NOT NULL
Error report:
SQL error: ORA-01722: invalid number
01722 00000 - "invalid number."
* Cause:
* Action:I tried to remove the single quotes of my column and that does make a difference. Any help is appreciated.
It's a good first step. Literals are enclosed in single quotes are not identifiers (including the column names). "fccpdate" is the literal string of 8 characters containing 'f', ' c; Another 'c', 'p' 'd', 'a', 't' and 'e'. " fccpdate (without the single quotes) can be the name of a column.
If fccpdate is a string, as July 18, 2012', then you can convert it to a DATE using TO_DATE.
TO_DATE (fccpdate, 'DD-MON-YYYY')
If you want to display a DATE in a particular format, use
TO_CHAR ( d , f )
where d is a DATE, and f is the format string. In this case, d is perhaps the TO_DATE expression above
TO_CHAR ( TO_DATE (fccpdate, 'DD-MON-YYYY') , 'MM/DD/YYYY' )
I hope that answers your question.
If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
Explain, using specific examples, how you get these results from these data.
Always tell what version of Oracle you are using.
See the FAQ forum {message identifier: = 9360002}
Maybe you are looking for
-
Apple script to check the part of iTunes XML library with other applications.
Y at - there no apple for script Check "Sharing iTunes library XML with other applications." Of iTunes Preferences Advanced tab... I want to read itunes Media Library .xml but lates itunes no xml is created by default, so I want this XML created by m
-
Matter of drivers HP Pavilion a6230.gr
Hello. I have the HP Pavilion a6230.gr for over a year now and I want to buy a new WD 670 GB internal HDD. Well, I also have my original Windows XP Professional boot drive of my old pc, and I want to install them in the internal drive of tnew without
-
I'm not able to open GP files sent by family of cell phones
The error message indicates that these are not files supported
-
Adobe first 14 elements does not recognize not my camcorder Sony HDR - HC7 recording on DV tapes.I see that it recognizes cards Flash and the DD, but recognises - it SD cards?Thanks for the reply because I intend to buy a new Sony camcorder
-
Elements 9 does not open the raw files from my new camera
Have a panasonic DMC-GX85. My 9 items does not open the raw file and I failed in upgrading to 9.03 and camera raw 6.5. Y at - it solution or do I have the latest elements?