Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6342493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:15:05+00:00 2026-05-24T20:15:05+00:00

CREATE FUNCTION TWO_FRONT(txt CHAR(30)) RETURNS CHAR(2) RETURN SUBSTRING(txt, 1, 2); DELIMITER $$ CREATE FUNCTION

  • 0
CREATE FUNCTION TWO_FRONT(txt CHAR(30))
RETURNS CHAR(2)
RETURN SUBSTRING(txt, 1, 2);

DELIMITER $$
CREATE FUNCTION CHECK_AVABILITY(t_nama CHAR(30))
RETURNS INT(4)
BEGIN
DECLARE vreturn INT(4);
DECLARE P CHAR(8);
SET p = (SELECT MAX(id) FROM tabel_user WHERE nama like CONCAT(TWO_FRONT(t_nama),'%'));
IF ISNULL(p)THEN
    SET vreturn = 0;
ELSE
    SET vreturn = SUBSTRING(p, 4, 4);
END IF;
RETURN vreturn;
END $$
DELIMITER;

CREATE FUNCTION COMBINE(fn CHAR(2), nu CHAR(4))
RETURNS CHAR(7)
RETURN CONCAT(UPPER(fn),'-',nu);

CREATE TRIGGER cast_id AFTER INSERT ON tabel_user 
FOR EACH ROW 
BEGIN 
UPDATE tabel_user SET id = COMBINE(TWO_FRONT(OLD.nama),CHECK_AVABILITY(OLD.nama)) WHERE id = OLD.id;
END;

Everyting is okay but after i insert this…

INSERT INTO tabel_user VALUES('','Blabla');

error is coming…

ERROR 1442 (HY000): Can’t update table ‘tabel_user’ in stored function/trigger because it is already used by statement which invoked this stored function/trigger.

Can you help me…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:15:06+00:00Added an answer on May 24, 2026 at 8:15 pm

    You’re sending MySQL mixed messages.

    cast_id fires after INSERT, but it is looking for OLD.nama and OLD.id. OLD, on the other hand, only exists when there is an UPDATE being called. I think you meant:

    CREATE TRIGGER cast_id AFTER INSERT ON tabel_user 
    FOR EACH ROW 
    BEGIN 
        -- notice no "UPDATE" or "WHERE", "SET" implies "set on this current row"
        SET NEW.id = COMBINE(TWO_FRONT(NEW.nama),CHECK_AVABILITY(NEW.nama));
    END;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following function: CREATE FUNCTION fGetTransactionStatusLog ( @TransactionID int ) RETURNS varchar(8000)
How come the following doesn't work? CREATE FUNCTION Test (@top integer) RETURNS TABLE AS
So basically I would like to create a function that when alerted, returns the
I want to create function to return a 1d array with 2 elements in
How do I create a 'user defined function' that returns a 'cursor' back to
I'd like to create a function that calculates the distance between two pairs of
I can create function pointers in Fortran 90, with code like real, external ::
I have the following function: CREATE FUNCTION [dbo].[ListStockBySubCategory] ( @CategoryID varchar(10), @SubCategoryID varchar(10), @startRowIndex
I have the following scalar function in MS SQL 2005: CREATE FUNCTION [dbo].[Distance] (
It's possible to call C functions through CREATE FUNCTION but how can .NET functions

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.