r/plsql • • Jan 15 '17

What is the use of creating a virtual column?

2 Upvotes

hello folks, I am currently working my way towards getting oracle certification. I found out in an oracle press release a complete reference book that one can create a virtual column using GENERATED ALWAYS AS clause. what is the purpose of such column?


r/plsql • • Dec 08 '16

I want to populate a column with new value once there is a new/update on existing column

2 Upvotes

I have two tables: TABLE 1: CREATE TABLE ADD_RECIPE( R_ID NUMBER(4) GENERATED BY DEFAULT ON NULL AS IDENTITY(START WITH 1 INCREMENT BY 1), RECIPE_NAME VARCHAR2(40)UNIQUE, SUBMITTED_BY VARCHAR2(40), CATEGORY VARCHAR(15), COOKING_TIME NUMBER(5), PORTIONS NUMBER(4), CUISINE VARCHAR(15), VISIBILITY VARCHAR2(15), DESCRIPTION VARCHAR2(1000) );

TABLE2: --CREATING TABLE FOR CUISINE CREATE TABLE CUISINE ( CUISINE_ID NUMBER(4) PRIMARY KEY,
CUISINE VARCHAR2 (25) ); INSERT INTO CUISINE(CUISINE_ID,CUISINE) VALUES(SEQ_CUISINE.NEXTVAL,'MEXICAN'); INSERT INTO CUISINE(CUISINE_ID,CUISINE) VALUES(SEQ_CUISINE.NEXTVAL,'CONTINENTAL'); INSERT INTO CUISINE(CUISINE_ID,CUISINE) VALUES(SEQ_CUISINE.NEXTVAL,'INDIAN'); INSERT INTO CUISINE(CUISINE_ID,CUISINE) VALUES(SEQ_CUISINE.NEXTVAL,'MEXICAN'); INSERT INTO CUISINE(CUISINE_ID,CUISINE) VALUES(SEQ_CUISINE.NEXTVAL,'CANADIAN'); INSERT INTO CUISINE(CUISINE_ID,CUISINE) VALUES(SEQ_CUISINE.NEXTVAL,'ITALIAN'); INSERT INTO CUISINE(CUISINE_ID,CUISINE) VALUES(SEQ_CUISINE.NEXTVAL,'CHINESE'); INSERT INTO CUISINE(CUISINE_ID,CUISINE) VALUES(SEQ_CUISINE.NEXTVAL,'THAI');

I want a trigger so that when there is a new recipe added and a new cuisine added with it which does not existing in the cuisine table, for example, RUSSIAN, it should automatically add RUSSIAN to cuisine table.

This is what I was thinking:

CREATE OR REPLACE TRIGGER ADD_NEW_CUISINE BEFORE DELETE OR INSERT OR UPDATE ON ADD_RECIPE FOR EACH ROW WHEN (new.CUISINE > 0) DECLARE CUISINE VARCHAR; BEGIN dbms_output.put(' New CUISINE: ' || :new.CUISINE); END;


r/plsql • • Oct 13 '16

Test Your SQL skills, Compete with SQL minds from across the world, Unlock new tricks and dive deep into SQL. HackerEarth presents one of its kind SQL Challenge - SQLizer - a 6 hours competitive challenge on SQL

Thumbnail
hackerearth.com
2 Upvotes

r/plsql • • Sep 05 '16

need help on how to save to a file on plsql

2 Upvotes

hi im currectly creating s script that will query a bunch of info and dump it to a text file. i checked some sample script that my colleague(which resigned already) created and it uses fopen. i tried mimicing it but i always encounter an error that the location doesnt exists. in the fopen my friend declared a sort of a variable i think but couldnt find where its value is located. so can anyone help me?


r/plsql • • May 10 '16

PLSQL Procedure Exception

2 Upvotes

Hey , i've got this code and im trying to create a exception so i cant enter the same data into a table multiple times, ive tried so many ways and im not quite sure how to do this?

CREATE OR REPLACE PROCEDURE enrollStudent IS v_stu_id enrollments.stu_id%TYPE; v_class_id enrollments.class_id%TYPE; v_t_date enrollments.enrollment_date%TYPE; BEGIN v_stu_id :=105; v_class_id :=2; v_t_date :=sysdate; INSERT into ENROLLMENTS (enrollment_date, class_id,stu_id, status) VALUES(v_t_date,v_class_id,v_stu_id,'Enrolled'); DBMS_OUTPUT.PUT_LINE('INSERTED' || SQL%ROWCOUNT || 'row'); END;

How would i add an exception to be able to make sure i cant add '105' and '2' if its already in the table??

thanks


r/plsql • • Mar 31 '16

Creating View Problem

2 Upvotes

Hi guys, i'll start saying sorry if this question may have and obvious answer but i can't figure it out.

Today i had to create a view that had to accomplish some things but it didn't not committed i didn't know why. If you could give this code a look and point the solution to me i would be very grateful. Let me say that it's the first time i'm working with such statements and function.

CREATE VIEW STIP_PROPOSTO AS
SELECT A.Cod, A.Nome || ' ' || A.Cognome As Nome, A.Stipendio,
CASE
    WHEN Data_Assunto <= TO_DATE('01/01/2013','DD/MM/YYYY') THEN A.Stipendio * 1.15
    WHEN Data_Assunto <= TO_DATE('01/01/2014','DD/MM/YYYY') THEN A.Stipendio * 1.1
    ELSE Stipendio
END AS Proposto, NVL2(A.Capo, B.Cognome, 'nessuno') 
FROM IMPIEGATO AS A JOIN IMPIEGATO AS B ON A.Capo = B.Cod

This is the table i'm working with

CREATE TABLE IMPIEGATO (
Cod NUMBER PRIMARY KEY,
Nome VARCHAR(20) NOT NULL,
Cognome VARCHAR(20) NOT NULL,
Data_Assunto DATE NOT NULL,
Stipendio NUMBER NOT NULL,
Capo NUMBER,
CONSTRAINT fk_Capo FOREIGN KEY (Capo) REFERENCES IMPIEGATO(Cod)
);

I'm using ORACLE XE 11g edition + SQL Developer

This is the error the compiler gave to me:

Report error -
Error SQL: ORA-00933: SQL command not properly ended
00933. 00000 - "SQL command not properly ended"
*Cause:
*Action:

Thanks for you time :)


r/plsql • • Dec 09 '15

Exit cursor on two different conditions?

2 Upvotes

Hello my question is how would i exit a cursor if one or another condition were to occur for example my code:

declare 
    v_snum waitlist.snum%type;
    v_callnum waitlist.callnum%type;
    cursor cStudent is
    select snum,callnum
    from Waitlist
   where p_callnum = callnum
   order by position desc;
 begin
   open cStudent;
   loop
   fetch cStudent into v_snum,v_callnum;
   Addme(v_snum,v_callnum,v_error_text);
   if v_error_text is null then
   delete from waitlist
   where v_snum = snum
   and v_callnum = callnum;
   exit when cStudent%found;
  end if;
 end loop;
  close cStudent;
 end;
 end;
 /                                                    

exits the cursor when a student is able to pass all the enrollments checks and enrolls, but if for example no one on the waitlist is able to enroll in the class I dont want the program to just crash. Would i use an exception if the cursor does not find a student?


r/plsql • • Oct 13 '15

Can I pick a cursor for a record dynamically?

2 Upvotes

Here is what I would like to do. Use the same record but select the cursor depending upon a parameter. That way, it is neatly in a cursor for each query. Here is a quick example:

  DECLARE
    ParmProgGroup VARCHAR2 (2) := UPPER ('&1');
    ParmTerm VARCHAR2 (2) := UPPER ('&2');

    CURSOR get_user IS
      SELECT id from IDTABLE where Term = ParmTerm;-- with many more ANDs and ORs

    CURSOR get_test IS
      SELECT id from IDTABLE where id IN (1234,2345);-- test IDs, dont use ANDs and ORs

    get_user_rec   get_user%ROWTYPE;
    
  BEGIN
   IF ParmProgGroup = 'T' THEN --test group
     FOR get_user_rec IN test_user
   ELSE
     FOR get_user_rec IN get_user
   END IF;

   LOOP
     DBMS_OUTPUT.PUT_LINE ('get_user_rec.id = '||get_user_rec.id);
   END LOOP;
  END;
  /

This doesn't work but I am hoping for a small adjustment that will make it work. Any ideas?


r/plsql • • Apr 07 '15

Ask the right questions before starting construction of your new PL/SQL-based application

Thumbnail
oracle.com
2 Upvotes

r/plsql • • Apr 02 '15

Is there a way to check if a Package/Procedure/Function is being used?

2 Upvotes

Or even the last time it was used?


r/plsql • • Oct 24 '14

PLSQL equivalent of SAS macro variable?

2 Upvotes

Sorry if this is something basic I should know. I have picked up SQL over the last couple of jobs and now use it daily but I've never learned some of the more advanced features. Is there a way to declare a string at the top of the query and then reference it below in calculated fields and parameters? For example: In SAS I would say: %let prod_list_a = '0123','4567','0987','9876' Then below I could reference that with: where product_number in (&prod_list_a.) Is there an equivalent I could use? *edit: this may belong in a different sub-reddit


r/plsql • • Sep 16 '13

Vincent Deelen: SEPA direct debit initiation with Oracle XML DB

Thumbnail
vincentdeelen.blogspot.com
2 Upvotes

r/plsql • • Jul 01 '13

Understanding Oracle PL/SQL

Thumbnail
mrbool.com
2 Upvotes

r/plsql • • Sep 15 '11

Oracle includes a package to encrypt your code, if you need that.

Thumbnail
imdjkoch.wordpress.com
2 Upvotes

r/plsql • • Aug 21 '11

Setting up a CVS for your PL/SQL code

Thumbnail aboutcm.com
2 Upvotes

r/plsql • • Aug 12 '11

Good beginner PL/SQL tuning scripts

Thumbnail
venushuynh.wordpress.com
2 Upvotes

r/plsql • • Jul 23 '11

Performance monitoring tool: Session Snapper

Thumbnail
tech.e2sn.com
2 Upvotes

r/plsql • • May 10 '26

Simplified Guide to IF-THEN-ELSE Statement in Oracle PLSQL with Examples

1 Upvotes

Hi everyone, I just wrote a detailed guide on using IF-THEN-ELSE in PLSQL. It covers the basic syntax and includes practical examples like updating records based on conditions. Thought it might be helpful for beginners starting with Oracle.

Link: [https://www.javainhand.com/2026/05/if-then-else-statement-in-oracle-plsql.html

]


r/plsql • • Apr 29 '25

Difference Between Implicit and Explicit Cursor in Oracle PLSQL

Post image
1 Upvotes

r/plsql • • Jan 13 '25

%ROWTYPE in Oracle PLSQL with Example

Thumbnail
javainhand.com
1 Upvotes

r/plsql • • May 18 '24

User Defined Exception with Example in PLSQL

Thumbnail
youtu.be
1 Upvotes

r/plsql • • May 11 '24

Exception Handling with Example in PLSQL

Thumbnail
youtu.be
1 Upvotes

r/plsql • • Apr 19 '24

Oracle PL/SQL Tutorial 30- Stored Procedure in PLSQL with Example || Jav...

Thumbnail
youtube.com
1 Upvotes

r/plsql • • Apr 12 '24

Oracle PL/SQL Tutorial 29- Function INOUT Parameter in PLSQL with Example

Thumbnail
youtube.com
1 Upvotes

r/plsql • • Mar 29 '24

Function Input (IN) Parameter in PLSQL with Example

Thumbnail
youtu.be
1 Upvotes