SQL - restructuring of the Table
Hello worldI hope that this is possible in Oracle. I need to restructure a followingly table. I appreciate all of your time.
With the help of 10 or 11 g
PCP MEASURE SUCCESS TOTAL
P001 A 2 3
P001 B 3 4
P001 C 4 5
P001 D 5 6
P001 E 6 7
P002 A 7 8
P002 B 8 9
P002 C 9 10
P002 D 10 11
P002 E 11 12
P003 C 12 13
P003 D 13 14
ResultPCP A B C D E FLAG
P001 2 3 4 5 6 SUCCESS
P001 3 4 5 6 7 TOTAL
P002 7 8 9 10 11 SUCCESS
P002 8 9 10 11 12 TOTAL
P003 0 0 12 13 0 SUCCESS
P003 0 0 13 14 0 TOTAL
Published by: 788729 on October 26, 2011 13:42
Hello
Assuming you are wanting to do using a query, you can go (using 10 G)...
select
pcp,
nvl(max(a),0) as a,
nvl(max(b),0) as b,
nvl(max(c),0) as c,
nvl(max(d),0) as d,
nvl(max(e),0) as e,
flag
from (
select
pcp,
case when measure = 'A' then success end as a,
case when measure = 'B' then success end as b,
case when measure = 'C' then success end as c,
case when measure = 'D' then success end as d,
case when measure = 'E' then success end as e,
'SUCCESS' as flag
from temptable
union all
select pcp,
case when measure = 'A' then total end as a,
case when measure = 'B' then total end as b,
case when measure = 'C' then total end as c,
case when measure = 'D' then total end as d,
case when measure = 'E' then total end as e,
'TOTAL' as flag
from temptable
)
group by pcp, flag
order by pcp, flag
Hope this helps,
Mark
Published by: user455268 on October 26, 2011 16:15
Tags: Database
Similar Questions
-
SQL query for the table in the schema
Hi user;
Imagine that we have 10 schema in oracle db. I wonder all the name of the table as shcema A1. I want to find these tables name everything first (let us suppose schema A1 has 100,000 tables)
Then, I want to give select grant the user A for these 100,000 tables. I don't want to use grant any table. I just want to give A user to select right for tables (100,000) which is under schema A1. How can I do? Please give me some ideas or the path
Thank youAAAAA says:
Hi Nicholas.Its system of prod and I'm afraid to be confused :)
Yes, I understand very well you're scared, then why not you plan some tests in front on a dummy database?
Nicolas.
-
Hello
Thanks for your time in advance. I have following way table and need to restructure.
Desired resultDROP TABLE HCC_DETAIL ; COMMIT ; CREATE TABLE HCC_DETAIL ( M_ID VARCHAR2(5), AGE_FEMALE_0_64 CHAR(1), AGE_FEMALE_65_69 CHAR(1), AGE_MALE_0_64 CHAR(1), AGE_MALE_65_69 CHAR(1), D_HCC1 CHAR(1) , D_HCC2 CHAR(1) , D_HCC3 CHAR(1) , D_HCC4 CHAR(1) , D_INT1 CHAR(1) , D_INT10 CHAR(1) ) ; TRUNCATE TABLE HCC_DETAIL ; INSERT INTO HCC_DETAIL ( M_ID, AGE_FEMALE_0_64, AGE_FEMALE_65_69, AGE_MALE_0_64, AGE_MALE_65_69, D_HCC1, D_HCC2, D_HCC3, D_HCC4, D_INT1, D_INT10 ) VALUES ( '111AA', '1', '0', '0', '0', '1', '0', '0', '1', '1', '1' ) ; INSERT INTO HCC_DETAIL ( M_ID, AGE_FEMALE_0_64, AGE_FEMALE_65_69, AGE_MALE_0_64, AGE_MALE_65_69, D_HCC1, D_HCC2, D_HCC3, D_HCC4, D_INT1, D_INT10 ) VALUES ( '1A1AA', '0', '0', '0', '1', '1', '0', '0', '1', '1', '0' ) ; COMMIT;
M_ID AGE_BRACKET HCC_GROUP INT_GROUP 111AA 0_64 1, 4 1, 10 1A1AA 65_69 1, 4 1
Hello
According to your data and your needs:
SELECT m_id , CASE WHEN age_female_0_64 = 1 THEN '0_64' WHEN age_female_65_69 = 1 THEN '65_69' WHEN age_male_0_64 = 1 THEN '0_64' WHEN age_male_65_69 = 1 THEN '65_69' END AS age_bracket , SUBSTR ( CASE WHEN d_hcc1 = '1' THEN ', 1' END || CASE WHEN d_hcc2 = '1' THEN ', 2' END || CASE WHEN d_hcc3 = '1' THEN ', 3' END || CASE WHEN d_hcc4 = '1' THEN ', 4' END , 3 ) AS hcc_group , SUBSTR ( CASE WHEN d_int1 = '1' THEN ', 1' END || CASE WHEN d_int10 = '1' THEN ', 10' END , 3 ) AS int_group FROM hcc_detail ;
I did a lot of assumptions to what are the possible values and how the columns are related to the other columns on the same line.
-
How to add data to the table changed in sql developer at Apex and vice versa
Hello
I had tables of database with sql developer. But now, I have modified the database (new tables added + changed the data in the tables). However, in the Apex, I the old database. Is it possible to get the new Apex database with the data of the table changed so this database in both places (sql and apex developer) is exactly the same... Also the other way around.
Thank you
The database schema that contains the tables, is it associated with the workspace even you are searching through the APEX product t development? Why I'm asking is, if they are the same schema, the tables that you MODIFIED should be appear in the sql for APEX workshop part. Now reports and forms will NOT see the changes (unless you have actually added or updated definitions for column).
Can you explain what exactly you were doing the SQL Developer to the tables in your schema?
Thank you
Tony Miller
Los Alamos, NM -
How can I pass a condition of the table in the sql statement?
For example, in the table in the COND Varchar2 column (200) there is the value ' VAR > 10'.
| COND |
|' VAR > 10' |
where VAR is the name of the table column. I would like to make statement CASE WHEN VAR > 10 AND 0... I tried with as subquery
WHEN BOX (SELECT COND FROM TABLE WHERE...) THEN 0, but it does not work.
Hello
You can do this by using dynamic SQL.
that is to say:
declare v_stm varchar2(4000); v_cond varchar2(100); v_result integer; begin select cond into v_cond from yourtable where a=1; v_stm := 'select case when '||v_cond||' then 0 ...'; -- dynamic sql execute immediate v_stm into v_result; end; /
Remember that, in general, dynamic SQL has a performance degradation that SQL static and should be avoided when possible.
Storage condition or the SQL statements in the tables is not a good practice.
Kind regards.
Alberto
-
Shrink the table, rebuild the index?
I need to reduce some very large tables after the removal of lines and I want to validate the script to run. I was thinking something like this:
run_deleting_process;
change the movement line of table my_tableI enable;
ALTER table my_table retractable space WATERFALL;
change the movement line of table my_tableI disable;
I need to rebuild the index after that?, or if I rebuild the markings, can I delete clause CASCADE of the command? It is recommended to run utltrp.sql after shrink the table?, maybe some dependent object needs to be recompiled after the reduction of a table?
The database version is 11.1.0.7 and documentation does not specify that the index rebuild is required, but I realized it is a desition normall when the narrowing of the tables.
Thank youNo there is no rebuild the index after shrinkage. And if you use "cascade", your index will be supported. You do very well.
Visit this link as well.
http://www.orafaq.com/Forum/t/137522/2/
-
identify the tables that are affected by a transaction
Hi guys,.
I am running version:
Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE Production 11.2.0.3.0
AMT for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
Is it possible to identify the SQL code or the tables involved in a transaction by looking at the transaction$ v?Just wrote a small application, but can't test it in my DB... Just check it...
Basically CREATE all the views will provide some information.SELECT t.ses_addr, s.sid, p.object_id, D.OBJECT_NAME,s.command FROM v$transaction t, v$session s, V$locked_object p, dba_objects d WHERE t.ses_addr = s.saddr AND p.session_id = s.sid AND d.object_id = p.object_id;
The command column is a code displays what kind of operation is being currently... the explanation of the code can be mentioned in the documentation:
http://docs.Oracle.com/CD/B19306_01/server.102/b14237/dynviews_2088.htm
See you soon,.
Manik. -
How to find the primary key columns in the tables in MS Access using SQL queries
How to find the primary key columns in the tables in MS Access using SQL queries
Hello
This is the forum for Windows Vista programs related issues.
For better assistance, please try instead the Forums in SQL Server .
Thank you! Vincenzo Di Russo - Microsoft MVP Windows Internet Explorer, Windows Desktop Experience & security - since 2003. ~ ~ ~ My MVP profile: https://mvp.support.microsoft.com/profile/Vincenzo
-
While performing a mapping (present in the package) that loads the file to table data, my mapping is being failed in the step - LKM file with above mentioned SQL error.
This task is running for 30 candy Mint and loading data about 30 to 40 million for the temporary table of C$ ODI.
Before the completion of the task is to make failure and also C$ table is also get deleted.
Any possible resolution for above mentioned the issue?
Problems have been solved.
In our case, the prefix of all the data store name has been SRC_ so the nickname of all the data store became SRC, and the table name C$ depends on the daatastore Alias.
So for executing two mapping tables $ CAN have been getting dropped by other mapping due to the same table name $ CAN.
Change the Alias name giving it a unique name solve the problem.
-
Single SQL query for the analysis of the date of customs declaration under the table of Stock codes
Dear all,
Please tell us a single SQL query for the below,
We have a Table of Stock as shown below,
STOCK_TABLE
ITEM_CODE
(item code)
BAT_NO
(lot no.)
TXN_CODE
(transaction code)
DOC_NO
(number)
BOE_DT
(date of the customs declaration)
I1
B1
I1
I2
I3
B70
I4
B80
I5
B90
T102
1234
JULY 2, 2015
I6
B100
We have to find the date of customs declaration (i.e. the date when the items have come under this particular table) for items that are not attached to any document (that is, who have TXN_CODE, DOC_NO and BOE_DT fields with a NULL value).
For each item in the table of actions, which is not attached to any document, the customs declaration date is calculated as follows.
- If (code section, lot number) combination is present under HISTORY_TABLE, the date of customs declaration will receive the UPDT_DT, the transaction code (TXN_CODE) is an IN or transactions (which can be analyzed from the TRANSACTIONS table).
- If (code section, lot number) combination is NOT currently at the HISTORY_TABLE (or) the transaction code respective to item - batch number combination code is an operation then customs declaration date will be the date of the document (DOC_DT) that we receive from one of the 3 tables IN_TABLE_HEAD that contains the element of that particular lot.
- If the case 1 and case 2 fails, our customs declaration date will be the last date of document (DOC_DT) that we receive from one of the 3 tables IN_TABLE_HEAD containing that particular item and the BAT_NO in expected results will be that corresponding to this document, as appropriate, to another NULL.
- If the case 1 or case 2 is successful, the value of the last field (in the output expected, shown further below) BATCH_YN will be 'Y', because it fits the lot. Otherwise it will be 'n'.
-
What is the SQL to determine what are the table objects in the KEEP buffer pool?
What is the SQL to determine what are the table objects in the KEEP buffer pool?
Select owner, table_name
from dba_tables
where USER_TABLES = "KEEP."
/
David Fitzjarrell
-
Question to load data using sql loader in staging table, and then in the main tables!
Hello
I'm trying to load data into our main database table using SQL LOADER. data will be provided in separate pipes csv files.
I have develop a shell script to load the data and it works fine except one thing.
Here are the details of a data to re-create the problem.
Staging of the structure of the table in which data will be filled using sql loader
create table stg_cmts_data (cmts_token varchar2 (30), CMTS_IP varchar2 (20));
create table stg_link_data (dhcp_token varchar2 (30), cmts_to_add varchar2 (200));
create table stg_dhcp_data (dhcp_token varchar2 (30), DHCP_IP varchar2 (20));
DATA in the csv file-
for stg_cmts_data-
cmts_map_03092015_1.csv
WNLB-CMTS-01-1. 10.15.0.1
WNLB-CMTS-02-2 | 10.15.16.1
WNLB-CMTS-03-3. 10.15.48.1
WNLB-CMTS-04-4. 10.15.80.1
WNLB-CMTS-05-5. 10.15.96.1
for stg_dhcp_data-
dhcp_map_03092015_1.csv
DHCP-1-1-1. 10.25.23.10, 25.26.14.01
DHCP-1-1-2. 56.25.111.25, 100.25.2.01
DHCP-1-1-3. 25.255.3.01, 89.20.147.258
DHCP-1-1-4. 10.25.26.36, 200.32.58.69
DHCP-1-1-5 | 80.25.47.369, 60.258.14.10
for stg_link_data
cmts_dhcp_link_map_0309151623_1.csv
DHCP-1-1-1. WNLB-CMTS-01-1,WNLB-CMTS-02-2
DHCP-1-1-2. WNLB-CMTS-03-3,WNLB-CMTS-04-4,WNLB-CMTS-05-5
DHCP-1-1-3. WNLB-CMTS-01-1
DHCP-1-1-4. WNLB-CMTS-05-8,WNLB-CMTS-05-6,WNLB-CMTS-05-0,WNLB-CMTS-03-3
DHCP-1-1-5 | WNLB-CMTS-02-2,WNLB-CMTS-04-4,WNLB-CMTS-05-7
WNLB-DHCP-1-13 | WNLB-CMTS-02-2
Now, after loading these data in the staging of table I have to fill the main database table
create table subntwk (subntwk_nm varchar2 (20), subntwk_ip varchar2 (30));
create table link (link_nm varchar2 (50));
SQL scripts that I created to load data is like.
coil load_cmts.log
Set serveroutput on
DECLARE
CURSOR c_stg_cmts IS SELECT *.
OF stg_cmts_data;
TYPE t_stg_cmts IS TABLE OF stg_cmts_data % ROWTYPE INDEX BY pls_integer;
l_stg_cmts t_stg_cmts;
l_cmts_cnt NUMBER;
l_cnt NUMBER;
NUMBER of l_cnt_1;
BEGIN
OPEN c_stg_cmts.
Get the c_stg_cmts COLLECT in BULK IN l_stg_cmts;
BECAUSE me IN l_stg_cmts. FIRST... l_stg_cmts. LAST
LOOP
SELECT COUNT (1)
IN l_cmts_cnt
OF subntwk
WHERE subntwk_nm = l_stg_cmts (i) .cmts_token;
IF l_cmts_cnt < 1 THEN
INSERT
IN SUBNTWK
(
subntwk_nm
)
VALUES
(
l_stg_cmts (i) .cmts_token
);
DBMS_OUTPUT. Put_line ("token has been added: ' |") l_stg_cmts (i) .cmts_token);
ON THE OTHER
DBMS_OUTPUT. Put_line ("token is already present'");
END IF;
WHEN l_stg_cmts EXIT. COUNT = 0;
END LOOP;
commit;
EXCEPTION
WHILE OTHERS THEN
Dbms_output.put_line ('ERROR' |) SQLERRM);
END;
/
output
for dhcp
coil load_dhcp.log
Set serveroutput on
DECLARE
CURSOR c_stg_dhcp IS SELECT *.
OF stg_dhcp_data;
TYPE t_stg_dhcp IS TABLE OF stg_dhcp_data % ROWTYPE INDEX BY pls_integer;
l_stg_dhcp t_stg_dhcp;
l_dhcp_cnt NUMBER;
l_cnt NUMBER;
NUMBER of l_cnt_1;
BEGIN
OPEN c_stg_dhcp.
Get the c_stg_dhcp COLLECT in BULK IN l_stg_dhcp;
BECAUSE me IN l_stg_dhcp. FIRST... l_stg_dhcp. LAST
LOOP
SELECT COUNT (1)
IN l_dhcp_cnt
OF subntwk
WHERE subntwk_nm = l_stg_dhcp (i) .dhcp_token;
IF l_dhcp_cnt < 1 THEN
INSERT
IN SUBNTWK
(
subntwk_nm
)
VALUES
(
l_stg_dhcp (i) .dhcp_token
);
DBMS_OUTPUT. Put_line ("token has been added: ' |") l_stg_dhcp (i) .dhcp_token);
ON THE OTHER
DBMS_OUTPUT. Put_line ("token is already present'");
END IF;
WHEN l_stg_dhcp EXIT. COUNT = 0;
END LOOP;
commit;
EXCEPTION
WHILE OTHERS THEN
Dbms_output.put_line ('ERROR' |) SQLERRM);
END;
/
output
for link -.
coil load_link.log
Set serveroutput on
DECLARE
l_cmts_1 VARCHAR2 (4000 CHAR);
l_cmts_add VARCHAR2 (200 CHAR);
l_dhcp_cnt NUMBER;
l_cmts_cnt NUMBER;
l_link_cnt NUMBER;
l_add_link_nm VARCHAR2 (200 CHAR);
BEGIN
FOR (IN) r
SELECT dhcp_token, cmts_to_add | ',' cmts_add
OF stg_link_data
)
LOOP
l_cmts_1: = r.cmts_add;
l_cmts_add: = TRIM (SUBSTR (l_cmts_1, 1, INSTR (l_cmts_1, ',') - 1));
SELECT COUNT (1)
IN l_dhcp_cnt
OF subntwk
WHERE subntwk_nm = r.dhcp_token;
IF l_dhcp_cnt = 0 THEN
DBMS_OUTPUT. Put_line ("device not found: ' |") r.dhcp_token);
ON THE OTHER
While l_cmts_add IS NOT NULL
LOOP
l_add_link_nm: = r.dhcp_token |' _TO_' | l_cmts_add;
SELECT COUNT (1)
IN l_cmts_cnt
OF subntwk
WHERE subntwk_nm = TRIM (l_cmts_add);
SELECT COUNT (1)
IN l_link_cnt
LINK
WHERE link_nm = l_add_link_nm;
IF l_cmts_cnt > 0 AND l_link_cnt = 0 THEN
INSERT INTO link (link_nm)
VALUES (l_add_link_nm);
DBMS_OUTPUT. Put_line (l_add_link_nm |) » '||' Has been added. ") ;
ELSIF l_link_cnt > 0 THEN
DBMS_OUTPUT. Put_line (' link is already present: ' | l_add_link_nm);
ELSIF l_cmts_cnt = 0 then
DBMS_OUTPUT. Put_line (' no. CMTS FOUND for device to create the link: ' | l_cmts_add);
END IF;
l_cmts_1: = TRIM (SUBSTR (l_cmts_1, INSTR (l_cmts_1, ',') + 1));
l_cmts_add: = TRIM (SUBSTR (l_cmts_1, 1, INSTR (l_cmts_1, ',') - 1));
END LOOP;
END IF;
END LOOP;
COMMIT;
EXCEPTION
WHILE OTHERS THEN
Dbms_output.put_line ('ERROR' |) SQLERRM);
END;
/
output
control files -
DOWNLOAD THE DATA
INFILE 'cmts_data.csv '.
ADD
IN THE STG_CMTS_DATA TABLE
When (cmts_token! = ") AND (cmts_token! = 'NULL') AND (cmts_token! = 'null')
and (cmts_ip! = ") AND (cmts_ip! = 'NULL') AND (cmts_ip! = 'null')
FIELDS TERMINATED BY ' |' SURROUNDED OF POSSIBLY "" "
TRAILING NULLCOLS
('RTRIM (LTRIM (:cmts_token))' cmts_token,
cmts_ip ' RTRIM (LTRIM(:cmts_ip)) ")". "
for dhcp.
DOWNLOAD THE DATA
INFILE 'dhcp_data.csv '.
ADD
IN THE STG_DHCP_DATA TABLE
When (dhcp_token! = ") AND (dhcp_token! = 'NULL') AND (dhcp_token! = 'null')
and (dhcp_ip! = ") AND (dhcp_ip! = 'NULL') AND (dhcp_ip! = 'null')
FIELDS TERMINATED BY ' |' SURROUNDED OF POSSIBLY "" "
TRAILING NULLCOLS
('RTRIM (LTRIM (:dhcp_token))' dhcp_token,
dhcp_ip ' RTRIM (LTRIM(:dhcp_ip)) ")". "
for link -.
DOWNLOAD THE DATA
INFILE 'link_data.csv '.
ADD
IN THE STG_LINK_DATA TABLE
When (dhcp_token! = ") AND (dhcp_token! = 'NULL') AND (dhcp_token! = 'null')
and (cmts_to_add! = ") AND (cmts_to_add! = 'NULL') AND (cmts_to_add! = 'null')
FIELDS TERMINATED BY ' |' SURROUNDED OF POSSIBLY "" "
TRAILING NULLCOLS
('RTRIM (LTRIM (:dhcp_token))' dhcp_token,
cmts_to_add TANK (4000) RTRIM (LTRIM(:cmts_to_add)) ")" ""
SHELL SCRIPT-
If [!-d / log]
then
Mkdir log
FI
If [!-d / finished]
then
mkdir makes
FI
If [!-d / bad]
then
bad mkdir
FI
nohup time sqlldr username/password@SID CONTROL = load_cmts_data.ctl LOG = log/ldr_cmts_data.log = log/ldr_cmts_data.bad DISCARD log/ldr_cmts_data.reject ERRORS = BAD = 100000 LIVE = TRUE PARALLEL = TRUE &
nohup time username/password@SID @load_cmts.sql
nohup time sqlldr username/password@SID CONTROL = load_dhcp_data.ctl LOG = log/ldr_dhcp_data.log = log/ldr_dhcp_data.bad DISCARD log/ldr_dhcp_data.reject ERRORS = BAD = 100000 LIVE = TRUE PARALLEL = TRUE &
time nohup sqlplus username/password@SID @load_dhcp.sql
nohup time sqlldr username/password@SID CONTROL = load_link_data.ctl LOG = log/ldr_link_data.log = log/ldr_link_data.bad DISCARD log/ldr_link_data.reject ERRORS = BAD = 100000 LIVE = TRUE PARALLEL = TRUE &
time nohup sqlplus username/password@SID @load_link.sql
MV *.log. / log
If the problem I encounter is here for loading data in the link table that I check if DHCP is present in the subntwk table, then continue to another mistake of the newspaper. If CMTS then left create link to another error in the newspaper.
Now that we can here multiple CMTS are associated with unique DHCP.
So here in the table links to create the link, but for the last iteration of the loop, where I get separated by commas separate CMTS table stg_link_data it gives me log as not found CMTS.
for example
DHCP-1-1-1. WNLB-CMTS-01-1,WNLB-CMTS-02-2
Here, I guess to link the dhcp-1-1-1 with balancing-CMTS-01-1 and wnlb-CMTS-02-2
Theses all the data present in the subntwk table, but still it gives me journal wnlb-CMTS-02-2 could not be FOUND, but we have already loaded into the subntwk table.
same thing is happening with all the CMTS table stg_link_data who are in the last (I think here you got what I'm trying to explain).
But when I run the SQL scripts in the SQL Developer separately then it inserts all valid links in the table of links.
Here, she should create 9 lines in the table of links, whereas now he creates only 5 rows.
I use COMMIT in my script also but it only does not help me.
Run these scripts in your machine let me know if you also get the same behavior I get.
and please give me a solution I tried many thing from yesterday, but it's always the same.
It is the table of link log
link is already present: dhcp-1-1-1_TO_wnlb-cmts-01-1 NOT FOUND CMTS for device to create the link: wnlb-CMTS-02-2
link is already present: dhcp-1-1-2_TO_wnlb-cmts-03-3 link is already present: dhcp-1-1-2_TO_wnlb-cmts-04-4 NOT FOUND CMTS for device to create the link: wnlb-CMTS-05-5
NOT FOUND CMTS for device to create the link: wnlb-CMTS-01-1
NOT FOUND CMTS for device to create the link: wnlb-CMTS-05-8 NOT FOUND CMTS for device to create the link: wnlb-CMTS-05-6 NOT FOUND CMTS for device to create the link: wnlb-CMTS-05-0 NOT FOUND CMTS for device to create the link: wnlb-CMTS-03-3
link is already present: dhcp-1-1-5_TO_wnlb-cmts-02-2 link is already present: dhcp-1-1-5_TO_wnlb-cmts-04-4 NOT FOUND CMTS for device to create the link: wnlb-CMTS-05-7
Device not found: wnlb-dhcp-1-13 IF NEED MORE INFORMATION PLEASE LET ME KNOW
Thank you
I felt later in the night that during the loading in the staging table using UNIX machine he created the new line for each line. That is why the last CMTS is not found, for this I use the UNIX 2 BACK conversion and it starts to work perfectly.
It was the dos2unix error!
Thank you all for your interest and I may learn new things, as I have almost 10 months of experience in (PLSQL, SQL)
-
Insert SQL % number of ROWS in the table for forest exploitation
Hi Experts,
I have a stored procedure that I want to write to a log table the actual number of lines inserted for the audit later if necessary.
Despite,.
var_year is a parameter
but the error is thrown to the SQL % ROWCOUNT, saying: the symbol is not recognized.
INSERT IN T_LOG (var_Year, time, message) VALUES (year, SYSDATE, TO_CHAR(SQL%ROWCOUNT) |' xxxxx ' |) VAR_year | 'inserted');
Any ideas?
Declare a variable of type NUMBER.
Immediately after your INSERT, copy SQL ROWCOUNT % to this variable.
Then use this variable to insert in the newspaper.
declare
number of l_rowcount;
Start
-Insert stuff
l_rowcount: = SQL % ROWCOUNT;
INSERT IN T_LOG (var_Year, time, message) VALUES (year, SYSDATE, TO_CHAR (l_rowcount): ' xxxxx ' |) VAR_year | 'inserted');
--
end;
/
-
I write in the topic, I have created a form and in some of their fields, I used a SQL query to get information from a table based on the user who has been logging.
The information displayed well, but when I press "Send button" loses information and the field in the table is shown empty.
Anyone know what is happening?
I enclose below a picture of the problem
Concerning
Hi ANTHONY,.
ANTHONY wrote:
I give you the credentials of my database, I hope you could do it works and most importantly, showing me what the error care...
Feel free to change what you want in the application
https://Apex.Oracle.com/pls/Apex/f?p=4550:1:2838412118981:
BANCO_PRUEBAS
ADMIN
password
It is interesting that, when I use APEX 5.0.1.00.06, I have some errors form appearing not using APEX 4.1.0.00.32
Check your 77569 application-> Page 1. I have modified the page element attributes. Now it's working.
Here are the changes (I will explain for P1_NOMBRE, did the same for the P1_APELLIDOS and P1_CATEGORIA):
- 'Source' has become article attributed to him include:
Source: Replacement always, value that exists in session state
Source type: column database
Source of value or an expression: NUMBER
- The "Default" article now the following attributes:
By default of Type: PL/SQL function body
Default value:
DECLARE L_NOMBRE B_LISTA_EMPLEADOS.NOMBRE%TYPE; BEGIN select NOMBRE into L_NOMBRE from B_LISTA_EMPLEADOS where USERNAME = :APP_USER; RETURN L_NOMBRE; EXCEPTION WHEN NO_DATA_FOUND THEN RETURN NULL; END;
Kind regards
Kiran
-
How to update table pl SQL by using the loop
Assuming I don't have only one table: members_tbl which columns are: SN, FN, DB, IDDBL, FLAG, DBLCRIT
I need to update the table if certain conditions are OK with this algorithm:
id_dup: = 1;
(I, 1 to Nrow (members_tbl)) THEN
{
((I + 1) J to Nrow (members_tbl)) THEN
{
IF (members_tbl (i) .iddbl IS NULL) THEN
members_tbl (i) .iddbl: = id_dup
IF (((members_tbl (i). DB is members_tbl (j). DB)
AND (UTL_MATCH.jaro_winkler_similarity (members_tbl (i). SN, members_tbl (j). (SN) > 80)
AND (UTL_MATCH.jaro_winkler_similarity (members_tbl (i). FN, members_tbl (j). FN) > 80))
AND (members_tbl (j) .iddbl IS NULL)) THEN
{
members_tbl (j) .iddbl: = id_dup;
members_tbl (i) .flag: = 1;
members_tbl (j) .flag: = 1;
members_tbl (i) .dblcrit: = 1;
members_tbl (j) .dblcrit: = 1;
}
}
id_dup: = id_dup + 1;
}
Is there a way to write this algorithm in a pl/sql procedure? I'm relatively new to PL/SQL, and I've never written a stored procedure.
IDDBL is a NUMBER yet, there may be several duplicate rows. How you expect store multiple values in a single issue?
SQL > select m.idm
2, m.sname
3, m.fname
4, m.dbirth
5, listagg (m2.idm, ',') Group (order of m2.idm) as dups
members_tbl 6 m
7 left join external members_tbl m2 (m.idm! = m2.idm)
8 and m.dbirth = m2.dbirth
9 and utl_match.jaro_winkler_similarity (m.sname, m2.sname) > 80
10 and utl_match.jaro_winkler_similarity (m.fname, m2.fname) > 80
11 )
Group m.idm 12, m.sname, m.fname, m.dbirth
13.
IDM SNAME FNAME DBIRTH DUPS
---------- -------------------- -------------------- --------------- --------------------
BOLOREY JEANNE 05/11/1955 126 125 223
126 BOLLOREY JEANNE 05/11/1955 125 223
153 BALORE GIANNE 05/11/1955
223 ABOLLOREYY JEANNE 05/11/1955 125 126
225 RELIABLE MARINE 25/04/1963 228 230
228 LOW MARYANE 25/04/1963 225 230
LOW 230 SAILOR 25/04/1963 225 228
235 LIPARK JACQLINE 20/12/1939 237
236 ILIPARC JACQUELYNE 20/12/1939 237
237 LIPARC JACQUELHINE 20/12/1939 235 236
240 RINTET MALIKA 08/07/1954
241 GRISION RAUGER 26/10/1931 242-245
ROGER 10/26/1931 241 GRISION 242
245 GRESION RAUJER 26/10/1931 24114 selected lines.
HISTORY_TABLE
ITEM_CODE | BAT_NO |
TXN_CODE
DOC_NO
UPDT_DT
I1
B1
T1
1234
JANUARY 3, 2015
I1
B20
T20
4567
MARCH 3, 2015
I1
B30
T30
7890
FEBRUARY 5, 2015
I2
B40
T20
1234
JANUARY 1, 2015
TRANSACTION
TXN_CODE | TXN_TYPE |
T1 | IN |
T20 |
OFF
T30
ALL THE
T50
IN
T80
IN
T90
IN
T60
ALL THE
T70
ALL THE
T40
ALL THE
IN_TABLE_HEAD_1
H1_SYS_ID (primary key) | TXN_CODE | DOC_NO |
DOC_DATE
H1ID1
T1
1234
JANUARY 1, 2015
H1ID2
T70
1234
FEBRUARY 1, 2015
IN_TABLE_ITEM_1
I1_SYS_ID |
H1_SYS_ID
(foreign key referencing H1_SYS_ID in IN_TABLE_HEAD_1)
ITEM_CODE
I1ID1
H1ID1
I1
I1ID2
H1ID1
I100
I1ID3
H1ID2
I3
IN_TABLE_BATCH_1
B1_SYS_ID | TXN_CODE DOC_NO (now in IN_TABLE_HEAD_1) | BAT_NO |
B1ID1
T1
1234
B1 / can be empty
B1ID2
T70
1234
B70
IN_TABLE_HEAD_2
H2_SYS_ID (primary key) | TXN_CODE |
DOC_NO
DOC_DATE
H2ID1
T30
4567
FEBRUARY 3, 2015
H2ID2
T60
1234
JANUARY 3, 2015
IN_TABLE_ITEM_2
I2_SYS_ID | H2_SYS_ID (foreign key referencing H2_SYS_ID in IN_TABLE_HEAD_2) | ITEM_CODE |
I2ID1 | H2ID1 |
I1
I2ID2
H2ID1
I200
I2ID3
H2ID2
I2
IN_TABLE_BATCH_2
B2_SYS_ID |
I2_SYS_ID
(foreign key referencing I2_SYS_ID in IN_TABLE_ITEM_2)
BAT_NO
B2ID1
I2ID1
B30 / null
B2ID2
I2ID2
B90
B2ID2
I2ID3
B60
IN_TABLE_HEAD_3
H3_SYS_ID (primary key) | TXN_CODE | DOC_NO | DOC_DATE |
H3ID1 |
T50
1234
JANUARY 2, 2015
H3ID2
T80
1234
JANUARY 3, 2015
H3ID3
T90
1234
JANUARY 4, 2015
H3ID4
T40
1234
AUGUST 5, 2015
IN_TABLE_ITEM_3
I3_SYS_ID |
H3_SYS_ID
(foreign key referencing H3_SYS_ID in IN_TABLE_HEAD_3)
ITEM_CODE
BAT_NO
I3ID1
H31D1
I2
B50
I3ID2
H3ID2
I4
B40
I3ID3
H3ID3
I4
I3ID4
H3ID4
I6
There is no IN_TABLE_BATCH_3
Please find below the expected results.
OUTPUT
ITEM_CODE | BAT_NO | TXN_CODE | DOC_NO |
BOE_DT
BATCH_YN
I1
B1
T1
1234
JANUARY 3, 2015
THERE
I1
B30
T30
7890
FEBRUARY 5, 2015
N
I2
B60
T60
1234
JANUARY 3, 2015
N
I3
B70
T70
1234
FEBRUARY 1, 2015
THERE
I4
T90
1234
JANUARY 4, 2015
N
I6
T40
1234
AUGUST 5, 2015
N
Controls database to create the tables above and insert the records.
CREATE TABLE stock_table()item_code VARCHAR2()80),bat_no VARCHAR2()80),txn_code VARCHAR2()80),
doc_no VARCHAR2 (80), boe_dt DATE );
INSERT EN stock_table
VALUES ('I1', 'B1', '', '', '');
INSERT EN stock_table
VALUES ('I1', '', '', '', '');
INSERT IN stock_table
VALUES ('I2', '', '', '', '');
INSERT EN stock_table
VALUES ('I3', 'B70', '', '', '');
INSERT EN stock_table
VALUES ('I4', 'B80', '', '', '');
INSERT EN stock_table
VALUES ('I5', 'B90', 'T102', '1234', '02-JUL-2015');
INSERT EN stock_table
VALUES ('I6', 'B100', '', '', '');
SELECT *
FROM stock_table
CREATE TABLE history_table()item_code VARCHAR2()80),bat_no VARCHAR2()80),txn_code VARCHAR2()80),
doc_no VARCHAR2 (80), updt_dt DATE );
INSERT IN history_table
VALUES ('I1', 'B1', 'T1', '1234', '03-JAN-2015');
INSERT IN history_table
VALUES ('I1', 'B20', 'T20', '4567', '03-MAR-2015');
INSERT IN history_table
VALUES ('I1', 'B30', 'T30', '7890', '05-FEB-2015');
INSERT IN history_table
VALUES ('I2', 'B40', 'T20', '1234', '01-JAN-2015');
SELECT *
FROM history_table
CREATE TABLE transaction1()txn_code VARCHAR()80),txn_type VARCHAR()80));
INSERT INTO transaction1
VALUES ('T1', 'IN');
INSERT INTO transaction1
VALUES ('T20', 'OUT');
INSERT INTO transaction1
VALUES ('T30', 'ALL');
INSERT INTO transaction1
VALUES ('T40', 'ALL');
INSERT INTO transaction1
VALUES ('T50', 'IN');
INSERT INTO transaction1
VALUES ('T60', 'ALL');
INSERT INTO transaction1
VALUES ('T70', 'ALL');
INSERT INTO transaction1
VALUES ('T80', 'IN');
INSERT INTO transaction1
VALUES ('T90', 'IN');
SELECT *
FROM transaction1
CREATE TABLE in_table_head_1()h1_sys_id VARCHAR2()80) PRIMARY KEY,txn_code VARCHAR2()80),
doc_no VARCHAR2 (80), doc_dt DATE );
CREATE TABLE in_table_head_2()h2_sys_id VARCHAR2()80) PRIMARY KEY,txn_code VARCHAR2()80),
doc_no VARCHAR2 (80), doc_dt DATE );
CREATE TABLE in_table_head_3()h3_sys_id VARCHAR2()80) PRIMARY KEY,txn_code VARCHAR2()80),
doc_no VARCHAR2 (80), doc_dt DATE );
INSERT IN in_table_head_1
VALUES ('H1ID1', 'T1', '1234', '01-JAN-2015');
INSERT IN in_table_head_1
VALUES ('H1ID2', 'T70', '1234', '01-FEB-2015');
INSERT IN in_table_head_2
VALUES ('H2ID1', 'T30', '4567', '03-FEB-2015');
INSERT IN in_table_head_2
VALUES ('H2ID2', 'T60', '1234', '03-JAN-2015');
INSERT IN in_table_head_3
VALUES ('H3ID1', 'T50', '1234', '02-JAN-2015');
INSERT IN in_table_head_3
VALUES ('H3ID2', 'T80', '1234', '03-JAN-2015');
INSERT IN in_table_head_3
VALUES ('H3ID3', 'T90', '1234', '05-JAN-2015');
INSERT IN in_table_head_3
VALUES ('H3ID4', 'T40', '1234', '05-AUG-2015');
CREATE TABLE in_table_item_1()i1_sys_id VARCHAR2()80) PRIMARY KEY,
h1_sys_id VARCHAR2 (80) REFERENCES in_table_head_1()h1_sys_id),item_code VARCHAR2()80));
CREATE TABLE in_table_item_2()i2_sys_id VARCHAR2()80) PRIMARY KEY,
h2_sys_id VARCHAR2 (80) REFERENCES in_table_head_2()h2_sys_id),item_code VARCHAR2()80));
CREATE TABLE in_table_item_3(i3_sys_id VARCHAR2(80) PRIMARY KEY,
h3_sys_id VARCHAR2 (80) REFERENCES in_table_head_3()h3_sys_id),item_code VARCHAR2()80),
bat_no VARCHAR2 (80));
INSERT IN in_table_item_1
VALUES ('I1ID1', 'H1ID1', 'I1');
INSERT IN in_table_item_1
VALUES ('I1ID2', 'H1ID1', 'I100');
INSERT IN in_table_item_1
VALUES ('I1ID3', 'H1ID2', 'I3');
INSERT IN in_table_item_2
VALUES ('I2ID1', 'H2ID1', 'I1');
INSERT IN in_table_item_2
VALUES ('I2ID2', 'H2ID1', 'I200');
INSERT IN in_table_item_2
VALUES ('I2ID3', 'H2ID2', 'I2');
INSERT IN in_table_item_3
VALUES ('I3ID1', 'H3ID1', 'I2','B50');
INSERT IN in_table_item_3
VALUES ('I3ID2', 'H3ID2', 'I4','B40');
INSERT IN in_table_item_3
VALUES ('I3ID3', 'H3ID3', 'I4','');
INSERT IN in_table_item_3
VALUES ('I3ID4', 'H3ID4', 'I6','');
SELECT *
FROM in_table_item_1
SELECT *
FROM in_table_item_2
SELECT *
FROM in_table_item_3
CREATE TABLE in_table_batch_1()b1_sys_id VARCHAR2()80) PRIMARY KEY,
txn_code VARCHAR2 (80), doc_no VARCHAR2 (80), bat_no VARCHAR2 (80));
CREATE TABLE in_table_batch_2()b2_sys_id VARCHAR2()80) PRIMARY KEY,
i2_sys_id VARCHAR2 (80) REFERENCES in_table_item_2()i2_sys_id),bat_no VARCHAR2()80));
INSERT IN in_table_batch_1
VALUES ('B1ID1', 'T1', '1234', 'B1');
INSERT IN in_table_batch_1
VALUES ('B1ID2', 'T70', '1234', 'B70');
INSERT IN in_table_batch_2
VALUES ('B2ID1', 'I2ID1', 'B30');
INSERT IN in_table_batch_2
VALUES ('B2ID2', 'I2ID2', 'B90');
INSERT IN in_table_batch_2
VALUES ('B2ID3', 'I2ID3', 'B60');
Please advise a solution for the same.
Thank you and best regards,
Séverine Suresh
very forced (question subfactoring used to allow easy testing/verification - could work with these test data only)
with
case_1 as
(select s.item_code,
s.bat_no,
h.txn_code,
h.doc_no,
h.updt_dt boe_dt,
cases where s.bat_no = h.bat_no then 'Y' else ' n end batch_yn.
cases where h.txn_code is not null
and h.doc_no is not null
and h.updt_dt is not null
then 'case 1' '.
end refers_to
from (select item_code, bat_no, txn_code, doc_no, boe_dt
of w_stock_table
where bat_no is null
or txn_code is null
or doc_no is null
or boe_dt is null
) s
left outer join
w_history_table h
On s.item_code = h.item_code
and s.bat_no = h.bat_no
and exists (select null
of w_transaction1
where txn_code = nvl (s.txn_code, h.txn_code)
and txn_type in ('IN', 'ALL')
)
),
case_2 as
(select s.item_code,
NVL (s.bat_no, h.bat_no) bat_no.
NVL (s.txn_code, h.txn_code) txn_code.
NVL (s.doc_no, h.doc_no) doc_no.
NVL (s.boe_dt, h.updt_dt) updt_dt.
cases where s.bat_no = h.bat_no then 'Y' else ' n end batch_yn.
cases where h.txn_code is not null
and h.doc_no is not null
and h.updt_dt is not null
then 'case 2'.
end refers_to
from (select item_code, bat_no, txn_code, doc_no, boe_dt
of case_1
where refers_to is null
) s
left outer join
w_history_table h
On s.item_code = h.item_code
and exists (select null
of w_transaction1
where txn_code = nvl (s.txn_code, h.txn_code)
and txn_type in ('IN', 'ALL')
)
and not exists (select null
of case_1
where item_code = h.item_code
and bat_no = h.bat_no
and txn_code = h.txn_code
and doc_no = h.doc_no
and updt_dt = h.updt_dt
)
),
case_31 as
(select s1.item_code,
NVL (S1.bat_no, W1.bat_no) bat_no.
NVL (S1.txn_code, W1.txn_code) txn_code.
NVL (S1.doc_no, W1.doc_no) doc_no.
NVL (S1.updt_dt, W1.doc_dt) updt_dt.
cases where s1.bat_no = w1.bat_no then 'Y' else ' n end batch_yn.
cases where w1.txn_code is not null
and w1.doc_no is not null
and w1.doc_dt is not null
then "case 31'.
end refers_to
from (select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn, refers_to
of case_2
where refers_to is null
) s1
left outer join
(select i1.item_code, h1.txn_code, h1.doc_no, h1.doc_dt, b1.bat_no
of w_in_table_item_1 i1
inner join
w_in_table_head_1 h1
On i1.h1_sys_id = h1.h1_sys_id
inner join
w_in_table_batch_1 b1
On h1.txn_code = b1.txn_code
and h1.doc_no = b1.doc_no
) w1
On s1.item_code = w1.item_code
),
case_32 as
(select s2.item_code,
NVL (S2.bat_no, W2.bat_no) bat_no.
NVL (S2.txn_code, W2.txn_code) txn_code.
NVL (S2.doc_no, W2.doc_no) doc_no.
NVL (S2.updt_dt, W2.doc_dt) updt_dt.
cases where s2.bat_no = w2.bat_no then 'Y' else ' n end batch_yn.
cases where w2.txn_code is not null
and w2.doc_no is not null
and w2.doc_dt is not null
then "case 32'.
end refers_to
from (select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn, refers_to
of case_2
where refers_to is null
) s2
left outer join
(select i2.item_code, h2.txn_code, h2.doc_no, h2.doc_dt, b2.bat_no
of w_in_table_item_2 i2
inner join
w_in_table_head_2 h2
On i2.h2_sys_id = h2.h2_sys_id
inner join
w_in_table_batch_2 b2
On i2.i2_sys_id = b2.i2_sys_id
) w2
On s2.item_code = w2.item_code
),
case_33 as
(select s3.item_code,
w3.bat_no,
NVL (S3.txn_code, w3.txn_code) txn_code.
NVL (S3.doc_no, w3.doc_no) doc_no.
NVL (S3.updt_dt, w3.doc_dt) updt_dt.
cases where s3.bat_no = w3.bat_no then 'Y' else ' n end batch_yn.
cases where w3.txn_code is not null
and w3.doc_no is not null
and w3.doc_dt is not null
then "case 33'.
end refers_to
from (select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn, refers_to
of case_2
where refers_to is null
) s3
left outer join
(select i3.item_code, h3.txn_code, h3.doc_no, h3.doc_dt, i3.bat_no
of w_in_table_item_3 i3
inner join
w_in_table_head_3 h3
On i3.h3_sys_id = h3.h3_sys_id
) w3
On s3.item_code = w3.item_code
)
Select item_code, bat_no, txn_code, doc_no, boe_dt, batch_yn
of case_1
where refers_to is not null
Union of all the
Select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn
of case_2
where refers_to is not null
Union of all the
Select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn
from (select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn,
ROW_NUMBER() over (partition by item_code of updt_dt desc order) rn
from (select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn
of case_31
where refers_to is not null
Union of all the
Select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn
of case_32
where refers_to is not null
Union of all the
Select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn
of case_33
where refers_to is not null
)
)
where rn = 1
ITEM_CODE | BAT_NO | TXN_CODE | DOC_NO | BOE_DT | BATCH_YN |
---|---|---|---|---|---|
I1 | B1 | T1 | 1234 | JANUARY 3, 2015 | THERE |
I1 | B30 | T30 | 7890 | FEBRUARY 5, 2015 | N |
I2 | B60 | T60 | 1234 | JANUARY 3, 2015 | N |
I3 | B70 | T70 | 1234 | FEBRUARY 1, 2015 | THERE |
I4 | - | T90 | 1234 | JANUARY 5, 2015 | N |
I6 | - | T40 | 1234 | AUGUST 5, 2015 | N |
Concerning
Etbin
Maybe you are looking for
-
With Firefox browser open, a message @ bottom right a message promoting a security for 1 free month using a credit card. then it would be $50.00 for a year. I hope that Fire Fox, so I registered. It did not work well, it's why I ask... is this your p
-
Re: keyboard in Tablet - spectrum mode
I think it was some time ago, but have you ever found a solution for this problem of keyboard? Thank you
-
15 - g207ax: lack of drivers for HP 15 - g207AX.
-
Why Skype keep crashing?
He worked for a week. Now, I get a message saying that Skype has stopped running. Windows will close the session. I have even improved. They me even if I cancel my subscription, they still charge me.
-
Can't see the other hand google calendars
Recently my computer I created another calendar in google calendar to share with the family, without having to share my main calendar (so this calendar can include only events of interest to us all without clogging each other calendars with appointme