Select the data in a table and update in another table

Dear experts,

create the table TB_ENCRYPT

(

Identification number,

Varchar2 (200) KEY

);

INSERT INTO TB_ENCRYPT VALUES(1,'HJUVHDUIFBSDGVU');

SELECT * FROM TB_ENCRYPT;

1 HJUVHDUIFBSDGVU

create TABLE users)

username, NUMBER of

password VARCHAR2 (200)

);

Insert users

values (1, 123 # "")

Insert users

values (2, 456 #')

Select * from users;

1 123 #.

# 2 456

I want to select the data KEY for table TB_ENCRYPT column and update in the column of tables for the respective key user password

TB_ENCRYPT table contains only a single key value. Comparing this key, I want to update the old value of the key to the new value.

For encryption and decryption I followed the java class method.no is worried about that.

create or replace

PACKAGE PCK_ENC AUTHID CURRENT_USER AS

FUNCTION DECRYPT (VARCHAR arg0, arg1 VARCHAR) AS VARCHAR BACK LANGUAGE JAVA NAME 'Encrclass.decrypt (java.lang.String, java.lang.String) return java.lang.String ';

FUNCTION ENCRYPT (VARCHAR arg0, arg1 VARCHAR) AS VARCHAR BACK LANGUAGE JAVA NAME 'Encrclass.encrypt (java.lang.String, java.lang.String) return java.lang.String ';

END;

SELECT PCK_ENC. ENCRYPT('1234','HJUVHDUIFBSDGVU') FROM DUAL;

HERE,

1234 - is the password of the users table column data

HJUVHDUIFBSDGVU - represents the key of table TB_ENCRYPT column data.

Comparing this key, I want to update the old value of the key to the new value.

I tried with this method

declare

cursor c1 is

Select the key

of TB_ENCRYPT

where id = 1

update the id;

Start

for c1_rec looping c1

update users

password is PCK_ENC. Encrypt (Password, Key)

the location being c1;

commit;

end loop;

end;

/

Help, please

You can use the MERGE statement.

merge into users
using tb_encrypt
   on (id = userid)
  when matched then
      update set password = PCK_ENC.ENCRYPT(password,key);

And why you encrypt your password. This isn't a good idea. Just password hash.

Tags: Database

Similar Questions

  • Distribute the data in a column and update new column with data of split

    Hi all

    I'm working on Oracle 10 g. One of my table of the column stores the data, sampled below.

    1722999340KK000200000
    1444210829AB1001EX003
    1444300000CD0148EX003
    1722999340KL 000200000

    I want to split the data in the report between the numbers (4; 6; 6; 5), as shown below and store it in different columns (A1 |) A2 | A3 | A4).
    1444 | 210829 | AB1001 | EX003

    Grateful if someone can give me some advice on how to achieve the same in the SQL database.

    See you soon,.

    novice
    insert into split_tab  (A1,A2,A3,A4)
    select substr(mycolumn,1,4), substr(mycolumn,5,6), substr(mycolumn,11,6), substr(mycolumn,17)
    from myoriginaltab;
    

    Max

  • Select the data in two tables

    Hello

    I am trying to build a query WITH, but I can't seem to make it work:

    WITH P1 AS (SELECT OT_VALUE

    OF CSD_OPEN_VERY_HIGH_INCIDENTS VHIGH

    WHERE OT_VALUE > = 0

    ). P2 AS (SELECT OT_VALUE

    OF HIGH CSD_OPEN_HIGH_INCIDENTS

    WHERE OT_VALUE > = 0

    ), SELECT VHIGH. OT_VALUE, TOP. OT_VALUE

    P1 P2 JOIN INTERNALLY. RATING = P2. RANKING

    The two tables have the same column names.

    I want to only return a set of results if the two columns (OT_VALUE) contain in reality 1.

    Select this check box. This is a job for all four images. This will return the line to the following combinations. 0.0 and 0.1 and 1.0 and 1.1. Importance is 1.2.  Let me know if you face any problem

    SELECT CASE WHEN ((VH_OT_VAL = 0 ET H_OT_VAL = 0) OR (VH_OT_VAL = 1 AND H_OT_VAL = 0) OR (VH_OT_VAL = 0 AND H_OT_VAL = 1) or (VH_OT_VAL = 1 AND H_OT_VAL = 1)) 1

    ANOTHER ACE OF NULL TERMINATOR OT_VAL

    DE)

    SELECT H.OT_VALUE H_OT_VAL,

    VH. OT_VALUE VH_OT_VAL

    OF CSD_OPEN_VERY_HIGH_INCIDENTS VH.

    CSD_OPEN_HIGH_INCIDENTS H

    WHERE NVL (VH. CLASSIFICATION, 0) = NVL(H.CLASSIFICATION,0)

    AND VH. IMPORTANCE IN (1,2)

    AND H.IMPORTANCE IN (1,2)

    AND NVL (VH. OT_GROUP, 0) = NVL(H.OT_GROUP,0)

    AND VH. IMPORTANCE = H.IMPORTANCE

    AND VH. TIME_STAMP = H.TIME_STAMP

    );

  • Size of the data in a table and the size of the table

    I am trying to determine the size of the data in a table and also the overall table size. I use the following query:

    SELECT BOTTOM (a.owner) as owner,
    LOWER (a.table_name) AS table_name,
    a.tablespace_name,
    a.Num_Rows,
    ROUND ((a.blocks * 8 / 1024)) AS size_mb,
    a.Blocks,
    a.Blocks * 8 Blocks_Kilo_Byte.
    a.PCT_FREE,
    a.compression,
    a.Logging,
    b.bytes / 1024 / 1024
    From all_tables a, dba_segments b
    WHERE the a.owner AS SUPERIOR ("USER_TEST")
    AND a.table_name = "X_TEST_TABLE."
    AND b.segment_name = a.table_name
    AND b.owner = a.owner
    ORDER BY 1, 2;

    Is this the right way to go about finding the size of the data in a table? If this isn't the case, please give your suggestions.

    BTW, this in a 10g version.

    You probably want to use the DBMS_SPACE package. In particular, the procedures SPACE_USAGE and UNUSED_SPACE to get an accurate account of the use of space in a table. Your application may give you a relatively accurate estimate if the optimizer on your table's statistics are reasonably accurate estimates. But there is no guarantee that the optimizer statistics are accurate.

    If you want just an approximate answer and you're comfortable that your statistics are accurate, this query may be close enough. If you want a specific response, however, use the DBMS_SPACE package.

    Justin

  • Inventory of the data of all Tables in a database

    Hello
    We do the analysis of the existing data base (Oracle 10 g) and I want to prepare an inventory of the data of all tables in a database that is

    1. total number of records in a table
    2. total number of records that have null values in a column
    3. total number of standalone tables IE have no connection with other tables
    etc...

    Please let me know if there are tools or query that can do these tasks.

    Thank you and best regards,
    Lokesh
    select owner "Owner",
    table_name "Table_Name",
    column_name "Column_Name",
    initcap(data_type) ||
    decode(data_type,
    'CHAR', '('|| char_length ||')',
    'VARCHAR', '('|| char_length ||')',
    'VARCHAR2', '('|| char_length ||')',
    'NCHAR', '('|| char_length ||')',
    'NVARCHAR', '('|| char_length ||')',
    'NVARCHAR2', '('|| char_length ||')',
    'NUMBER', '('||
    nvl(data_precision,data_length)||
    decode(data_scale,null,null,
    ','||data_scale)||')',
    null) "Type",
    nullable "Nullable",
    decode(to_char(num_distinct),
    0,'No',
    'YES') "Have Data",
    owner sdev_link_owner,
    table_name sdev_link_name,
    'TABLE' sdev_link_type
    from sys.dba_tab_columns
    where (:OWNER is null or instr(owner,upper(:OWNER)) > 0)
    and (:TABLE_NAME is null or
    instr(upper(table_name),upper(:TABLE_NAME)) > 0)
    and (:COLUMN_NAME is null or
    instr(upper(column_name),upper(:COLUMN_NAME)) > 0)
    and substr(table_name,1,4) != 'BIN$'
    and substr(table_name,1,3) != 'DR$'
    order by owner, table_name, column_id
    

    I added a new column with an alias "get data". This new column will display "NO" is the entire column is zero and 'YES' if there is even a value not null in the column. But caution is that statistics table must be updated to get the correct results.

    Thus, it may be useful to gather current statistics before executing the query.

    Exec dbms_stats.gather_schema_stats or even dbms_stats.gather_database_stats.

  • Select the column in a table that is defined in the select previous in the statement

    Hello

    I want to write a procedure that selects all the data in a table has then records them in the text file. I tested on table hr.countries.

    My code is like this:

    echo off newpage 0 space 0 pagesize 0 feed head off trimspool check out serveroutput on the value

    coil countries.txt

    define dtable = COUNTRY;

    declare

    col_num NUMBER;

    no_lig NUMBER;

    line VARCHAR2 (100);

    Col VARCHAR2 (100);

    Start

    Select count (COLUMN_ID) in the col_num USER_TAB_COLUMNS WHERE table_name = '& dtable';

    Select count (*) in no_lig of & dtable;

    because me in 1.row_num

    loop

    1.col_num j

    loop

    Select column_name from col FROM USER_TAB_COLUMNS WHERE table_name = '& dtable' and column_id = j;

    Select the pass in the row (select col, rownum: nurse of (select col from & dtable)) where rn = i;

    IF (j! = col_num) THEN

    DBMS_OUTPUT. PUT(Row ||) ', ');

    ON THE OTHER

    DBMS_OUTPUT. PUT (Row);

    END IF;

    end loop;

    DBMS_OUTPUT. NEW_LINE;

    end loop;

    end;

    /

    spool off

    I have had no error, but the result is like this:

    COUNTRY_ID, COUNTRY_NAME, REGION_ID

    COUNTRY_ID, COUNTRY_NAME, REGION_ID

    COUNTRY_ID, COUNTRY_NAME, REGION_ID

    .. and so on for the whole table.

    I want to have results with data not only the names of columns. No idea what is the problem? I thought that select col online would do the thing, but the line is identical to the col variable...

    Thank you

    Honza

    Set serveroutput on;

    define dtable = COUNTRY;

    declare

    col_num NUMBER;

    no_lig NUMBER;

    line VARCHAR2 (100);

    Col VARCHAR2 (100);

    Start

    Select count (COLUMN_ID) in the col_num USER_TAB_COLUMNS WHERE table_name = '& dtable;

    Select count (*) in the no_lig argument of &dtable;

    because me in 1.row_num

    loop

    1.col_num j

    loop

    Select column_name from col FROM USER_TAB_COLUMNS WHERE table_name = '& dtable' and column_id = j;

    run immediately 'select'. Col | "from (select ' |) Col |', rownum: nurse from (select ' |) Col |' of & dtable)) where rn =' | I have

    Online;

    IF (j! = col_num) THEN

    DBMS_OUTPUT. PUT(Row ||) ', ');

    ON THE OTHER

    DBMS_OUTPUT. PUT (Row);

    END IF;

    end loop;

    DBMS_OUTPUT. NEW_LINE;

    end loop;

    end;

    /

    Output

    anonymous block filled

    AR, Argentina, 2

    To, Australia, 3

    BEING, Belgium, 1

    BR, Brazil, 2

    CA, Canada, 2

    CH, Switzerland, 1

    CN, China, 3

    OF (Germany), 1

    DK, Denmark, 1

    For example, Egypt, 4

    FR, France, 1

    HE, Israel, 4

    IN, India, 3

    IT, Italy, 1

    JP, Japan, 3

    KW, Kuwait, 4

    ML, Malaysia, 3

    MX, Mexico, 2

    NG, Nigeria, 4

    NL, Netherlands, 1

    SG, Singapore, 3

    UK, United Kingdom, 1

    WE, United States of America, 2

    ZM Zambia, 4

    ZW, Zimbabwe, 4

  • Kindly help me with the request to find the data in two tables

    Hello Guru

    Kindly help me to recover the data from two tables-

    BASEBALL
    LEGAL_ENT_ID (PK)
    GAME_ID (FK)
    LEGAL_ENT_NM
    INACTIVE_DT
    DATE OF INS_TS
    INS_LOGIN
    DATE OF UPD_TS
    UPD_LOGIN


    FOOTBALL
    GAME_ID (PK)
    BRKR_NM,
    BRKR_ISR_ID
    BROKER_SYMBOL
    INACTIVE_DT
    BRKR_SWIFT_FLG
    BRKR_INTERNAL_FLG
    BRKR_CATEGORY
    UPD_TS
    MINORITY_FLG
    BROKER_TYP
    STATUS
    INS_TS
    INS_LOGIN
    UPD_LOGIN
    APP_USER
    ACTIVE_FLG

    and if I want fecth data from these two tables according to the following condition then it is fine with the suite of applications.

    1 select distinct values only table of BASEBALL by using the following query.

    SELECT DISTINCT B.GAME_ID as 'CLEARING GAME ID', B.BRKR_NM "NAME of THE GAME of COMPENSATION" OF BASEBALL A, FOOTBALL B WHERE A.BROKER_RELATION_CD IN ('FUTBRKR1', 'FUTBRKR2') AND A.GAME_ID = B.GAME_ID

    2 Select all the table BRKR_NM OF FOOTBALL as well by using the query - next

    SELECT GAME_ID "RUNNING GAME ID", 'NAME OF THE GAME OF EXECUTION' BRKR_NM SOCCER

    Now, my query is that--

    I want a query that gives me a combination of above mentioned queries... and if I tried to use Union or Union All, then she is not giving me the result as expected.

    I like the result to look like who has a few conditions such as -
    1 - the records in the table Football are high vs Baseball table because there is no condition to filter the records of the Football.
    2 - football is a superset of records and Baseball is a subset.
    3 - COMPENSATION NOM_JEU and RUNNING NOM_JEU may return the same values as well.

    I want the result to be in the following form-

    EXECUTION ID GAME | NAME OF THE GAME TO RUN. COMPENSATION ID GAME | DELETE THE NAME OF THE GAME.
    2123 test1 2345 test5
    2456 test10 2456 test10


    Thanks in advance. Kindly help me.

    Published by: user555994 on January 4, 2011 23:48

    In the output you want.
    All the values of baseball;
    Values of football that are matched;
    But on what condition you want to match?

  • "shuffle" the data in a table...

    Hello world...

    Pleade help me solve this problem.

    Is it possible to combine the data in a table?
    Let say if i have a table with following data..
    
    PERSON_ID    PERSON_LAST_NAME        PERSON_FIRST_NAME        DOB
    
       1             Test1                   Test1              01/01/1970
       2             Test2                   Test2              01/01/1971
       3             Test3                   Test3              01/01/1972
       4             Test4                   Test4              01/01/1973
       5             Test5                   Test5              01/01/1974
    
    I am trying to shuffle the above data so that no person will have their
    "real last,first and dob match".
    
    I need the output like this or in any combinations so that no one can
    identify a person actual "last name,first name and dob"
    
    
    PERSON_ID    PERSON_LAST_NAME        PERSON_FIRST_NAME        DOB
    
       1             Test1                   Test2              01/01/1974
       2             Test2                   Test4              01/01/1975
       3             Test3                   Test5              01/01/1971
       4             Test4                   Test3              01/01/1972
       5             Test5                   Test1              01/01/1973
    
    please help me to solve this issue. Thanks in advance

    Hello

    You can do something like this:

    WITH     got_nums     AS
    (
         SELECT     person_id
         ,     ROW_NUMBER () OVER (ORDER BY dbms_random.value)          AS person_id_num
         ,     person_last_name
         ,     ROW_NUMBER () OVER (ORDER BY dbms_random.value)          AS person_last_name_num
         ,     person_first_name
         ,     ROW_NUMBER () OVER (ORDER BY dbms_random.value)          AS person_first_name_num
         ,     dob
         ,     ROW_NUMBER () OVER (ORDER BY dbms_random.value)          AS dob_num
         FROM     table_x
    --     WHERE     ...     -- Any filtering goes here
    )
    SELECT     id.person_id
    ,     ln.person_last_name
    ,     fn.person_first_name
    ,     db.dob
    FROM     got_nums     id
    JOIN     got_nums     ln     ON id.person_id_num     = ln.person_last_name_num
    JOIN     got_nums     fn     ON id.person_id_num     = fn.person_first_name_num
    JOIN     got_nums     db     ON id.person_id_num     = db.dob_num
    ;
    

    This does not guarantee that no column of the same original line will be on the same line of output. I don't think that you really want it.

  • Help! iPad 2 keeps coming out of the recovery mode. I have the latest version of itunes and updated my drivers.

    Help! iPad 2 keeps coming out of the recovery mode. I have the latest version of itunes and updated my drivers.

    Please take a genius appointment at an Apple Store, or select another authorized service provider.

  • concatenate the data in 2 tables in a third table as well as in CONCATENATE strings

    Hello. as the title says, I wish to only concatenate the data in 2 tables in a similar third table that concatenate strings don't. All tables should be 1 d. For example, suppose that there is 1 table with the following: 1. 2; 3; 4 and table 2 with:; b; c; d. I would like a table 3 either 1 a, 2 b, 3 c, 4 d. Now this could be done easily with above mentioned concatenate strings, then table construction. but table 1 and 2 have something like 150 items. Rather painful. Any ideas?

    Hold arrays of two strings in a loop for example, concatentate the strings inside the loop and run the result réécrirait array3.

    Autoindexing manages table manipulations.

    MIke...

  • I can't change the date & time to receive automatic updates of Windows XP - help!

    How can I change the date & time to get automatic updates - I've tried everything and did what I was asked to do - still not able to do!       Lin

    What happens when you try to do?

  • Delete the data in partitioned tables

    Hello

    Oracle 11.2.0.3.0 version, running on Linux Enterprise.

    I need to remove all the data from two tables (several 100 million lines each) that are partitioned.

    (1) table 1 is a partition table have varied to a DATE column

    (2) Table2 is a partition of reference table; partitioning is referenced on a relationship of foreign key to Table1 (column: key Table1.Primary)

    As I have no need for data, but want to keep the structure of the table, I would ideally like to delete partitions at the same time that the deletion of the data, so that the 2 tables partitioned and empty.

    Additionally, Table1 has some partitioned index I would be rebuilt as an index unpartitioned (given that Table1 will be empty).

    I thought I would start by removing all partitions of Table1 (via "ALTER TABLE DROP PARTITION nom_partition Table1"), but when the script came to the last partition, I got this error message:

    ORA-14083: cannot delete the only one partition of a partitioned table

    ORA-06512: at "SYS." DROP_PARTITIONS', line 46

    If someone could advise as to the best approach to what I want to achieve with regard to the two tables? Two tables down and recreate them then without partitions would be the easiest way?

    Thanks in advance for any guidance.

    If someone could advise as to the best approach to what I want to achieve with regard to the two tables? Two tables down and recreate them then without partitions would be the easiest way?

    Yes - delete the tables and re-create them.

    As says the exception that you cannot delete the last partition. A table is partitioned either or it is not.

    There was no interest at all to use DBMS_REDEFINITION to redefine tables because you do not want the data anyway.

  • to refine my question. The Lasso tool does not work.  When I select the content aware lasso shrinks and nothing changes.  Help please.

    to refine my question. The Lasso tool does not work.  When I select the content aware lasso shrinks and nothing changes.  Help please.

    A simple reset will often be the case if a tool becomes awkward. Go to this link, then select the lasso tool:

    Difficulty of tool

  • How can I sync 2 sony AVCHD images from the camera on the "date" as a prelude and import it in first pro?

    I have 2 sony camera popular with the AVCHD file structure. The two cameras are the same. How can I sync 2 sony AVCHD images from the camera on the "date" as a prelude and import it in first pro? Im working with 6.0


    Now I see the date taken in the import screen until I click "ingest". When in the trash, this option is there, but no metadata in there. It is therefore impossible to import images from two cameras and have these sorted.


    How can I get this sorted out before, so I can export for the first?

    Thank you. Tom van den Dool

    Hi Tom,

    How can I sync 2 sony AVCHD images from the camera on the "date" as a prelude and import it in first pro? Im working with 6.0.

    Sorry, you can not do as a prelude. You can request a feature here: http://adobe.ly/feature_request

    Thank you

    Kevin

  • Edit/view (data or Table column) value - cannot change the data, but it can be updated

    Hello

    According to the help of Oracle SQL Developer Center, the dialog ' Change/see value (data or Table column)' should "change the value of data" if we "are allowed to change the data." We strive to use this dialog box to modify/update data without having to write an Update statement, but is not to leave us. Us are not allowed to update the data, we can update via update statements. Even as the owner of the schema.table, it don't will change us the value in the dialog box "Edit/see value (data or Table column).

    Any ideas?

    We are on SQL Developer Version 3.0.0.4 build HAND - 04.34 and Oracle 11 GR 1 material (11.1.0.7) database.

    Thank you

    Alex Larzabal.

    You can still vote on the existing demand for this developer SQL to add Exchange of weight for implementation as soon as possible:
    https://Apex.Oracle.com/pls/Apex/f?p=43135:7:3974986722753169:no:RP, 7:P7_ID:4902

    Kind regards
    K.

Maybe you are looking for

  • How can I sync the iphone 2 6 calendars

    How can I synchronize the calendars of the two iphone6?

  • Mac book pro cursor moving by itself

    difficult to type as it keeps the files moving and openng I ran a diagnosis appear anything else I can try?

  • HP Elitebook 8740w: validity and windows 10 fingerprint sensor: does not

    Dear all, I come to you today because I have already tried many (perhaps all) of the suggested solutions posted on this forum. Unfortunately, I could never get a correct installation, work. After upgrading to windows 10 (automatic update of windows -

  • How can I sort the photos by title

    I had read in the latest version of pictures you had to to be able to sort the photos by title. However, I don't seem to have this ability. In fact only 1 sort option is available and it is greyed out and cannot be changed.

  • NEITHER USB 6008 OEM DEATH

    Hello I have a problem with some NI USB 6008 OEM. They do not work! I have attached to my PC and the light starts flashing, Windows detects new hardware and everything's fine (the same way it usually works with the regular OEM-NIUSB6008 Board, not).