Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Retrieving data before insert statement in procedure

BufossJul 19 2015 — edited Jul 20 2015

Hi,
I am new in plsql programming and I would like to make a procedure.I have tables like the following TABLE1

|COL1 | COL2 | COL3 | COL4 | COL5 | COL6 |COL7|
| 600 | 140 | 2 | 10 | 1300 | 500 | 1 |
| 600 | 140 | 2 | 20 | 1400 | 340 | 4 |
| 600 | 140 | 2 | 15 | 1400 | 230 | 3 |
| 600 | 140 | 2 | 35 | 1700 | 120 | 2 |
| 600 | 150 | 3 | 10 | 1300 | 166 | 6 |
| 600 | 150 | 3 | 15 | 1400 | 435 | 5 |

For the same COL1 and COL2/COL3 , check the select different values from COL4
For instance for COL1=600 , COL2=140/COL3=2 and COL2=150/COL3=3
Return 20 and 35 as not common values


Then insert in this table TABLE1 the rows
600 , 150 , 3, 20 , 1400 , 340, 7
600 , 150 , 3, 35 , 1700 , 120, 8


I am trying to make the procedure like below but I have problem how to retrieve data in insert statement

PROCEDURE COPY_COLUMNS  ( P_COL1        IN  A.COL1%TYPE,

                          P_FROM_COL2   IN  B.COL2%TYPE,

                          P_FROM_COL3   IN  B.COL3%TYPE,

                          P_TO_COL2     IN  B.COL2%TYPE,

                          P_TO_COL3     IN  B.COL3%TYPE,

                          P_FLG1        IN  VARCHAR2,

                          P_FLG2        IN  VARCHAR2,

                          P_FLG3        IN  VARCHAR2                                     

                                     ) IS

CURSOR CFL1 IS select COL4

    FROM TABLE1

    WHERE COL1 = P_COL1 AND COL2 = P_FROM_COL2 AND COL3 = P_FROM_COL3

    MINUS

    select COL4

    FROM TABLE1

    WHERE COL1 = P_COL1 AND COL2 = P_TO_COL2 AND COL3 = P_TO_COL3;

CURSOR CFL2 IS select COL4

    FROM TABLE2

    WHERE COL1 = P_COL1 AND COL2 = P_FROM_COL2 AND COL3 = P_FROM_COL3

    MINUS

    select COL4

    FROM TABLE2

    WHERE COL1 = P_COL1 AND COL2 = P_TO_COL2 AND COL3 = P_TO_COL3;

CURSOR CFL3 IS select COL4

    FROM TABLE3

    WHERE COL1 = P_COL1 AND COL2 = P_FROM_COL2 AND COL3 = P_FROM_COL3

    MINUS

    select COL4

    FROM TABLE3

    WHERE COL1 = P_COL1 AND COL2 = P_TO_COL2 AND COL3 = P_TO_COL3; 

V_REC        CFL1%ROWTYPE;

BEGIN

IF P_FLG1='N' OR P_FLG2='N' OR P_FLG3='N' THEN

    GOTO label; --do nothing

END IF;

IF P_FLG1 = 'Y' THEN

    OPEN CFL1;

    FETCH CFL1 INTO V_REC;

    CLOSE C1;

--    SELECT COL5, COL6

--    FROM TABLE1

--    WHERE COL1 = P_COL1 AND COL2 = P_FROM_COL2 AND COL3 = P_FROM_COL3 AND COL4 = V_REC.COL4;

    FOR REC IN CFL1 LOOP

        INSERT INTO TABLE1

            SELECT P_COL1, P_TO_COL2, P_TO_COL3, CFL1.COL4, -- COL5 ?? , COL6 ?? -- , SEQname2.NEXTVAL)

    END LOOP;

END IF;

<<label>>

END;

Could you help me please do it ?
Thanks in advance

This post has been answered by Solomon Yakobson on Jul 19 2015
Jump to Answer

Comments

Christian.Shay -Oracle
Answer

Hi Scott,

We don't support that syntax yet, but in the meantime you can do the following to connect proxy users:

  • To connect to Oracle Database from a .SQL or .PL/SQL file, press F1 to open Command Palette and select Oracle:Connect from the dropdown
  • To connect from Oracle Database Explorer, click the plus sign button
  • A connection dialog will open. In the Connection Type dropdown, select ODP.NET Connect String
  • In the Connection String field, enter a string with this format if providing the hostname, port and service name explicitly: User Id=myuser;Data Source=dbhostname:1521/DBSERVICENAME;Proxy User Id=myproxyuser;Proxy Password=myproxypass;
  • If using a TNS Alias, enter a connect string with this format: User Id=myuser;Data Source=mytnsalias;Proxy User Id=myproxyuser;Proxy Password=myproxypass;
  • Provide a connection name to be used to reference this connection in Database Explorer and elsewhere
  • Click the Create Connection button

For more tips, see the quickstart:

https://www.oracle.com/database/technologies/appdev/dotnet/odtvscodequickstart.html

Marked as Answer by Scott · Oct 6 2019
Scott

Perfect - that worked like a charm!

- Scott -

Hi Scott,
In our newest 19.3.3 release we made it a lot easier to connect using a proxy user. Please try it out and let me know any feedback about the release!
(In any connection dialog, check the Show more options checkbox and provide the proxy username and password)

User_6BTKC

Hello,
Am I being dense with the new dialog
In the examples here
alter user hr grant connect through scott;
connect scott[hr]/tiger
in the new dialog should I be entering scott in user name and scott[hr] in the proxy user name?

User_6BTKC

Ignore me all i was being dense. The proper syntax in the new dialog is
EX alter user hr grant connect through scott;
It is to place the target user HR in user name, and scott and scott's password in the new proxy user fields.

1 - 5
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Aug 17 2015
Added on Jul 19 2015
9 comments
1,169 views